Login
Order Now
Support
C++ Programming Assignment Help - Solution on Strings Class

C++ Programming Assignment Help - Solution on Strings Class

  • 22nd Dec, 2022
  • 16:13 PM

C++ Programming Assignment Help -  Solution on Strings Class

#include
#include
#include
#include
#include
using namespace std;


int main()
{
    int sizeOfVector;
    vector wordList;
    vector wordListCount;
    vector  stopWord{"a","an","as","be","buy","for","i","is","it","or"};
    fstream fp;
    string filename = "English.txt";
    string word;
    fp.open(filename.c_str());
    if (!fp)
        cout << "\nFile not found\n";
    while (fp >> word)
    {

        for (int i = 0, j = word.size(); i < j; i++)
        {
            if (ispunct(word[i]))
            {
                word.erase(i--,1);
                j = word.size();
            }

        }
        wordList.push_back(word);
    }
    for (auto i = stopWord.begin(); i != stopWord.end(); ++i)
    {
        for (auto j = wordList.begin(); j != wordList.end(); ++j)
        {
            string temp=*j;
            transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
            if (temp == *i)
            {
                wordList.erase(j);
                j--;

            }
        }
    }

    for (auto j = wordList.begin(); j != wordList.end(); ++j)
    {
        wordListCount.push_back(count(wordList.begin(), wordList.end(), *j));
    }


    sizeOfVector=wordList.size();

     for (int i = 0; i < sizeOfVector-1; i++)
     {
        for (int j = 0; j < sizeOfVector-i-1; j++)
        {

            if (wordListCount[j] < wordListCount[j+1])
            {
                int tempcount=wordListCount[j];
                wordListCount[j]=wordListCount[j+1];
                wordListCount[j+1]=tempcount;

                string tempWord=wordList[j];
                wordList[j]=wordList[j+1];
                wordList[j+1]=tempWord;
            }
         }
     }
     cout<<"\nThree most Frequent word \n";
     string printedWord[3]={"","",""};
     int index=0;
     for(int i=0;i      {
         int found=0;
         for(int j=0;j          {
             if(printedWord[j]==wordList[i])
             {
                 found=1;
             }
         }
         if(found==0)
         {
             cout<<"\nword      :  "<              cout<<"\nOccurence :  "<              cout<              printedWord[index]=wordList[i];
             index++;
         }
         if(index==3)
            break;

     }
     return 0;
}
 

Share this post

assignment helpassignment helperassignment expertsassignment writing services