Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

c++ Need help with part 4 

so far i have this:

#include <iostream>
#include <string>
using namespace std;

void printMenu() {
cout << "\nMENU" << endl;
cout << "c - Number of non-whitespace characters" << endl;
cout << "w - Number of words" << endl;
cout << "f - Find text" << endl;
cout << "r - Replace all !'s" << endl;
cout << "s - Shorten spaces" << endl;
cout << "q - Quit" << endl;
}
string ExecuteMenu(string text, char choice) {
int i, count;
string temp;
int found;
int lenT = text.length(), lenTemp = 0, j;
char t;
switch (choice) {
case 'q':exit(0); break;
case 'c':
count = 0;
for (i = 0; i < text.length(); ++i)
{
if (text[i] != ' ')
count++;
}
cout << "\nNumber of non-whitespace characters : " << count; break;
case 'w':
count = 1;
for (i = 0; i < text.length(); ++i)
{
if (text[i] == ' ')
count++;
}
cout << "\n Number of words : " << count; break;
case 'f':
cout << "Enter the string to find : ";
cin >> temp;
lenTemp = temp.length();
found = text.find(temp);
if (found != string::npos)
cout << "Found Text At : " << found << endl; break;
case 'r':
cout << "Enter the character to replace \"!\" : ";
cin >> t;
for (i = 0; i < text.length(); ++i)
{
if (text[i] == '!')
text[i] = t;
}
cout << "Given string after replace : " << text; break;
case 's':
for (i = 0; i < text.length() - 2; ++i)
{
while (text[i] == ' ' && text[i + 1] == ' ')
{
for (j = i + 1; j < text.length(); j++)
text[j] = text[j + 1];
text[j] = '\0';
}
}
cout << "The given text after shorten spaces : " << text;

}
return text;
}
int main() {

string text;
cout << "Enter a sample text:\n" << endl;
getline(cin, text);

cout << "You entered: ";
cout << text << endl;
int choice;
string t;
while (true) {
printMenu();

cout << "\nChoose an option:" << endl;

cin >> t;
choice = t[0];
if (choice != 'c' && choice != 'w' && choice != 'f' && choice != 'r' && choice != 's' && choice != 'q')
{
cout << "Invalid Choice\nPlease enter Correct Option" << endl;
}
else
text = ExecuteMenu(text, choice);
}
return 0;
}

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:
expand button
Transcribed Image 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:
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY