
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;
}


Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- //I need help debugging the C code below the image is what I was following for directions while doing the code// #include <stdio.h> #include <stdlib.h> struct employees { char name[20]; int ssn[9]; int yearBorn, salary; }; // function to read the employee data from the user void readEmployee(struct employees *emp) { printf("Enter name: "); gets(emp->name); printf("Enter ssn: "); for (int i = 0; i < 9; i++) scanf("%d", &emp->ssn[i]); printf("Enter birth year: "); scanf("%d", &emp->yearBorn); printf("Enter salary: "); scanf("%d", &emp->salary); } // function to create a pointer of employee type struct employees *createEmployee() { // creating the pointer struct employees *emp = malloc(sizeof(struct employees)); // function to read the data readEmployee(emp); // returning the data return emp; } // function to print the employee data to console void display(struct…arrow_forwardIn c++, please and thank you! Write a function that dynamically allocates an array of integers. The function should accept an integer argument indicating the number of elements to allocate. The function should return a pointer to the array.arrow_forwarddemo.cpp #include "Poly.h" #include<iostream> using namespace std; int main() { Poly p1; couble d[3]={1,2,3}: Poly p2(3, d); Poly p3(p2); cout << "Polynomial p1 is: "; p1.display(); cout << "Polynomial p2 is: " << p2 << endl; cout << "Polynomial p3 is: " << p3 << endl; if (p2 == p3) { cout << "p2 and p3 are the same."; } else { cout << "p2 and p3 are different."; } cout << endl; cout << "The coefficient of power 1 of p3 is: " << p2.getCoef(1) << endl; p3.setCoef(1, 99); cout << "p3 after setup is: " << p3 << endl; if (p2 == p3) { cout << "p2 and p3 are the same."; } else { cout << "p2 and p3 are different."; } cout << endl; Poly p4; cout << "Please enter the power and coefficients of Polynomial p4: " << endl; cin >> p4; cout <<…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





