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
The LList class is (mostly) the same one discussed in lecture, but you must write a sort() function that uses one of the three i
Vladimir79 [104]

Answer:

see explaination

Explanation:

#include <iostream>

#include <string>

using namespace std;

class LinkedList{

class Node{

public :

int data;

Node* next;

Node(int data){

this->data = data;

next = NULL;

}

};

public :

Node *head;

LinkedList(){

this->head = NULL;

}

void insert(int d){

Node* new_node = new Node(d);

new_node->next = head;

head = new_node;

}

// sort the list with selection sort algorithm.

// Pick the smallest element in the unsorted array and place in the first element in the unsorted.

void sort_list(){

if (head == NULL){

return;

}

Node* current = head;

while (current->next != NULL){

Node* min_node = current;

Node* traverse = current->next;

while(traverse != NULL){

if(traverse->data < min_node->data){

min_node = traverse;

}

traverse = traverse->next;

}

int temp = current->data;

current->data = min_node->data;

min_node->data = temp;

current = current->next;

}

}

void print_list(){

Node* current = head;

while(current !=NULL){

cout<<current->data<<" ";

current = current->next;

}

cout<<"\n";

}

};

int main(){

LinkedList ll;

for(int i=0;i<10;i++){

ll.insert(i);

}

ll.print_list();

cout<<"*******************************************\n";

ll.sort_list();

ll.print_list();

cout<<"*******************************************\n";

}

8 0
3 years ago
Write the contributions of dr herman hollerith​
Ad libitum [116K]

He invented the tabulating machine. In 1890 U.S

5 0
3 years ago
The default color scheme is called ____.
notsponge [240]
What program is this regarding?

If it's a Microsoft Office product, the default colour scheme is "office"
5 0
3 years ago
What is the differnce between ''P4 and 4P''
34kurt
The number and letter are switched. This question needs more context to get a accurate answer.
5 0
3 years ago
Read 2 more answers
The power of if worksheet
sergejj [24]
What are you talking about?
3 0
3 years ago
Other questions:
  • It is not recommended by the USA EPA, but adding refrigerant to a leaking A/C system is
    13·1 answer
  • Software that controls a computer. an os controls how system resources are used and provides a user interface, a way of managing
    13·1 answer
  • What technology did one of the student's have to learn to use in order to help him with his homework in the film, "Disconnected:
    11·2 answers
  • What is the best way to protect against the loss of important files
    15·1 answer
  • Use the drop-down menus to answer the questions.
    6·1 answer
  • A computer is made up of hardware and software ​
    5·1 answer
  • Use the drop-down menus to complete each statement. Two main versions of Outlook are the desktop app and the app. The has limite
    15·2 answers
  • If a movie, song, or book is offered for free, is it malware?
    15·1 answer
  • Yeoo check dis out!!!!!! wait my full vid dont show hol on
    7·2 answers
  • Algorithm to eat orange<br><br>​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!