I'm getting an error message where the FindText() is returning 0 instead of the proper amount of parameters. Here is the code #include #include using namespace std; char print_menu(string); int...


I'm getting an error message where the FindText() is returning 0 instead of the proper amount of parameters.



Here is the code



#include


#include


using namespace std;


char print_menu(string);


int GetNumOfNonWSCharacters(string);


int GetNumOfWords(string);


void ReplaceExclamation(string&);


void ShortenSpace(string&);


int FindText(string, string);


int main()


{


char opt;


string tx, ph;


cout < "enter="" a="" sample="">


getline(cin, tx);


cout < "you="" entered:="" "=""><>


do


{


opt = print_menu(tx);




} while (opt == 'Q' || 'q');


// system("pause");


return 0;


}


char print_menu(string tx)


{


char ch1;


string ph;


cout <>


cout < "c="" -="" number="" of="" non-whitespace="" characters\nw="" -="" number="" of="" words\nf="" -="" find="" text\nr="" -="" replace="" all="" !'s\ns="" -="" shorten="" spaces\nq="" -="">


cout < "\n\nchoose="" an="">


cin >> ch1;


switch (ch1)


{


case 'q':


case 'Q':



exit(0);


case 'c':


case 'C':


cout < "\nnumber="" of="" non-whitespace="" characters:="" "=""><>


break;



case 'w':


case 'W':


cout < "\n\n="" number="" of="" words:="" "=""><>


break;



case 'f':


case 'F':


cin.ignore();


cout < "\nenter="" a="" word="" or="" phrase="" to="" be="">


//getvalue
getline(cin, ph);


cout < "\n\""="">< ph="">< "\"="" instances:="" "="">< findtext(tx,="">


break;



case 'r':


case 'R': ReplaceExclamation(tx); cout < "\n\nedited="" text:="" "=""><>


break;


case 's':


case 'S': ShortenSpace(tx); cout < "\n\nedited="" text:="" "=""><>


break;


default:


cout < "\n\n="" invalid="">


break;



}


return ch1;


}


int GetNumOfNonWSCharacters(const string tx)


{


int cnt = 0, i;


int leng = tx.size();



for (i = 0; i


{


if (!isspace(tx[i]))


cnt++;


}


return cnt;


}


int GetNumOfWords(const string tx)


{


int words11 = 0, i;


int leng = tx.size();


for (i = 0; i<>


{


if (isspace(tx[i]))


{



while (isspace(tx[i]))


i++;



words11++;


}


else


{


i++;


}


}


words11 = words11 + 1;


return words11;


}


void ReplaceExclamation(string& tx)


{


string newtx = tx;


int i, leng = tx.size();



for (i = 0; i


{



if (tx[i] == '!')


newtx[i] = '.';


}


tx = newtx;


}


void ShortenSpace(string& tx)


{


char *newtx;


int i1, leng = tx.size(), k = 0;


newtx = new char[leng + 1];



for (i1 = 0; i1


{


newtx[k] = tx[i1];



if (isspace(tx[i1]))


{


while (isspace(tx[i1]))


i1++;


}


else


{


i1++;


}


}


newtx[k] = '\0';


tx = newtx;


}


int FindText(string tx, string ph)


{


int cnt = 0;


//size value


if (ph.size() == 0)


return 0;


//find value


for (size_t offset = tx.find(ph); offset != string::npos; offset = tx.find(ph, offset + ph.size()))


{
++cnt;
}
return cnt;


}


Tests that FindText() returns 5 for parameters

Extracted text: Tests that FindText() returns 5 for parameters "more" and "We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!" Test feedback FindText () incorrectly returns 0.
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here