Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads in a text file one word at a time. Store a word into

ID: 3697702 • Letter: W

Question

Write a program that reads in a text file one word at a time. Store a word into a dynamically created array when it is first encountered. Create a parallel integer array to hold a count of the number of times that each particular word appears in the text file. If the word appears in the text file multiple times, do not add it into your dynamic array, but make sure to increment the corresponding word frequency counter in the parallel integer array. Remove any trailing punctuation from all words before doing any comparisons. Create and use the following text file containing a quote from Bill Cosby to test your program. I don't know the key to success, but the key to failure is trying to please everybody. At the end of your program, generate a report that prints the contents of your two arrays in a format similar to the following: Word Frequency Analysis

Explanation / Answer

#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

int main()
{
    int size=0,count[100];
    string word[100];
    /*
      ofstream ofile;
    ofile.open("input.txt");
    ofile<<"I don't know the key to success but the key to failure is trying to please everybody";
    ofile.close();
    */
    ifstream ifile;
    ifile.open("input.txt");
    if (ifile.is_open())
    {
        char output[100];
        while (!ifile.eof())
        {
            ifile >> output;
            bool flag=true;
            int index=-1;
            for(int i=0;i<size;i++)
            {
                if(word[i]==output)
                {
                    flag=false;
                    index=i;
                }
                if(!flag)
                break;
            }
            if(flag==false)
            {
                count[index]++;
            }
            else
            {
                word[size]=output;
                count[size]=1;
                size++;
            }
            word[size]=output;
            }
    }
    ifile.close();
    cout<<" *******Word Frequency Analysis****"<<endl;
    cout<<"Word Frequency"<<endl;
    for(int i=0;i<size;i++)
    {
        cout<<word[i]<<" "<<count[i]<<endl;
    }
    cout<<endl;
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote