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
Which of the following characters is not allowed for java variable names
Rainbow [258]
The variables must begin with a letter of the alphabet, a dollar sign or a underscore. After the first character you may add numbers as well. All special characters besides the dollar sign and underscore and not allowed in variables.
8 0
3 years ago
Explain the steps users can take to maintain an operating system
Mars2501 [29]

First is it to always clean out all the junk that is left behind by the operating system and the browsers. You can easily do this using the Disk Cleanup utility included on the windows systems. You can clean up the registry. However, you should be very careful with the registry. Any wrong move might mess up everything


Search and destroy viruses and malware on your PC by installing an anti-virus security program and setting up an automated maintenance schedule.


Defragment main and partitioned drives to keep your computer running smoothly.


Uninstall software programs and personal files like pictures, movies and music that are no longer in use to free up more space. The more the space, the faster the PC will go. You can also run the msconfig command in the RUN command prompt to uncheck start up programs that you do not use

4 0
3 years ago
NWhen you measure a person’s weight, you are measuring the
MAVERICK [17]

Answer:

gravitational force acting on that person.

Explanation:

5 0
3 years ago
Read 2 more answers
Which of the following is NOT a possible combination of values of the variables in this program when it finishes running?
Nady [450]

Answer:

Definitely D

Explanation:

When you flip a coin it’s a 50/50 chance. Meaning it’s equal.

7 0
3 years ago
Read 2 more answers
Use the ________ method to write text to a web page.
Nastasia [14]
Document.write()

I'm not sure that this is a method, but I think this is right. 
3 0
3 years ago
Other questions:
  • Which method tries all possible passwords until a match is found?
    13·1 answer
  • Write a function M-file that takes as input two matrices A and B, and as output produces
    8·1 answer
  • Search engine ranking evaluates the variables that search engines use to determine where a URL appears on the list of search res
    7·1 answer
  • ___MSDS provides information on how to handle, store, discard and care for potentially hazardous chemicals. true or false?​
    5·1 answer
  • Which part of the operating system enables you to interact with the device? Question 9 options: The graphical user interface The
    8·1 answer
  • Write an algorithm to solve general formula? ​
    10·1 answer
  • Differentiate between perfect and imperfect market​
    14·1 answer
  • How to transfer bookmarks to new computer
    15·1 answer
  • PLEASE HELP! I accidently looked up a link, and now this same link keeps popping up everywhere, how do I stop this!?!? please he
    13·2 answers
  • Resource _____ let you view, manage, and automate tasks on multiple aws resources at a time.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!