C++ part 4: I have these error i am missing the ExecuteMenu Function This is my code so far. #include #include using namespace std; int GetNumOfNonWSCharacters(const string text); int...


C++ part 4: I have these error i am missing the ExecuteMenu Function


This is my code so far.


#include
#include


using namespace std;


int GetNumOfNonWSCharacters(const string text);

int GetNumOfWords(const string text);

int FindText(string text, string sample_text);

string ReplaceExclamation(string text);
string ShortenSpace(string text);



char PrintMenu(string sample_text){

char option;
cout <><>
cout < "c="" -="" number="" of="" non-whitespace=""><>
cout < "w="" -="" number="" of=""><>
cout < "f="" -="" find=""><>
cout < "r="" -="" replace="" all=""><>
cout < "s="" -="" shorten=""><>
cout < "q="" -=""><>

cout<>
cout < "choose="" an=""><>
cin >> option;



if(option == 'c'){

int nonWSCharacters = GetNumOfNonWSCharacters(sample_text);

cout < "number="" of="" non-whitespace="" characters:=""><><>

}else if(option == 'w'){

int numOfWords = GetNumOfWords(sample_text);

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

}else if(option == 'f'){

cout<"enter a="" word="" or="" phrase="" to="" be=""><>

string phrase;

cin.ignore();

getline(cin, phrase, '\n');

int instances = FindText(phrase,sample_text);

cout <>< phrase="">< "\"="" instances:=""><><>

}else if(option == 'r'){

string edited_text = ReplaceExclamation(sample_text);

cout < "edited="" text:=""><><>

}else if(option == 's'){

string edited_text = ShortenSpace(sample_text);
cout < "edited="" text:=""><><>

}



return option;



}



int GetNumOfNonWSCharacters(const string text){

int len = text.length(), nonWSCharacters = 0;

for(int i = 0; i < len;="">
if(text[i] != ' ' && text[i] != '\n' && text[i] != '\t')

nonWSCharacters++;
}

return nonWSCharacters;

}



