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 amount of a good or service that business have available to sell?
REY [17]
The answer is supply
3 0
3 years ago
Select the statement that best describes the function of the cell wall. O it gives shape to plants cells. O it produces food fro
Maslowich
It’s jelly like fluid surrounds the nucleus
8 0
2 years ago
Question 2 (2 points)
swat32

I beleive all of the above for question one

4 0
3 years ago
To maintain your body temperature, your body converts chemical potential energy into thermal energy T or F
PilotLPTM [1.2K]
True
This is physics btw
CPE --> TE
4 0
3 years ago
Importance/Role of the information systems in Education​
JulsSmile [24]

Answer:

Information technology can be used to promote opportunities for knowledge dissemination.

Explanation:

It can help the teachers and students have up-to-date information and knowledge. The accurate and right information is necessary for effective teaching and learning; and information technology

7 0
2 years ago
Other questions:
  • Write an expression that evaluates to true if and only if the value of the integer variable workedOvertime is true.
    7·1 answer
  • What will be displayed as a result of executing the following code?
    5·1 answer
  • If metal shims are used for alignment adjustment in the front, they adjust ________.
    5·1 answer
  • What is the device that uses sprockets along a film's perforated edges to run 50 feet of film in thirty seconds? A. cinematograp
    10·1 answer
  • Suppose that a computer has three types of floating point operations: add, multiply, and divide. By performing optimizations to
    7·1 answer
  • What is the purpose of a hyperlink in a presentation?
    11·1 answer
  • In a List of Positive Integers, Set MINIMUM to 1. For each number X in the list L, compare it to MINIMUM. If X is smaller, set M
    11·1 answer
  • What is the optimal number of members for an Agile team?
    10·1 answer
  • To read encrypted data, the recipient must decipher it into a readable form. What is the term for this process?.
    12·1 answer
  • What is the name of the method generated when you double-click a button named btnprocess in the form designer?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!