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
You put $500 in an interest bearing bank account that pays 2% per year but has a fee of $2 per month. Are you getting ahead?
MA_775_DIABLO [31]
The answer is b) No

2% of 500 is 10.
$10 interest per year.

There are 12 months in a year. $2 per month
2 * 12 = 24
$24 a year is the fee. 

So, if you have a $10 interest per year, but are paying $24 per year on a fee, you are not getting ahead. 


Hope this helps you! (:
-Hamilton1757
4 0
3 years ago
Read 2 more answers
Why do we need to connect computers"​
Gennadij [26K]

Answer:

batteries cant last connected to nothing forever probably

8 0
2 years ago
Draw a flowchart for an algorithm which calculates how much money a student will need per week to buy a meal and two drinks each
jasenka [17]

Flowcharts are used as a prototype of an actual program.

First, I will write out the algorithm; which will be used as an explanation of the flowchart (see attachment for flowchart)

The algorithm is as follows;

1. Start

2. Get input for cost of a meal and cost of a drink;

3. Calculate the total cost for a meal and two drinks

4. Multiply the total cost of a meal and two drinks by 7, to get the weekly cost

5. Display the weekly cost

6. Stop

At the end of the algorithm/flowchart, the weekly cost is calculated and printed.

See attachment for flowchart

Read more about algorithms and flowcharts at:

brainly.com/question/18088572

3 0
3 years ago
What aspect should you consider before adding pictures to a document? You should structure the first before you search for a rel
suter [353]

Answer:make sure it line up with tour essay

Explanation:

5 0
3 years ago
How many parts does status bar consist ?​
Maslowich

Answer:

here you go

Explanation:

256 parts

I hope it helped

8 0
2 years ago
Read 2 more answers
Other questions:
  • If you had a chance to see what your life would be like in 20 years
    8·1 answer
  • Which answer best describes an unsubsidized federal loan
    9·1 answer
  • Select all that apply. Given the following code fragment, which of the things shown below happen when the statement on line 8 ex
    13·1 answer
  • Power brakes:
    12·2 answers
  • When the function below is called with 1 dependent and $400 as grossPay, what value is returned?
    13·1 answer
  • What ways does e-governance empower citizens
    15·1 answer
  • Modern life is not possible if computer stops working? Give your opinion<br>​
    7·1 answer
  • Which method can be used for making a robot perform a different set of functions?
    13·1 answer
  • The entities on which data are collected are _____.
    10·2 answers
  • Which sql keyword is used to retrieve a minimum value from an attribute in a table
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!