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

I have a word frequency program that prints out all the words in the tree. I nee

ID: 3682440 • Letter: I

Question

I have a word frequency program that prints out all the words in the tree. I need to add functions to print only the first 100 words for output. Then, delete 15% of the most common words found in this text. Now compute their NEW relative values for the new set of words and print the list of words left in the data structure. (Again print out only the first 100 words.) I need help on how to do this. I am using c++ on a windows xp platform.

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cassert>

using namespace std;

ifstream infile;


class Cache
{
  
   public:
       Cache()
       {
           root = NULL;
       }
       void Examine(string w)
       {
           totalCounter = 0;
           Node *a;
           a = NULL;
           infile.open("The Bill of Rights.txt");
           assert(infile);
           infile >> w;
          
           while (infile)
           {
              
               insertN(a,wordcheck(w));
               totalCounter++;
               infile >> w;
           }
           printN();
       }

   private:
       typedef Cache Node;
       typedef string value_type;
       value_type v;
       Node *linky;
       Node *lChild;
       Node *rChild;
       Node *root;
       int counter;
       float totalCounter;
       typedef int size_type;

       Node *MyNewNode(value_type val)
       {
           Node *temp;
           temp = new Node();
           temp -> v = val;
           temp -> lChild = NULL;
           temp -> rChild = NULL;
           temp ->counter = 0;
           return temp;
       }
       void insertNode(Node **c, Node *d)
       {
           if ( *c == NULL)
           {
               *c = d;
               (*c) -> counter++;
           }
           else if(d->v < (*c)->v)
           {
               insertNode(&(*c)->lChild, d);
           }
           else if (d->v > (*c)->v)
           {
               insertNode(&(*c)->rChild,d);
           }
           else if (d->v == (*c)->v)
           {
               (*c)->counter++;
           }
       }
       void insertN(Node *d, string val)
       {
           d = MyNewNode(val);
           if ( root == NULL)
           {
               root = d;
           }
           else insertNode(&root,d);
       }
       void print(Node *c)
       {
           if (c->lChild)
           {
               print(c->lChild);
           }
           cout << fixed;
           cout << setw(20) << c->v << setw(6) << c->counter << setw(10) << setprecision(3) <<(c->counter/totalCounter)*100<< "%"<<endl;
           if (c->rChild)
           {
               print(c->rChild);
           }
       }
       void printN()
       {
           if (root)
           {
               print(root);
           }
       }
       value_type wordcheck(value_type val)
       {
           for(int i = 0; i < val.length(); i++)
           {
               if (val[i] == '.' || val[i] == '"' || val[i] == ','|| val[i] == ';')
               {
                   val.erase(i, 1);
               }
               else
               {
                   val[i] = tolower(val[i]);
               }
           }
           return val;
       }
       void lastdel()
       {
           Node *c;
           Node *p;
           c = root;
           while (c->linky != NULL)
           {
               p = c;
               c = c -> linky;
           }
           c -> linky = p ->linky;
           p->linky = NULL;

       }
       size_type list_length(Node *c)
       {
           Node *d;
           c = root;
           size_type answer;
           answer = 0;
           for (d = c; d!=NULL; d = d->linky)
               answer++;
           return answer;
       }
       bool search(Node *c, string tar)
       {
           c = root;
           Node *p;
           while ((c!=NULL) && (c->v != tar))
           {
               c = c-> linky;
           }
           return c;
       }
       friend istream& operator >> (istream& ins, Node *val)
       {
      
           ins >> val->v;
           val = val -> linky;
           return ins;
       }
};


int main()
{
   string words;
   Cache list;
   cout << setw(20) << "Word" << setw(6) << "Absolute" << setw(10) << setprecision(3) << "Relative "<<endl;
   list.Examine(words);

  

   system ("Pause");
}

Explanation / Answer

Yes, It is possible.

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