1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pychu [463]
3 years ago
11

Write a program that will read in a line of text and output the number of words in the line and the number of occurrences of eac

h letter. Define a word to b any string of letters that is delimited at each end by either 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 letters as the same letter. Output the letters I alphabetical order and list only those letters that do occur in the input line.

Computers and Technology
1 answer:
kherson [118]3 years ago
7 0

Answer:

Here is the C++ program:

#include<iostream>  //to use input output functions

#include <algorithm>  //to use tolower() function

using namespace std;  //to identify objects like cin cout

int main() {  //start of main function

 string text;  // to hold text input

 cout<<"Enter a line of text: ";  // prompts user to enter a string

 getline(cin,text);  // reads the input string (text) from user

transform(text.begin(), text.end(), text.begin(), ::tolower);  //converts the text into lower case

 int letter[26] = {0}; //to hold the letters

 int i;  // used as a loop variable

 int words=0;  // to hold the count of words

 for(i = 0; i< text.size();i++){  // iterates through the text

 if(isalpha(text[i])&&(text[i+1]=='.'||text[i+1]==','||text[i+1]==' '))  //checks if the character at i-th index of text is a letter, and checks if i+1 index position of text is a period, comma or a space

 words++;  // adds 1 to the count of words

 if(isalpha(text[i]))  // if the character at the i-th index of text is a letter

 letter[text[i]-'a']++;  }  // counts the occurrences of each letter

 char j = text[text.size()-1];  // sets j to the last character of text

 if(j != '.' && j!= ' '&& j!=',' &&j!= '\0')  //if the last character is not a period or empty space  or comma or end of lone

 words++;  //add 1 to the count of words

 cout<<"Number of words: "<<words<<endl;  //display the number of words in the text

 for(i=0; i<26; i++)  {  //iterates 25 times

   if(letter[i]>0)  //if letter at index i is greater than 0

   cout<<(char)('a'+i)<<" : "<<letter[i]<<endl;  }} //displays each letters and its number of occurrences in the text

 

Explanation:

The program is explained in the attached document with an example.

You might be interested in
What is the basic purpose of Google calendar?
goldenfox [79]
The basic purpose of a google calendar is basically the same as a regular calendar. it is used to keep track life's important events all in one place.    
7 0
3 years ago
Read 2 more answers
PLEASE-I'M STUCK!!!!!!!!!!!!!!!!!!!!!!
Blababa [14]

Answer: Input is the answer.

8 0
2 years ago
Carlos had 194 seeds and 11 flower pots he put the same number of seeds in each flower pot which is the best estimate for the nu
Inessa [10]

Answer:

20?

Explanation:

4 0
2 years ago
The AutoRecovery feature would be useful for which situations? Check all that apply.
Aliun [14]

Answer:

All of the above but I'm not 100% sure.

5 0
3 years ago
A clock is reading 10:27:54.0 (hr:min:sec) when it is discovered to be 4 seconds fast. Explain why it is undesirable to set it b
lara31 [8.8K]

Answer:

(a)Applications Time Stamp Events

(b)S=0.5(W-T_{skew})+T_{skew}, where T_{skew}≤W≤T_{skew}+8.

Explanation:

Some applications assume that clocks always advance, so they could timestamp events under this assumption.

In our case we have the wrong timed clock, say W and the hardware clock H which is supposed to advance at a perfect rate.

We proceed to construct a software clock such that after 8 seconds we can replace the wrong timed clock with the software clock in good conditions.

Let us denote the software clock with S.

Then, S=c(W-T_{skew})+T_{skew} where:

T_{skew}=The current Time(10:27:54) and;

c is to be found.

We already know that S=T_{skew}+4 when W= T_{skew}+8,

So:

S=c(W-T_{skew})+T_{skew}

T_{skew}+4=c(T_{skew}+8-T_{skew})+T_{skew}

4=8c

c=0.5

We obtain the formula

S=0.5(W-T_{skew})+T_{skew}, where T_{skew}≤W≤T_{skew}+8.

4 0
3 years ago
Other questions:
  • Write a method called printRange that accepts two integers as arguments and prints the sequence of numbers between the two argum
    6·1 answer
  • What is the least number of bits you would need to borrow from the network portion of a Class B subnet mask to get at least 130
    10·1 answer
  • Your supervisor has asked you to set up a RAID hard drive array in a tower system, which has a motherboard that uses the B360 ch
    10·1 answer
  • A colleague asks you to research a CPU for a new server that will run Windows Server 2019. He explains the server roles that he
    7·1 answer
  • The mathematical constant Pi is an irrational number with value approximately 3.1415928... The precise value of this constant ca
    12·1 answer
  • Please help!!
    8·1 answer
  • I really need this done Thank you!!
    6·1 answer
  • Name:
    11·1 answer
  • Edhesive 7.6 lesson practice python
    11·1 answer
  • c++ 4.17 LAB: Count characters Write a program whose input is a character and a string, and whose output indicates the number of
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!