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
How was science used to make television?
Wewaii [24]

Answer:

Sir William Crookes invented the cathode ray tube in 1878, but these discoveries took many years to merge into the common ground of television. His mechanical system used a scanning disk with small holes to pick up image fragments and imprint them on a light-sensitive selenium tube. A receiver reassembled the picture.

5 0
3 years ago
Read 2 more answers
Four examples of computer virus​
Nikitich [7]

Virus that infects files. Macro Virus is a virus that attaches itself to an executable application. This type of virus is commonly found in Microsoft Word or Excel programs.... Browser Hijacker.... Web Scripting Virus.

Good morning, I hope this helps, and if you don't mind, please mark me as brainliest ❤

4 0
3 years ago
You have a small company and want to keep your costs low, but it is important your employees share data. Which network would pro
Crank

Answer:

centralised

Explanation:

duhh

7 0
3 years ago
Read 2 more answers
The parallax perspective says that objects that are close up appear to move __________ than far away objects.
serious [3.7K]

Answer:

It appears to move faster.

5 0
3 years ago
Assume that two classes 'Temperature' and 'Sensor' have been defined. 'Temperature' has a constructor that accepts a double para
Black_prince [1.1K]

Answer:

The answer for the following question is given as:

public static Temperature create(Sensor ob)

{

return new Temperature(ob.getReading());

}

Explanation:

In this we have create a static method of  Temperature class which accept a 'Sensor' object and  return the new 'Temperature' object that calls the 'getReading()' function This function returns the sensor's current reading.

7 0
3 years ago
Other questions:
  • What type of devices are the key board and the mouse?
    10·1 answer
  • Mike is reading about machine-dependent programming languages. Which languages are machine-dependent programming languages?
    11·1 answer
  • T F The scope of a parameter is limited to the function which uses it.
    12·1 answer
  • Your boss bought a new printer with a USB 3.0 port, and it came with a USB 3.0 cable. Your boss asks you:
    7·2 answers
  • Your company has a wireless network for its small office network. The wireless network does not broadcast its service set identi
    11·1 answer
  • For what purpose is keylogging software used? a. To automatically translate input to another language as the user enters data b.
    10·1 answer
  • In the language of the World Wide Web, "this page cannot be displayed" means A. your computer's software is damaged. B. the ISP
    10·2 answers
  • Declare an ArrayList of Strings. Add eight names to the collection. Output the Strings onto the console using the enhanced for l
    9·1 answer
  • For each of the descriptions below, perform the following tasks:
    11·1 answer
  • What is "mob of the dead"?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!