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
How many binary digits are in 10^100.
Basile [38]

Answer:

333 binary digits.

Explanation:

8 0
2 years ago
Sean has trouble remembering all the geometry formulas. What can he do to make sure he doesn't forget these formulas during his
son4ous [18]
3 i think but im not sure
7 0
3 years ago
Read 2 more answers
After logging into your Blackboard account, you will never be required to enter a separate password provided by your instructor
FinnZ [79.3K]

Answer:

False.

Explanation:

If the institute in which you are enrolled have blackboard account for you then you are given a login ID and password which can be used to login onto the website.

But after logging in you are required to enter a separate password given by the instructor to begin the test.So we conclude that the answer to this question is False.

5 0
3 years ago
Draw a flowchart or write pseudocode to represent the logic of a program that allows the use to enter values for the width and l
DIA [1.3K]
In psuedocode it would be:

length = input()
width = input()

area = length * width

print(area + " sq ft");

3 0
3 years ago
Select the correct answer from each drop-down menu.
Gnesinka [82]

Answer:

Explanation:

creating .

6 0
3 years ago
Other questions:
  • Define the missing function. licenseNum is created as: (100000 * customID) + licenseYear. Sample output:
    10·2 answers
  • Which of the following is an occupation management group? Select the choice that best answers the question.
    15·1 answer
  • Getting access to web browsing software to install it on a computer or to update your existing software is called _________ .
    9·2 answers
  • Write a single statement that assigns avg_sales with the average of num_sales1, num_sales2, and num_sales3.
    15·1 answer
  • Hello people, I was wandering if I could get some people to complete this questionnaire for my business course. It would be very
    5·1 answer
  • Consider the following code segment.
    12·1 answer
  • ¿Cuál es la diferencia entre una plataforma educativa y una tutoría?
    7·1 answer
  • Multiple choice:
    12·2 answers
  • To add a hyperlink to your presentation, select the text, choose Hyperlink from the Insert menu, and then
    15·1 answer
  • Class Main {
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!