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
Shadow and highlight create depth (3D).<br> TRUE OR FALSE
tamaranim1 [39]

Answer:

true because then it would be like not popping out

7 0
3 years ago
Given the following MIPS Code Fragment:
galben [10]

Answer:

There are 3 Data Hazard

Explanation:

Find attached the solution

6 0
3 years ago
These operating systems were referred to as command-based.
Doss [256]

{\underline{\boxed{\bf{MS - DOS \:  and \:  UNIX}}}}

3 0
2 years ago
Read 2 more answers
What is the dividend rate for ibm stock?
Vaselesa [24]
3.28% I think 
......................................................................................................................................
5 0
3 years ago
Whenever you are designing a project for commercial use (making money) and need to use photographs with people in them you must
Leya [2.2K]

Answer:

Copyright

Explanation:

7 0
3 years ago
Other questions:
  • What can you do with someone's ip address?
    9·1 answer
  • I'm looking for a new laptop for school. Which laptop would be the best. Right now I have a chromebook and it is broken. 
    12·2 answers
  • Lisa is modifying a spreadsheet. Which view will allow Lisa to see how her changes will look when she prints the spreadsheet?
    13·2 answers
  • 2. Integer plot function (find a smart way to code big integers) Write a program BigInt(n) that displays an arbitrary positive i
    8·1 answer
  • Clicking the ____ opens the insert function dialog box.
    13·1 answer
  • In a word-processing program, what are the easily accessible icons that allow you to print, save and change fonts with a click o
    8·1 answer
  • He should identify his various
    6·1 answer
  • Describe risk avoidance. Name three common methods of risk avoidance.
    5·1 answer
  • What role does the automated surface observing system.
    5·2 answers
  • Which network device sends data to every device that is connected to it?.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!