basically for this code i need a program that reads the text word by word ,all words occurring in the text are to be stored as a “Word Item”; a WordItem is a type of object that stores the word proper and its frequency in a given text, and all WordItems from a text are stored in a List so that at any time, the items are listed in alphabetical order of their word component. this is the code i need to complete
#include <iostream>
#include <fstream>
#include "WordItem.h"
#include "List.h"
using namespace std;
template void print_list (list);
template void print_lines (list);
void alpha_insert (string, list &);
string strip_punct (string);
int main ()
{
list wdList;
string next;
ifstream inp;
inp.open ("file.txt");
inp >> next;
next = strip_punct (next);
while (!inp.fail ()) {
alpha_insert (next, wdList); // DEFINE BELOW
inp >> next;
next = strip_punct (next); // DEFINE BELOW
}
inp.close ();
// Print out each word and its number of occurrence
// in "file.txt"; word:count pair per alpha_insert
// Iterate over the wdList and determine the word
// among all WordItems that has maximal count;
// : export this most frquent word and its count;
return 0;
}
template void print_list (list lst)
{
cout << endl;
typename list::iterator itr;
for (itr = lst.begin (); itr != lst.end (); ++itr)
cout << *itr << " ";
cout << endl;
}
template void print_lines (list lst)
{
cout << endl;
typename list::iterator itr;
for (itr = lst.begin (); itr != lst.end (); ++itr)
cout << *itr << " " << endl;
cout << endl;
}
string strip_punct (string x)
{
for (int i = x.size () - 1; i >= 0; i--) {
if (ispunct (x[i])) {
x.erase (i--, 1);
i++;
} else
return x;
}
return x;
}
void alpha_insert (string x, list & wdlst)
{
WordItem wordit;
if (wdlst.empty ()) {
wordit = WordItem (x);
wdlst.insert (wdlst.begin (), wordit);
return;
}
Find proper place and insert ... return;
}