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]
4 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]4 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
In order to create a horizontal 2-inch-thick dotted green line exactly 2 inches away from the top of the canvas, a graphic artis
Harrizon [31]

Answer:

I Think meter .

Explanation:

Not so Sure

4 0
3 years ago
Read 2 more answers
A(n) ____ is a client, server, or other device that can communicate over a network and is identified by a unique number, known a
Elden [556K]

Answer:

The answer is "node".

Explanation:

The network address is known as a logical or physical address, which defines a networking module/device from a network. It is an allocated numerical number, to every device requiring access to the list or is a member of it.

  • In network communication, it uses the nodes for store data, and there address, these addresses are described by the unique numbers.
  • These node stores data packets, which stores encrypted data.  
7 0
4 years ago
If a question on a job application does not apply to you, simply write
bonufazy [111]
Your answer your looking for is letting D because you don’t know it or it don’t have anything to do with you...
3 0
4 years ago
Read 2 more answers
Chris has just graduated from high school. He hopes to complete a carpenter's apprenticeship and eventually open his own busines
malfutka [58]
I would want to say a goal.
4 0
3 years ago
Read 2 more answers
Where was the first type of computer found
Dennis_Churaev [7]
The ENIAC was invented by J. Presper Eckert and John Mauchly at the University of Pennsylvania and began construction in 1943 and was not completed untill 1946. It occupied about 1,800 square feet and used about 18,000 vacuum tubes, weighing almost 50 tons.
8 0
3 years ago
Read 2 more answers
Other questions:
  • list and briefly explain two other Discovery / inventions that were necessary for the eventual development of the technology nee
    12·1 answer
  • Need help with this file and due today!!
    6·1 answer
  • Type of media that uses laser technology to store data and programs is
    6·1 answer
  • Write a function that, given an array of integers and its size, reverses the elements in the array. For example, if the original
    13·1 answer
  • How to curl your hair with a curling iron
    5·1 answer
  • The time delay of a long-distance call can be determined by multiplying a small fixed constant by the number of communication li
    8·1 answer
  • Select the correct statement(s) regarding a Network Access Point (NAP), also known as an Internet Exchange Point (IXP). a. At a
    12·1 answer
  • E) Point out the errors( if any) and correct them:-
    14·1 answer
  • What does the sign (#) mean in manuscript edpm<br> and also what does (DEL)
    15·1 answer
  • The rules that govern the correct order and usage of the elements of a language are called the of the language:.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!