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
1. JAVA Create one method to do the following expressions. Given the following declarations, what is the result of each of the e
nordsb [41]
<span>public void myMethod(int w, int y, int z) {
</span>int a, b, c, d, e, f, g, h, i, j, k, l;

<span>a = w * z;
</span>b = w * z + y;
c = w * -z;
d = w * --z + y++;
e = w * z-- + ++y<span> ;
</span>f = w + z * y;
g =  w – y + z;
h = (w + y) * z;
i = y / w;
j = y / z;
k = w % y;
<span>l = y % w;
</span>System.out.println( "%d %d %d %d %d %d %d %d %d %d %d %d", a,b,c,d,e,f,g,h,i,j,k);
}

To use 
myMethod(2, 7, 12);
7 0
3 years ago
Pls help ...
dedylja [7]

Answer:

  • You open the class, and print sleep after thread 3000
  • So A
8 0
3 years ago
What is the main reason that IT managers believe the future IT career model will be diamond-shaped, with few entry-level IT jobs
Valentin [98]
<span>In which career field, would the Computing Technology Industry Association's CompTIA A+ certification be useful?</span>
4 0
3 years ago
Consider the following import statement in Python, where statsmodels module is called in order to use the proportions_ztest meth
den301095 [7]

Answer:

a. count of observations that meet a condition (counts), total number of observations (nobs), Hypothesized value of population proportion (value).

Explanation:

In other to use the proportion_ztest method, the need to make import from the statsmodel module ; statsmodels.stats.proportion.proportions_ztest ; this will allow use use the Z test for proportion and once this method is called it will require the following arguments (count, nobs, value=None, alternative='two-sided', prop_var=False)

Where;

nobs = number of observations

count = number of successes in the nobs trial or the number of successes for each independent sample.

Value = hypothesized value of the population proportion.

7 0
3 years ago
Modify the code below to do the following:
Kitty [74]

Answer:

The code is appropriately given below with comments for better understanding

Explanation:

#include <linux/init.h>

#include <linux/module.h>

#include <linux/kernel.h>

#include <linux/hash.h>

#include <linux/gcd.h>

#include <asm/param.h>

#include <linux/jiffies.h>

/* This function is called when the module is loaded. */

static int simple_init(void)

{

  printk(KERN_INFO "Loading Module\n");

  printk(KERN_INFO "These are the HZ: %d\n", HZ);

  printk(KERN_INFO "These are the jiffies: %lu\n", jiffies);

  printk(KERN_INFO "Golden Ratio is: %lu\n", GOLDEN_RATIO_PRIME);  

  return 0;

}

/* This function is called when the module is removed. */

static void simple_exit(void) {

  printk(KERN_INFO "Removing Module");

  unsigned long a = gcd(3300, 24);

  printk(KERN_INFO "Greatest Common Denominator between 3,300 and 24 is: %lu\n", a);

  printk(KERN_INFO "These are the jiffies: %lu\n", jiffies);

}

/* Macros for registering module entry and exit points. */

module_init( simple_init );

module_exit( simple_exit );

MODULE_LICENSE("GPL");

MODULE_DESCRIPTION("Simple Module");

MODULE_AUTHOR("SGG");

7 0
3 years ago
Other questions:
  • Which of the following criteria would not make a person eligible to receive medicare benefits?Which of the following criteria wo
    12·2 answers
  • What does the do not disturb button do on the iphone?
    12·1 answer
  • They begin beating it with a hose to find out what it really means. How does the figurative language in this excerpt reveal Coll
    9·2 answers
  • An embedded os must be developed specifically for use with embedded systems. true or false?
    6·1 answer
  • What is a system unit
    7·1 answer
  • Whats yall favv scary movie
    11·1 answer
  • An optical fibre has an attenuation of 0.3 dB/km. If a laser launches an optical power level of PIN (mW) into 35 km length of th
    8·1 answer
  • Which of the following are causes of a run-time error. Choose all that apply.
    13·1 answer
  • _____ oversee the work of various types of computer professionals and must be able to communicate with people in technical and n
    5·1 answer
  • A(n) _____ is a data validation rule that should be applied to mandatory data items.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!