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]
4 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]4 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
Click this link to view O*NET’s Work Styles section for Petroleum Engineers. Note that common work styles are listed toward the
inysia [295]

Answer:

2 (cooperation )

3 (integrity)

5 (analytical thinking)

6 (dependability)

Explanation:

Good luck! Hope this helps.

4 0
3 years ago
Read 2 more answers
The command-line interface tells a user that it's ready to receive commands by displaying a specific set of characters called a(
Brrunno [24]

Answer:

B) prompt

Explanation:

Prompt tells a user that it's ready to receive commands by displaying a specific set of characters.

For example in <em>windows</em> it can be:

C:\Temp>, The prompt states that user is currently in <em>C </em>drive <em>Temp</em> directory.

in <em>Linux </em>based operating systems it can be:

[email protected]:~/Documents$

where it is in the format [email protected]:~directory$

5 0
3 years ago
What is the famous saying among computer programmers?
USPshnik [31]
The famous saying is garbage in , garbage out .
3 0
4 years ago
What is computer hardware?
faltersainse [42]
Computer hard ware is any thing physical that you can touch such as the mouse , keyboard hard drive cpu, moniter or if your using a laptop it will be the entire computer its self.
5 0
4 years ago
Read 2 more answers
What does IP stand for (as in IP address)? Also, what is overtype mode?
tino4ka555 [31]
An  IP address is mostly for your WIFI . Internet Protocol . 

Overtype Mode is where you are making changes to text (putting in new characters) 
4 0
3 years ago
Other questions:
  • You have been tasked with finding the routers that have been installed between two networks. what utility would you use to provi
    5·1 answer
  • The different concepts in the architecture operating model are aligned with how the business chooses to integrate and standardiz
    10·2 answers
  • TCP will guarantee that your packets will arrive at the destination, as long as the connection is still established. True False
    11·1 answer
  • What field in an IPv4 packet is altered to prioritize video streaming traffic over web surfing traffic?
    7·1 answer
  • Assume that the following table is created and stored in your database:
    5·1 answer
  • A restaurant recorded the ages of customers on two separate days. You are going to write a program to find the minimum age of a
    5·2 answers
  • This software application can be used to organize, analyze, and illustrate data?
    12·2 answers
  • def list_length(shrinking_list): ''' A recursive way to count the number of items in a list. ''' if shrinking_list
    10·1 answer
  • How do i delete peoples comments
    14·2 answers
  • Given a string on one line and an integer index on a second line, output the character of the string at that index.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!