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
For a certain company, the cost function for producing x items is C(x)=50x+100 and the revenue function for selling x items is R
solmaris [256]

Assuming that this company sells all that it produces, the profit function would be given by P(x) = -0.5(x - 100)² + 5,000 - 50x - 100.

<h3>What is profit?</h3>

In Economics, profit can be defined as a measure of the amount of money (revenue) that is generated when the selling price is deducted from the cost price of a good or service, which is usually provided by producers.

This ultimately implies that, all producers generally work to maximize their profits and make them as large as possible, in order to enable them break even and successful.

Mathematically, the profit function P(x) of a business firm simply refers to the revenue function R(x) minus the cost function C(x):

P(x) = R(x) - C(x)

Where:

  • R(x) represents how much it takes in.
  • C(x) represents how much it spends.

Substituting the given parameters into the formula, we have;

P(x) = -0.5(x - 100)² + 5,000 - (50x + 100)

P(x) = -0.5(x - 100)² + 5,000 - 50x - 100

Read more on maximized profit here: brainly.com/question/13800671

#SPJ1

7 0
2 years ago
In QBasic, create a number guessing challenge. Your program should generate a random number from 1-
Sergio039 [100]

Answer:

yes

Explanation:

6 0
2 years ago
What is tnylnk? I keep seeing people leave answers with this.....can someone explain what this is, please...I might give brainie
Naddika [18.5K]

Answer:

ITS A SCAM IT DOWN LOADS NASTY STUFF ON TO UR COMPUTER

Explanation:

hope this helps

8 0
2 years ago
Read 2 more answers
Which of the following is the single best rule to enforce when designing complex passwords?
saw5 [17]

Answer:

B. Longer passwords

Explanation:

If the password is longer, it requires more incorrect attempts to find it, so the system could identify a potential hacker attempt. Smaller but more complex passwords could be identified by mistype or forgotten passwords.

3 0
2 years ago
Which item converts a high level language program to low level machine instruction?
vodomira [7]
The compiler translates each source code instruction into the appropriate machine language instruction, an
8 0
3 years ago
Other questions:
  • ​A(n) ____ will hold an online auction buyer’s payment until he or she is satisfied that the item bought matches the seller’s de
    13·1 answer
  • 1. You have recently been hired by a leading firm, which provides information management solutions to large corporations. As a n
    12·2 answers
  • Develop a C++ program that will determine whether a department store customer has exceeded the credit limit on a charge account.
    13·1 answer
  • What was the first computer programming language?
    7·2 answers
  • State the functions of all the parts of the computer​
    14·1 answer
  • Sustainable development is a goal towards which all human societies need to be moving. elaborate the statement in about 120 word
    9·1 answer
  • When using the Photo Album dialog box, a picture
    13·2 answers
  • Select the correct answer.
    5·1 answer
  • How does a computer do its work? Mention its working principle.<br><br>​
    8·1 answer
  • What is the launching of a 3-D map called?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!