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
List one unprofessional AND one professional example of internet/social media
Leni [432]

Professional: Using social media to advertise a company you created

Unprofessional: Using social media to watch cat videos

4 0
2 years ago
colby lives a very career-driven lifestyle. he works long hours and enjoys making a lot of money by working overtime. after he a
just olya [345]

The role of being a father will decrease Colby’s income and decrease the career-driven nature of his lifestyle.

8 0
3 years ago
Read 2 more answers
How do i use a computer (i'm 99999 years old)
AlekseyPX

Answer:

grandma?

Explanation:

is it you?

6 0
3 years ago
Read 2 more answers
Mark is learning to make logos. Once he finishes learning, he plans to freelance. Which software is most preferred to create art
MAVERICK [17]
Abode Illustrator helps to design logos in professional way
8 0
2 years ago
Calculator and clocks are examples of -------------- in windows 7
Luden [163]
Utilities (not sure)
7 0
2 years ago
Other questions:
  • Assume arr2 is declared as a two-dimensional array of integers. Which of the following segments of code successfully calculates
    6·1 answer
  • Linguist study
    9·1 answer
  • The factorial of an integer N is the product of the integers between 1 and N, inclusive. Write a while loop that computes the fa
    10·1 answer
  • Assembly (Procedure and Conditional Processing). For the following program, what are outputs for register EAX, EBX, ECX, and EDX
    11·1 answer
  • If you want to change the smart quote settings, what steps should you follow to find them?
    5·1 answer
  • You are in the windows power shell window and decide to encrypt folder which of the following command do you use
    7·1 answer
  • An important goal of biosecurity training is to: Prevent laboratory accidents that could expose personnel to hazardous agents. P
    13·1 answer
  • What is the value of the variable named result after the following code executes?
    10·1 answer
  • Which three statements are true of lossless compression?
    6·1 answer
  • Which very high-speed fiber network was already in place and being used for wide area networking (wan) transmissions, before the
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!