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
What is an html skeleton? If you know what it is can you write it for me?
shtirl [24]

Answer:

HTML Skeleton. The basic HTML skeleton is the set of tags required of every HTML web page you build. The tags that make up the skeleton tell browsers what kind of file it is reading, and without the skeleton HTML files will not be rendered correctly in web browsers. There are four tags that need to be included in the skeleton.

Explanation:

5 0
3 years ago
I was wondering how to give a person a Brainliest answer. Could someone please explain to me the steps on to giving someone a Br
alina1380 [7]
When more than 1 person gives an answer to your question, you receive the option to tick the one you think is more well-explained or thought out in order to make that the Brainliest Answer :)
4 0
3 years ago
What is the simplest way to permanently get rid of an unwanted file? A. Cancel the file. B. Go to the Start menu and then delete
Morgarella [4.7K]
Go to the Start menu and then delete the file <span>is the simplest way to permanently get rid of an unwanted file</span>
5 0
4 years ago
In the following code fragment, how many times is the count() method called as a function of the variable n? Use big-O notation,
ahrayia [7]

Answer:

The loop counts the count() function length of n-1 times with respect to n.

Explanation:

The first and outer loop counts for two times as the variable declared in the condition counts before the iteration is made. The same goes for the other for statements in the source code.

The n represents the number length of a range of numbers or iterables (like an array).

4 0
3 years ago
In order to get a great sports photograph, you need to do what?
Alik [6]
The answer is Anticipate the action.  <span>In order to get a great sports photograph, you need to anticipate the action.  </span><span>A big part of </span>sports photography<span> is </span>anticipating action.  <span>The photographer will be able to anticipate the action so that the camera will be pointed in the right direction to capture the decisive moments on film</span>
8 0
4 years ago
Read 2 more answers
Other questions:
  • Web maintenance plays a vital role in a website's development. It helps ensure the online presence of any website by performing
    8·1 answer
  • The ability to anticipate and determine upcoming driving hazards and conditions are adversely affected by stress.
    10·1 answer
  • What variation of a dictionary attack involves a dictionary attack combined with a brute force attack, and will slightly alter d
    5·1 answer
  • A difference between crt monitors and flat-panel displays is that most flat-panel displays use digital signals to display images
    8·1 answer
  • What are the examples of shareware?
    9·2 answers
  • What offers backup services that use cloud resources to protect applications and data from disruption caused by disaster? Multip
    9·1 answer
  • Lucy wants to add some notes in her research paper that provide additional information to the reader. She also wants to display
    14·1 answer
  • Choose two technologies that you think would help the company meet its goals. Then fill in the chart below to compare the techno
    11·2 answers
  • The default print setting for worksheets is________
    13·1 answer
  • Which of the following is/are used in multimedia?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!