C help using txt file Implement the function vector getToke

C++ help :

using .txt file

Implement the function vector<TokenFreq> getTokenFreq( string inFile_name); This function reads the specified input file line by line, identifies all the unique tokens in the file and the frequency of each token. It stores all the identified (token, freq) pairs in a vector and returns this vector to the calling function. Don\'t forget to close the file before exiting the function. In this homework, these tokens are case insensitive. For example, \"Hello\" and \"hello\" are considered to be the same token.  (20 points)

Implement the selection sort algorithm to sort a vector<TokenFreq> in ascending order of token frequency. The pseudo code of the selection algorithm can be found at http://www.algolist.net/Algorithms/Sorting/Selection_sort You can also watch an animation of the sorting process at http://visualgo.net/sorting -->under \"select\". This function has the following prototype:

void selectionSort( vector<TokenFreq> & tokFreqVector ); This function receives a vector of TokenFreq objects by reference and applies the selections sort algorithm to sort this vector in increasing order of token frequencies.  (20 points)

Implement the insertion sort algorithm to sort a vector<TokenFreq> in descending order of token frequency. The pseudo code of the selection algorithm can be found at http://www.algolist.net/Algorithms/Sorting/Insertion_sort Use the same link above to watch an animation of this algorithm. This function has the following prototype:

void insertionSort( vector<TokenFreq> & tokFreqVector );  (20 points)

Implement the void writeToFile( vector<TokenFreq> &tokFreqV, string outFileName); function. This function receives a vector of TokenFreq objects and writes each token and its frequency on a separate line in the specified output file. (10 points)

Implement the int main() function to contain the following features: (1) asks the enduser of your program to specify the name of the input file, (2) ) call the getTokenFreq() to identify each unique token and its frequency, (3) call your selection sort and insertion sort functions to sort the vector of TokenFreq objects assembled in (2); and (4) call the WriteToFile() function to print out the sorted vectors in two separate files, one in ascending order and the other in descending order. (15 points)     

Solution

#include #include using namespace std; int main() { char s1[4]=\"one\"; //remember there will be one space for null terminator char s2[]=\"two\"; char s3[4]; char *s4; //s4 will point to the beginning of the array of chars char s5[6]; //Assigning characters to s3 s3[0]=\'b\'; s3[1]=\'a\'; s3[2]=\'t\'; s3[3]=\'\\0\'; //Need to allocate space otherwise get core dump when do strcpy. Two ways: //s4=new char[6]; //specify size directly s4=new char[strlen(\"hello\") + 1]; //use strlen to determine size //Copy the strings strncpy(s4,\"hello\",6); // specify the size of the string + 1 for null //s5=\"bye\"; // 21: error: ISO C++ forbids assignment of arrays. Instead: strncpy(s5, \"bye\", (strlen(\"bye\") + 1)); cout << s1 << endl; cout << s2 << endl; cout << s3 << endl; cout << s4 << endl; cout << s5 << endl; //clean up space allocated for s4 delete [] s4; return 0; }
C++ help : using .txt file Implement the function vector<TokenFreq> getTokenFreq( string inFile_name); This function reads the specified input file line b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site