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
frutty [35]
3 years ago
8

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

th an integer indicating the number of words that follow. Assume that the list will always contain less than 20 words.
Computers and Technology
1 answer:
Margaret [11]3 years ago
4 0

Answer:

The following are the program in the C++ Programming Language:

#include <iostream> //header file

#include <string>  //header file

#include <vector>  //header file

//name space

using namespace std;

//main function

int main() {

  vector<string> word; //set variable

  vector<int> c;  //set variable

  int s, counts = 0; //set variable

  string strng;  //set variable

  cout<<"Enter the size of string: "; //print message

  cin >> s; //get input

  cout<<"Enter the string: "; //print message

  for(int i = 0; i < s; ++i) {  //set for loop

     cin >> strng; //get input

     word.push_back(strng);

  }

  for(int i = 0; i < s; ++i) { //set for loop

         counts = 0;

         for(int j = 0;j<word.size();j++){ //set for loop

       if(word[j] == word[i]){ //set if statement

          counts++; //increament in counts

       }        

     }

      c.push_back(counts);

  }

  for(int i = 0; i < s; ++i) {

      cout << word[i] << " " << c[i] << endl;//print result

  }

  return 0;

}

<u>Output</u>:

Enter the size of string: 2

Enter the string: hello  sir

hello 1

sir 1

Explanation:

Here, we define three header files <iostream>, <String>, <vector> and namespace "std" after that we define main() method inside it.

  • Then, we set two vector type variables first one is string variable "word" and the second one is integer variable "c".
  • Then we set two integer variable "s" and "counts" and variable "counts" assign to 0.
  • Then, we get input from the user in variable "s" for the length of the loop.
  • Then, we set for the loop inside it, we get input in the variable "strng" from the user.
  • Then, we set the for loop for count the string repetition if any word comes again in the string then the value of count will increase.
  • Finally, we set for a loop to print the result.
You might be interested in
Choose the appropriate software category for each specific application shown.
Tom [10]
Python is the correct answer
7 0
2 years ago
Which of the following is a characteristic of the college savings plan
Hoochie [10]

add the choices please

8 0
3 years ago
Read 2 more answers
Wich is the correct process for selecting an entire row in a spreadsheet?
umka21 [38]
CTRL - (select sentence) - ALT

4 0
3 years ago
Media has scientifically been linked to media messages, as in the cause and effect theory. True or False?
padilas [110]

Answer:

true

this ans is not 100% correct but it may help you

4 0
3 years ago
Please help! Why might NASCAR engineers modify racecars to create the type of drag your racecar experienced?
lutik1710 [3]
They modify is bcuz every race car is different and the driver is going to want something different then everyone else. 
4 0
3 years ago
Other questions:
  • Add the following functions to the code:
    9·1 answer
  • Which company provides the Loki Wi-Fi mapping service?
    10·1 answer
  • Below is a chart representing portions of resumes from 3 applicants. Which best explains the applicants careers?
    11·1 answer
  • Prepare a risk assessment report (RAR) with information on the threats, vulnerabilities, likelihood of exploitation of security
    14·1 answer
  • Which of the following is not considered format?
    8·2 answers
  • The process of combining rows and columns in a table is called _____.
    8·1 answer
  • Where does the list of incoming mail appear in gmail
    13·2 answers
  • Choose the word that matches each definition. : processed facts, how the output is used for making decisions : action performed
    12·2 answers
  • Using Microsoft Word, write a 250-word essay on the fading of home telephone use with the advent of recent technology, and share
    14·1 answer
  • Historically, storytelling passed down the most important ideas about life, family, and society from generation to generation; t
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!