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
ryzh [129]
3 years ago
13

Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a

n integer indicating the number of words that follow. Assume that the list will always contain less than 20 words. Ex: If the input is: 5 hey hi Mark hi mark the output is: hey 1 hi 2 Mark 1 hi 2 mark 1
Computers and Technology
1 answer:
siniylev [52]3 years ago
3 0

<u>Sample Output</u>

5 hey hi Mark hi mark

hey 1

hi 2

Mark 1

hi 2

mark 1

<u>Explanation</u>

#include <iostream>

#include <vector>

#include <string>

using namespace std;

int main() {

   /* Type you code here. */

   //Define a vector

   //to store the words.

   vector <string> words_list;

   //Define a vector to store

   //the frequencies of the words.

   vector <int> frequency_list;

   

   //Declare the

   //required variables.

   string curr_word;

   int num_words;

   //Read and store the total

   //number of words to be read.

   cin >> num_words;

   //Run the loop to read

   //and store the words

   for(int i=0; i<num_words; i++)

   {

       //Read and store

       //the current word.

       cin >> curr_word;

       

       //Push the current

       //word into the vector.

       words_list.push_back(curr_word);

   }

   //Run the loop to find the

   //frequency of each word.

   for(int i=0; i<num_words; i++)

   {

       //Read the word present at

       //the i'th position in the vector.

       curr_word = words_list.at(i);

       int count = 0;

       //Run the loop to find the

       //frequency of the current word.

       for(int j=0; j<num_words; j++)

       {

           if(words_list.at(j) == curr_word)

           {

               count++;

           }

       }

       //Insert the frequency

       //of the current word.

       frequency_list.push_back(count);

   }

   //Run the loop to display

   //the word and its frequency.

   for(int i=0; i<num_words; i++)

   {

       cout << words_list.at(i)

       << " " << frequency_list.at(i)

       << endl;

   }

   //Return from the

   //main() function.

   return 0;

}

You might be interested in
Help pls put them in order for me??
Natalija [7]

Answer: i can't see the hole thing?

Explanation:

3 0
3 years ago
Read 2 more answers
How can you tell if your car is overheating?
Nitella [24]
A) your temp gauge is moving into red
4 0
3 years ago
Read 2 more answers
Selecting the Tiled windows arrangement option places the windows in a(n) _______ pattern on the screen.
Archy [21]

Answer:

Selecting the Tiled windows arrangement option places the windows in a(n) Grid pattern on the screen.

Explanation:

3 0
2 years ago
These things are commonly found on the front of desktop computer cases:
jok3333 [9.3K]

USB ports, headphone jack/microphone port, and of course, a power button.

3 0
3 years ago
The correct or acceptable way of communicating on the internet is known as
stepladder [879]
I want to say e-mail.

8 0
3 years ago
Other questions:
  • For a project called "The Sheep Market", Aaron Koblin collected drawings of sheep from strangers on the Internet. He posted the
    14·1 answer
  • 4. Scientists are not concerned with the human impact on the environment. True or False?
    6·2 answers
  • 1⁰=?<br> Is equal to...........
    12·2 answers
  • to edit text boxes in a template, first A click on the text box you want to edit B begin typing C format the front D drag the te
    5·2 answers
  • What is the output?
    13·1 answer
  • Explain the paging concept and main disadvantages of pipelined
    15·1 answer
  • ```{r}
    11·1 answer
  • Explain Http and Ftp​
    12·1 answer
  • When a support agent does not know the answer to a question, a good incident management strategy is to tell the user ____.
    5·1 answer
  • The quickest way to change a word is to double
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!