Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will read in a line of text up to 100 characters as a C-sty

ID: 3551724 • Letter: W

Question

Write a program that will read in a line of text up to 100 characters as a C-style string, and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, and periods.

When outputting the number of letters that occur in a line, be sure to count upper- and lowercase versions of a letter as the same letter. Output the letters in alphabetical order and list only those letters that do occur in the input line. For example:

I say Hi.

You have 3 words with these letters: 1a
1h
2i

1s 1y

Requirements for your program:

o Read sentence from user.
o Do not modify the original sentence!!!!
o Print the number of words and number of occurrences of each letter.
o All functions (including main) must not be more than 15 lines of code!!!

c++

Explanation / Answer

#include<iostream>
#include<sstream>
#include<cstring>
using namespace std;
void countChars(char ch,int list[]) {
if(ch>=65 && ch<=90) list[ch-65]++; else if(ch>=97 && ch<=122) list[ch-97]++; }
int main(){
char input[100];int list[26]={0};string str;int count=0;
cout <<"Enter a Sentence :";
cin.getline(input,100); cout << endl; istringstream iss(input);iss >> str;
do {count++; for(int i=0; i<str.length(); i++) countChars(str[i],list); iss >> str;}while(iss);
cout <<"You have "<<(count) <<" words with these letters: ";
for(int i=0; i<26; i++) if(list[i]!=0) cout << list[i] << static_cast<char> (i+97) << endl; return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote