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
Point mode allows you to select cells for use in a formula by using your finger or the pointer
Serga [27]
That statement is true

in excel, you could enter point mode by pressing any keyboard navigation such as page down, page up, or the arrow keys or by clicking any cells in the worksheet

This mode will select a cell or range as formula operand


7 0
3 years ago
Write a public member function which replace that replaces one occurrence of a given item in the ArrayBag with another passed as
ira [324]

Answer:

The method is written in Java

public static boolean abc(int [] ArrayBag,int num, int replace){

    Boolean done = false;

    for(int i =0; i<ArrayBag.length;i++){

        if(ArrayBag[i] == num){

            ArrayBag[i] = replace;

            done = true;

        }

    }

    for(int i = 0;i<ArrayBag.length;i++){

        System.out.println(ArrayBag[i]+" ");

    }

    return done;

}

Explanation:

The method is written in java

The arguments of the method are:

<em>1. ArrayBag -> The array declares as integer</em>

<em>2. num -> The array element to check the presence</em>

<em>3. replace - > The replacement variable</em>

This line defines the method as boolean.

public static boolean abc(int [] ArrayBag,int num, int replace){

This line declares a boolean variable as false

    Boolean done = false;

The following iterates through the elements of the array

    for(int i =0; i<ArrayBag.length;i++){

This checks if the array element exist

        if(ArrayBag[i] == num){

If yes, the array element is replaced

            ArrayBag[i] = replace;

The boolean variable is updated from false to true

            done = true;

        }

    }

The following iteration prints the elements of the array

<em>     for(int i = 0;i<ArrayBag.length;i++){</em>

<em>         System.out.println(ArrayBag[i]+" ");</em>

<em>     }</em>

This prints returns the boolean thats indicates if replacement was done or not.

    return done;

}

<em>Attached to this solution is the program source file that includes the main method of the program</em>

Download txt
5 0
3 years ago
Which one of the following pieces of information would be allowed as part of a limited data set?
Inessa05 [86]
Phone number would be allowed
6 0
3 years ago
All of the following are simple steps for optimizing web page content except:
dangina [55]

Answer:

The correct answer is letter "B": segmenting computer servers to perform dedicated functions.

Explanation:

Computer segmentation refers to separating a server from the rest of the computers within the same network. The segmentation can separate one computer from others or groups of servers from one another. Thew type of segmentation will always depend on the device used to do the separation of the servers.

3 0
3 years ago
Write some positive and negative impacts of computer in our daily life​
8090 [49]
Positive impacts are
1. Communicating with people
2. Daily update of what going on in the world
3. learn new things
Negative impacts are
1. Viruses
2. Private information shared
3. Less face to face conversations
3 0
2 years ago
Other questions:
  • Image files are grouped into two categories: _____.
    5·1 answer
  • 7. What is the school campus’s setting<br> the school is sanford
    6·2 answers
  • Which of the following parameters should match in order for a pair of routers to form an adjacency when running OSPFv2? (Points
    9·1 answer
  • "list at least 3 key performance indicators that should be considered prior to initiating a cloud deployment."
    15·1 answer
  • Which property is assigned to a file by the operating system?
    13·1 answer
  • Nielsen purchases scanner data from retail transactions to track the sales of consumer packaged goods, gathered at the point of
    14·1 answer
  • In a study on software license infringement, those from United States were significantly more permissive than those from the Net
    15·1 answer
  • A seven-octet pattern of alternating 0s and 1s used by the receiver to establish bit synchronization is a _______
    11·1 answer
  • Select the correct answer. Which sign or symbol will you use to lock cells for absolute cell reference?
    9·2 answers
  • A network of computers that provides access to information on the web.
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!