(10%) Determine
whether the following code has syntax errors or not. If
it is correct, predict its output. If it is incorrect, point out
the mistake(s).
// Using the string class
#include <iostream>
#include <string>
using std::string;
int occurrence(string txt, string str)
{
int count(0);
int k = txt.find(str);
while (k != string::npos)
{
++count;
k = txt.find( str, k+str.length() );
}
return count;
}
int main()
{
string text("ABCABCABCABCABC");
string str("ABCABC");
std::cout << occurrence(text, str) << std::endl;
return 0;
}