Write a program that counts number of words in a sentence and displays the avera
ID: 3634567 • Letter: W
Question
Write a program that counts number of words in a sentence and displays the average number of letters in each word. Your program should ask the user to type a sentence (or sentences) that are 80 characters or less. If the sentence is longer than 80 characters, truncate it and notify the user of your action.Your program should call:
A function that accepts a string class object as its argument and returns the number of words contained in the string. For example, if the string argument is “Four score and seven years ago” the function should return the number 6.
A function that accepts a string class object as its argument and returns the number of punctuation characters (period, comma, exclamation, etc.) in the sentence(s).
A function that accepts a string class object as its argument and returns the average number of letters in each word.
Your program should present the user with the following menu:
A. Count number of words in the sentence
B. Count number of punctuations in the sentence
C. Compute the average number of letters in each word
D. Enter another sentence
E. Exit
The program should exit when the user selects “E” to exit the program. Pass data to your functions by value, by reference, and use static variables if necessary.
Explanation / Answer
#include #include #include #include using namespace std; const int MAX = 80; int countWords(const string&); int countPunc(const string&); int main(int argc, char *argv[]) { string input, choice; char ch; coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.