Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here's the code I have so far, I need help with my code. I only got 7/20. Here's the question: 6.20 HW 4: Authoring assistant

Here's the code I have so far, I need help with my code. I only got 7/20. Here's the question:

6.20 HW 4: Authoring assistant (C++)

(1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) 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 a PrintMenu() function, which has a string as a parameter, outputs a menu of user options for analyzing/editing the string, and returns the user's entered menu option. Each option is represented by a single character.

If an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call PrintMenu() in the main() function. Continue to call PrintMenu() until the user enters q to Quit. (3 pts) 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: 

(3) Implement the GetNumOfNonWSCharacters() function. GetNumOfNonWSCharacters() has a constant string as a parameter and returns the number of characters in the string, excluding all whitespace. Call GetNumOfNonWSCharacters() in the PrintMenu() function. (4 pts) Ex:

Number of non-whitespace characters: 181 

(4) Implement the GetNumOfWords() function. GetNumOfWords() has a constant string as a parameter and returns the number of words in the string. Hint: Words end when a space is reached except for the last word in a sentence. Call GetNumOfWords() in the PrintMenu() function. (3 pts) Ex:

Number of words: 35 

(5) Implement the FindText() function, which has two strings as parameters. The first parameter is the text to be found in the user provided sample text, and the second parameter is the user provided sample text. The function returns the number of instances a word or phrase is found in the string. In the PrintMenu() function, prompt the user for a word or phrase to be found and then call FindText() in the PrintMenu() function. Before the prompt, call cin.ignore() to allow the user to input a new string. (3 pts) Ex:

Enter a word or phrase to be found: more "more" instances: 5 

(6) Implement the ReplaceExclamation() function. ReplaceExclamation() has a string parameter and updates the string by replacing each '!' character in the string with a '.' character. ReplaceExclamation() DOES NOT output the string. Call ReplaceExclamation() in the PrintMenu() function, and then output the edited string. (3 pts) Ex.

Edited 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. 

(7) Implement the ShortenSpace() function. ShortenSpace() has a string parameter and updates the string by replacing all sequences of 2 or more spaces with a single space. ShortenSpace() DOES NOT output the string. Call ShortenSpace() in the PrintMenu() function, and then output the edited string. (3 pt) Ex:

Edited 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! 

#include #include #include #include #include using namespace std; void PrintMenu(string); int GetNumOfNonWSCharacters(string); int GetNumOfWords(string); void FindText(string,string); void ReplaceExclamation(string); void ShortenSpace(string);

int main() { string line; cout<<"Enter a sample text: "; getline(cin,line); cout<<" "; cout<<"You entered: "< PrintMenu(line); return 0; } //method for printing menu each time void PrintMenu(string line) { char ch; string word; while(ch!='q') { cout< cout<<"MENU"< cout<<"c - Number of non-whitespace characters"< cout<<"w - Number of words"< cout<<"f - Find text"< cout<<"r - Replace all !'s"< cout<<"s - Shorten spaces"< cout<<"q - Quit"< cout< cout<<"Choose an option: "; cin>>ch; cout< switch (ch) { case 'c': cout< break; case 'w':cout< break; case 'f': cout<<"enter word:"; cin>>word; FindText(line,word); break; case 'r':ReplaceExclamation(line); break; case 's':ShortenSpace(line); break; case 'q':break; default:break; } } }

//getting number of chars excluding the spaces int GetNumOfNonWSCharacters(string line) { int count=0; for(int i = 0;i if (!isspace(line[i])) count++; } return count; }

//method for number of rows int GetNumOfWords(string line) { int count=0; for(int i = 0;i if (isspace(line[i])) { count++; while(!isspace(line[i])) { } } } return count; }

//finding text void FindText(string line,string word) { if (line.find(word) != std::string::npos) { cout << "found!" << ' '; } else { cout << "Not found!" << ' '; } }

//method for replacing the ! void ReplaceExclamation(string line) { for(int i = 0;i if (line[i]=='!') { line[i]='.'; } } cout< }

//remove spaces void ShortenSpace(string line) { line.erase( std::remove_if( line.begin(), line.end(), ::isspace ), line.end() ); cout<

}

Please help me with this!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

Students also viewed these Databases questions

Question

Assessment of skills and interests.

Answered: 1 week ago

Question

Psychological, financial, and career counseling.

Answered: 1 week ago