Question

C++ Program Word frequency analysis. [32] Write a program which can accept via stdin any number...

C++ Program

Word frequency analysis.

[32] Write a program which can accept via stdin any number of words until the user types quit. Load the words into an array (use realloc to control the size). Then output the words in alphabetic order and give the number of times the word was used. Call this frequency.cpp.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: #include <iostream> #include <stdio.h> using namespace std; void main() char str[20] [20], t [20]; int ib, j; int tmpcout<< Words in alphabetical order n; for (i 0 kcount1 i++) cout<< strli] <<n; cout << the total words given is: << cou

copyable code:

#include<iostream>
#include<stdio.h>

using namespace std;

void main()
{

   char str[20][20], t[20];

   int i = 0, j;
   int tmp = 0;
   int count = 0;

   while (tmp == 0)
   {
       cout << "Enter the words : ";
       cin >> str[i];
       count++;

       if (strcmp(str[i], "quit") == 0)
       {
           tmp = 1;
       }
       i++;
   }

   for (i = 1; i < count - 1; i++)
   {
       for (j = 1; j < count - 1; j++)
       {
           if (strcmp(str[j - 1], str[j])>0)
           {
               strcpy_s(t, str[j - 1]);
               strcpy_s(str[j - 1], str[j]);
               strcpy_s(str[j], t);
           }
       }
   }


   cout << "Words in alphabetical order : \n";
   for (i = 0; i<count - 1; i++)
   {
       cout << str[i] << "\n";
      
   }
   cout << "the total words given is: " << count - 1<<endl;
   system("pause");
}

Add a comment
Know the answer?
Add Answer to:
C++ Program Word frequency analysis. [32] Write a program which can accept via stdin any number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Programming Language on Linux - Word Frequency Program Please write a Program in C that...

    C Programming Language on Linux - Word Frequency Program Please write a Program in C that will accept a text file name as a command-line argument via a main program that will do the following: First, read the file (first pass) and create a linked list of words (in their order of occurrence), with the frequency of each word set to 0. Then, read the file (second pass) and for each word identified, search the linked list, and when found,...

  • in C language Write a program to find the element of an array, which occurs maximum...

    in C language Write a program to find the element of an array, which occurs maximum number of times and its count. The program should accept the array elements as input from the user and print out the most occurring element along with its count. Hint: array size is 5. For example: Enter array elements (array size 5): 22321 Output: Max occurring element: 2. count: 3

  • write a c++ program that prompts a user for a number then attempts to allocate an...

    write a c++ program that prompts a user for a number then attempts to allocate an array of as many integers as the user enters. In other words, the program might prompt the user with a line like: “How many integers would you like to allocate?” It should then allocate as many integers as the user enters. The program should then wait for the user to press enter before deleting the allocated array and quitting. We will use this time...

  • Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit...

    Write a C++ program that prompts the user with the following menu options: Erase-ArrayContent Count-Words Quit 1. For Erase-ArrayContent option, write complete code for the C++ function Erase described below. The prototype for Erase function is as follow: void Erase( int a[ ], int * N, int * Search-Element) The function Erase should remove all occurrences of Search-Element from the array al). Note that array a[ ] is loaded with integer numbers entered by the user through the keyboard. N...

  • Pythong Program 4 should first tell users that this is a word analysis software. For any...

    Pythong Program 4 should first tell users that this is a word analysis software. For any user-given text file, the program will read, analyze, and write each word with the line numbers where the word is found in an output file. A word may appear in multiple lines. A word shows more than once at a line, the line number will be only recorded one time. Ask a user to enter the name of a text file. Using try/except for...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • C program: Write a program that assigns and counts the number of each alphabetic character in...

    C program: Write a program that assigns and counts the number of each alphabetic character in the Declaration of Independence and sorts the counts from the most used to the least used character. Consider upper and lower case letters the same. The frequency of each character should be accumulated in an array. USE POINTERS to increment counts for each letter, sort your array, and display the results. Output should consist of two columns: (1) each letter 'a'-'z' and (2) the...

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

  • In C++ ab 8 DESCRIPTION: Complete all four problems. 1. Write a program that will accept...

    In C++ ab 8 DESCRIPTION: Complete all four problems. 1. Write a program that will accept two numbers from the user. The program should then evaluate the following equation, using the data input: 2-3X2 - 4Y?. Assume the second number input is Y. Now the program should test Z to see if Z is a negative number or a positive number (assume zero is included as a positive number). The program should output the values of X, Y, and Z...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT