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
ANYONE WANNA FRIEND ME ON DISCORD ゴRose joestarゴ#2088
Sergeeva-Olga [200]

JOJO fan!?!!?!??!?!?!!?!?

6 0
3 years ago
You are having a problem with your Windows computer that is isolated to a single graphics editing program that you use every day
Murljashka [212]

Answer:

I'm not a big tech head but I know that creating a restore point is highly recommended for changing anything that you aren't 100% sure about to your computer.

8 0
2 years ago
Graded Discussion: a. Create your own Unique Java Class Previous Next Provide Java code for a simple class of your choice.b. Be
alexdok [17]

Answer:

The java program for the given scenario is shown below.

import java.util.*;

import java.lang.*;

class YourClass

{

   // two private integer variables are declared

   private int num1, num2;

   

// constructor has the same name as the class itself

// constructor is similar to a method

// constructor has no return type

// constructor may or may not accept parameters

   YourClass()

   {

       num1 = 1;

       num2 = 2;

   }

       

   // first method

   void add()

   {

      System.out.println("Sum of the numbers " + num1 + " and " + num2 + " is " + (num1+num2) );

   }

   // second method

   void subtract()

   {

      System.out.println("Difference between numbers " + num1 + " and " + num2 + " is " + (num1-num2) );  

   }

   

}

public class Test

{

   public static void main(String args[]) {          

         // object of the class, YourClass, is created

// since constructor takes no parameters, no parameters are passed to the object  

         YourClass ob = new YourClass();

         

         // first method called

         ob.add();

         

         // second method called

         ob.subtract();

   }

}

OUTPUT

Sum of the numbers 1 and 2 is 3

Difference between numbers 1 and 2 is -1

Explanation:

1. The class, MyClass, contains two private fields, one constructor and two methods.

2. The fields are integer variables which are initialized in the constructor.

3. In the add() method, both integer variables are added and their sum displayed with System.println() method.

4. In the subtract() method, both integer variables are subtracted and their difference displayed with System.println() method.

5. In the other class, Test, inside the main() method, the object of the class, MyClass, is created.

6. Using the object, both the methods, add() and subtract(), are called inside main().

7. Java is a purely object-oriented language hence all the code is written inside classes.

8. Only the class which has main() method can be declared as public. Other classes are not declared public.

6 0
3 years ago
What is a digital projector? How is it different from computer screen?
LUCKY_DIMON [66]

Answer:

A digital projector, also called a digital projection display system, is a specialized computer display that projects an enlarged image on a movie screen. Such devices are commonly used in presentations.

its different because In a computer display , the screen is the physical surface on which visual information is presented. This surface is usually made of glass.

6 0
2 years ago
Read 2 more answers
The human resource department at Mega Corporation is overwhelmed with a constant flood of résumés submitted through its website
ad-work [718]

Answer: The answer to the question, How might an applicant-tracking system help the department; is pretty simple. What this question really asks for is to explain the innovation of the Applicant Tracking System (commonly abbreviated as ATS). So the foremost thing to do is to describe the Applicant tracking system. Application tracking tracking systems (ATS from hereon), are digital systems that are designed to make the recruitment process for employers way less tedious than it normally should be. Imagine you had to hire for a huge company like Microsoft that could receive tens of thousands of applications everyday for a specific role. It would be pretty tedious to determine the most qualified for the role if you had to go through all the applications yourself. Even if you had a team of people, it would still be stressful and error prone because, as humans we can make mistakes and slip in the wrong file for an interview or even misplace an application or mix something up somewhere. Now imagine if you didn't have to do all that because a computer program can do it with more precision and speed than you and your whole team are capable of. That would be splendid, right? Well, you don't have to. Aanya in the question above does not have to bother the department with the tedious work. The ATS will take care of a good chunk of the work. Here's how it works. The ATS is comprised of bots that are programmed to scan through applications and arrange them in order of qualification and matching of requirements. A bot is software application that's preset to run programs automatically, usually over the internet. So when people apply on Mega Corporation's platform, the applications are sent through to the scanning of the ATS. Now the requirements for the job role will be filled in by the department ATS so it knows what it's looking out for. For example, if one of the requirements for the job is a Master's degree in Psychology, applications without Master's degrees will be grouped separately from those that have. Same thing for other criteria like years of experience, Age, etcetera. The ATS receives all these applications and groups them such that, at the deadline of the application process, the ATS would have screened a good portion of the applicants and only the most qualified would be left for the next stage of screening. This is how the Applicant Tracking System would help the Human Resource department at Mega Corporation.

7 0
3 years ago
Other questions:
  • Functions that are built-in into PHP to perform some standard operations.
    15·1 answer
  • Computer programmers often use binary codes (strings of 1s and 0s) to write programs for computers. These codes are then changed
    6·1 answer
  • Andre is teaching a class without the software development cycle while teaching the analyst phase which task should Andre mentio
    8·1 answer
  • Which of the following statements about electronic cover letters is true?
    14·2 answers
  • Write a filter that reads in a sequence of integers and prints the integers, removing repeated values that appear consecutively.
    5·2 answers
  • Help easy 50 points!!!!<br> How do i make someone be the brianliest? No crown thing is appering!!!!
    10·2 answers
  • In regard to segmentation, all of the following are examples of a customer's behavior or relationship with a product EXCEPT: a)
    14·1 answer
  • What is the difference between RELIABLE and UNRELIABLE sources of<br> income?
    7·2 answers
  • Question 5 of 10
    10·1 answer
  • This is a graded practice activity. This is not an actual quiz.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!