int GetNumOfWords(const string text){
int len = text.length(), numOfWords = 0;
for(int i = 0; i < len;="">

if(text[i] == ' ' || text[i] == '\n' || text[i] == '\t'){

numOfWords++;

++i;

while(i < len="" &&="" (text[i]="=" '="" '="" ||="" text[i]="=" '\n'="" ||="" text[i]="=">

++i;

--i;



}
}

if(text[len-1] != ' ' || text[len-1] != '\n' || text[len-1] != '\t')

numOfWords++;



return numOfWords;

}



int FindText(string text, string sample_text){
int sample_length = sample_text.length();
int text_length = text.length();

int instances = 0;

for(int i=0;i<=sample_length-text_length;>

int j = 0;

for(; j
if(text[j]!=sample_text[i+j])

break;

}

if(j==text_length){

instances++;


}

}

return instances;



}



string ReplaceExclamation(string sample_text){
int len = sample_text.length();

int i = 0;

string edited_text = "";

while(i <>

{

if(sample_text[i] == '!'){

edited_text += '.';

}else{
edited_text += sample_text[i];
}

i++;
}

return edited_text;



} string ShortenSpace(string sample_text){

int len = sample_text.length();
int i = 0;

string edited_text = "";

while(i <>

{

if(sample_text[i] == ' ' && sample_text[i+1] == ' ')

{

i++;

continue;

}else{

edited_text += sample_text[i];

}

i++;


}

if(sample_text[len-1] != ' '){

edited_text += sample_text[len-1];
}

return edited_text;
}





int main(){

string sample_text;

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

getline(cin, sample_text);

cout<>

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

cout<><>



while(true){

char option = PrintMenu(sample_text);

if(option=='q')

break;

}

return 0;



}


5.20 LAB*: Program: Authoring assistant<br>(1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string.<br>Ex:<br>Enter a sample text:<br>We'll continue our quest in space.<br>There will be more shuttle flights and more shuttle crews and,<br>yes,<br>more volunteers, more civilians,<br>more teachers in space. Nothing ends here;<br>our hopes and<br>our journeys continue !<br>You entered: We'll continue our quest in space.<br>There will be more shuttle flights and more<br>shuttle crews and,<br>yes,<br>more volunteers, more civilians,<br>more teachers in space. Nothing ends<br>here;<br>our hopes and our journeys continue!<br>(2) Implement the PrintMenu() function to print the following command menu.<br>Ex:<br>MENU<br>c - Number of non-whitespace characters<br>Number of words<br>f<br>Find text<br>Replace all !'s<br>s - Shorten spaces<br>r<br>Quit<br>(3) Implement the ExecuteMenu() function that takes 2 parameters: a character representing the user's choice and the user provided<br>sample text. ExecuteMenu() performs the menu options, according to the user's choice, by calling the appropriate functions described<br>below.<br>(4) In the main() function, call PrintMenu() and prompt for the user's choice of menu options for analyzing/editing the string. Each option is<br>represented by a single character.<br>If an invalid character is entered, continue to prompt for a valid choice. When a valid option is entered, execute the option by calling<br>ExecuteMenu(). Then, print the menu, and prompt for a new option. Continue until the user enters q. Hint: Implement Quit before<br>implementing other options.<br>Ex:<br>MENU<br>c - Number of non-whitespace characters<br>w - Number of words<br>f - Find text<br>r - Replace all !'s<br>s - Shorten spaces<br>q - Quit<br>Choose an option:<br>

Extracted text: 5.20 LAB*: Program: Authoring assistant (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. Ex: Enter a sample text: 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 ! You entered: 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! (2) Implement the PrintMenu() function to print the following command menu. Ex: MENU c - Number of non-whitespace characters Number of words f Find text Replace all !'s s - Shorten spaces r Quit (3) Implement the ExecuteMenu() function that takes 2 parameters: a character representing the user's choice and the user provided sample text. ExecuteMenu() performs the menu options, according to the user's choice, by calling the appropriate functions described below. (4) In the main() function, call PrintMenu() and prompt for the user's choice of menu options for analyzing/editing the string. Each option is represented by a single character. If an invalid character is entered, continue to prompt for a valid choice. When a valid option is entered, execute the option by calling ExecuteMenu(). Then, print the menu, and prompt for a new option. Continue until the user enters q. Hint: Implement Quit before implementing other options. Ex: MENU c - Number of non-whitespace characters w - Number of words f - Find text r - Replace all !'s s - Shorten spaces q - Quit Choose an option:
4: Unit test a<br>Test PrintMenu(). Should output the menu options.<br>| Compilation failed<br>ain.cpp: In function 'bool testPassed (std::ofstream&)':<br>ain.cpp:154:14: error: too few arguments to function 'char PrintMenu (std:<br>154 |<br>PrintMenu () ;<br>Compilation failed<br>ain.cpp:13: 9: note: declared here<br>13 |<br>char PrintMenu (string sample_text) {<br>5: Unit test a<br>Test ExecuteMenu('w', This is a test.

Extracted text: 4: Unit test a Test PrintMenu(). Should output the menu options. | Compilation failed ain.cpp: In function 'bool testPassed (std::ofstream&)': ain.cpp:154:14: error: too few arguments to function 'char PrintMenu (std: 154 | PrintMenu () ; Compilation failed ain.cpp:13: 9: note: declared here 13 | char PrintMenu (string sample_text) { 5: Unit test a Test ExecuteMenu('w', This is a test."). Should output "Number of words: 4" Compilation failed main.cpp: In function 'bool testPassed (std: :ofstream&)' : main.cpp:157:4: error: 'ExecuteMenu' was not declared in this scope Compilation failed 157 | ExecuteMenu (userOption, usrStr); ~~~~~~~~
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here