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
koban [17]
3 years ago
9

Write a C++ program that reads from the standard input and counts the number of times each word is seen. A word is a number of n

on-whitespace characters separated by whitespace.
After all input has been processed, print each word that was seen the largest number of times on a line by itself. The words should be printed in alphabetical order.

For example, with the input

Hello ... I said Hello are you there?

your program should print out

Hello

since it was the word that appeared most frequently in the input.

With the input

bow wow bow wow

the program should print out two lines:

bow

wow

Because both of those words appeared most frequently in the input.

If there is no input, your program should generate no output.
Computers and Technology
1 answer:
Rufina [12.5K]3 years ago
4 0

Answer:

#include <stdio.h>

#include <string.h>

#include <ctype.h>

 

struct detail

{

   char word[20];

   int freq;

};

 

int update(struct detail [], const char [], int);

 

int main()

{

   struct detail s[10];

   char string[100], unit[20], c;

   int i = 0, freq = 0, j = 0, count = 0, num = 0;

 

   for (i = 0; i < 10; i++)

   {

      s[i].freq = 0;

   }

   printf("Enter string: ");

   i = 0;

   do

   {

       fflush(stdin);

       c = getchar();

       string[i++] = c;

 

   } while (c != '\n');

   string[i - 1] = '\0';

   printf("The string entered is: %s\n", string);

   for (i = 0; i < strlen(string); i++)

   {

       while (i < strlen(string) && string[i] != ' ' && isalnum(string[i]))

       {

           unit[j++] = string[i++];

       }

       if (j != 0)

       {

           unit[j] = '\0';

           count = update(s, unit, count);

           j = 0;

       }

   }

 

   printf("*****************\nWord\tFrequency\n*****************\n");

   for (i = 0; i < count; i++)

   {

       printf("%s\t   %d\n", s[i].word, s[i].freq);

       if (s[i].freq > 1)

       {

           num++;

       }

   }

   printf("The number of repeated words are %d.\n", num);

 

   return 0;

}

 

int update(struct detail s[], const char unit[], int count)

{

   int i;

 

   for (i = 0; i < count; i++)

   {

       if (strcmp(s[i].word, unit) == 0)

       {

           s[i].freq++;

 

           return count;

       }

   }

   /*If control reaches here, it means no match found in struct*/

   strcpy(s[count].word, unit);

   s[count].freq++;

 

   /*count represents the number of fields updated in array s*/

   return (count + 1);

}

You might be interested in
Who like anime becus i dooooo ( wrote this becuse i forgot what i was writing abot)
mars1129 [50]

Answer:

My bestie loves Animes...... I don't watch anime But good at drawing anime(◠‿◕)

4 0
3 years ago
A _____ is a group of two or more devices/computers connected together to allow for the exchange and information and for the sha
IgorC [24]

Answer:

Network

Explanation:

When you have devices connected together to pass, share and exchange information; this connection is regarded as network.

Take for instance. you need to get a file from your friend's mobile phone; when you connect your phone to your friend's phone via Bluetooth, Xender or via whatever convenient means of connection; that is a network.

Another instance is when you connect multiple systems in a CBT examination; this connection is also regarded as a network.

6 0
4 years ago
Read 2 more answers
2. List the differences between personal
lesantik [10]

Explanation:

Mainframes typically run on large boxes with many processors and tons of storage, as well as high-bandwidth busses. PCs are desktop or mobile devices with a single multi-core processor and typically less than 32GB of memory and a few TBs of disk space. Second, a mainframe OS usually supports many simultaneous users.

5 0
3 years ago
Read 2 more answers
Define function print_popcorn_time() with parameter bag_ounces. If bag_ounces is less than 3, print "Too small". If greater than
yawa3891 [41]

Answer:

void print_popcorn_time(int bag_ounces){

   if(bag_ounces < 3){

       cout<<"Too small"<<endl;

   }else if(bag_ounces > 10){

       cout<<"Too large"<<endl;

   }else{

       cout<<(6 * bag_ounces)<<"seconds"<<endl;

   }

}

Explanation:

The function is the block of the statement which performs the special task.

For checking the condition in the program, the if-else statement is used.

It can check the condition one or two but if we want to check the more than two different conditions then the continuous if-else statement is used.

syntax of continuous if else:

if(condition){

statement;

}else if(condition)

statement;

}else{

statement;

}

In the question, there are three conditions;

1. bag_ounces is less than 3

2. bag_ounces greater than 10

3. else part.

we put the condition in the above if-else statement and print the corresponding message.

8 0
3 years ago
Read 2 more answers
____ refers to typing your entire e-mail message or discussion group post using only capital letters.
Over [174]
The answer to this question is: Shouting
7 0
3 years ago
Other questions:
  • Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in
    15·1 answer
  • Suppose that some company has just sent your company a huge list of customers. You respond to that company with a strongly worde
    15·1 answer
  • Roblox published a series of videos to help their audience use their creation engine, what are they called?​
    9·2 answers
  • Most printers are plug and play compatible and must be manually configured when they are plugged into the system.
    14·2 answers
  • Computer design replaced ______________
    6·1 answer
  • Anybody know any educational game sites unblocced in school besides funbrain and pb skids
    12·1 answer
  • Đánh giá hoạt động thanh toán điện tử của sinh viên
    6·1 answer
  • Miley met up with a bunch of her college friends after several years. She told them that she works for the sound department of a
    5·1 answer
  • The largest group of Linux users is likely to be
    7·1 answer
  • 60 points!
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!