Question: This is my code in C++, my code is working pretty good but there are some stuff needs ti be changed I included theb below

This is my code in C++, my code is working pretty good but there are some stuff needs ti be changed I included theb below the my code:

include

#include

#include

#include

#include

using namespace std;

//Structure

struct TokenFreq

{

//Structure variables

string token;

int freq=1;

};

//Method matrixInit()

void matrixInit(vector > &matrix, int numRows, int numCols)

{

//Declare the needed variables

int index1, index2;

//Resize

matrix.resize(numRows, vector(numCols));

//Loop

for(index1 = 0; index1 < numRows; index1++)

{

//Loop

for(index2 = 0; index2 < numCols; index2++)

//Update

matrix[index1][index2] = index1 * index2;

}

}

//Method getTokenFreqVec()

void getTokenFreqVec(const string &istr, vector &tfVec)

{

//Declare the needed variables

string value;

int index, marker;

TokenFreq tf;

istringstream isStream(istr);

//Loop

while(getline(isStream, value, ' '))

{

//Function call

transform(value.begin(), value.end(), value.begin(), ::tolower);

//Initialize

marker = 1;

//Loop

for(index = 0; index < tfVec.size(); index++)

{

//Check condition

if(tfVec[index].token == value)

{

//Update

tfVec[index].freq += 1;

marker = 0;

}

}

//Check condition

if(marker)

{

//Update

tf.token = value;

//Function call

tfVec.push_back(tf);

}

}

}

//Method selectionSort()

void selectionSort(vector &tokFreqVector)

{

//Declare the needed variables

int index1, index2, minimum;

TokenFreq tf;

//Loop

for(index1 = 0; index1 < tokFreqVector.size() - 1; index1++)

{

//Initialize

minimum = index1;

for(index2 = index1 + 1; index2 < tokFreqVector.size(); index2++)

{

//Check condition

if(tokFreqVector[index2].freq < tokFreqVector[minimum].freq)

{

//Update

tf = tokFreqVector[minimum];

tokFreqVector[minimum] = tokFreqVector[index2];

tokFreqVector[index2] = tf;

}

}

}

}

//Method insertionSort()

void insertionSort(vector &tokFreqVector)

{

//Declare the needed variables

int index1, index2;

TokenFreq tf;

//Loop

for(index1 = 1; index1 < tokFreqVector.size(); index1++)

{

//Initialize

tf = tokFreqVector[index1];

//Loop

for(index2 = index1 - 1; index2 >= 0 && tokFreqVector[index2].freq < tf.freq; index2--)

//Update

tokFreqVector[index2 + 1] = tokFreqVector[index2];

tokFreqVector[index2 + 1] = tf;

}

}

//Driver

int main()

{

//Declare and initialize

string istr = "And no, I'm not a walking C++ dictionary. I do not keep every technical detail in my head at all times. If I did that, I would be a much poorer programmer. I do keep the main points straight in my head most of the time, and I do know where to find the details when I need them. by Bjarne Stroustrup";

vector > matrix;

vector tfVec;

int index1, index2;

//Initialize matrix

matrixInit(matrix, 3, 4);

//Display

cout<

//Loop

for(index1 = 0; index1 < 3; index1++)

{

//Loop

for(index2 = 0; index2 < 4; index2++)

//Display

cout<

}

//Function call

getTokenFreqVec(istr, tfVec);

//Display

cout<

cout<<"Size: "<

//Loop

for(index1 = 0; index1 < tfVec.size(); index1++)

//Loop

cout<

//Function call

selectionSort(tfVec);

//Display

cout<

//Loop

for(index1 = 0; index1 < tfVec.size(); index1++)

//Display

cout<

//Function call

insertionSort(tfVec);

//Display

cout<

//Loop

for(index1 = 0; index1 < tfVec.size(); index1++)

//Display

cout<

//Pause

cin.get();cin.get();

//Return

return 0;

}

Here are the Hints, I don't know what to change in my code:

3: Unit testkeyboard_arrow_up

0 / 5

Testing the getTokenFreqVec( const string& istr, vector & tfVec) function: can it handle a string of zero tokens?

Test feedback

The input string contains only white spaces. The correct number of tokens identified should be: 0; but your function identifies:1

4: Unit testkeyboard_arrow_up

0 / 7

Testing the getTokenFreqVec( const string& istr, vector & tfVec) function: can it handle a string of some nice and funny quotes on C++?

Test feedback

The input string is:Writing in C or C++ is like running a chain saw with all the safety guards removed. In C++, reinvention is its own reward. The correct number of tokens identified should be: 22; but your function identifies:23 For your information, here's the content of your vector: tfVec[0].token=writing tfVec[0].freq=1 tfVec[1].token= tfVec[1].freq=10 tfVec[2].token=in tfVec[2].freq=2 tfVec[3].token=c tfVec[3].freq=1 tfVec[4].token=or tfVec[4].freq=1 tfVec[5].token=c++ tfVec[5].freq=1 tfVec[6].token=is tfVec[6].freq=2 tfVec[7].token=like tfVec[7].freq=1 tfVec[8].token=running tfVec[8].freq=1 tfVec[9].token=a tfVec[9].freq=1 tfVec[10].token=chain tfVec[10].freq=1 tfVec[11].token=saw tfVec[11].freq=1 tfVec[12].token=with tfVec[12].freq=1 tfVec[13].token=all tfVec[13].freq=1 tfVec[14].token=the tfVec[14].freq=1 tfVec[15].token=safety tfVec[15].freq=1 tfVec[16].token=guards tfVec[16].freq=1 tfVec[17].token=removed. tfVec[17].freq=1 tfVec[18].token=c++, tfVec[18].freq=1 tfVec[19].token=reinvention tfVec[19].freq=1 tfVec[20].token=its tfVec[20].freq=1 tfVec[21].token=own tfVec[21].freq=1 tfVec[22].token=reward. tfVec[22].freq=1

5: Unit testkeyboard_arrow_up

0 / 9

Testing the getTokenFreqVec( const string& istr, vector & tfVec) function: can it handle the example input in the problem description?

Test feedback

The input string is:And no, I'm not a walking C++ dictionary. I do not keep every technical detail in my head at all times. If I did that, I would be a much poorer programmer. I do keep the main points straight in my head most of the time, and I do know where to find the details when I need them. by Bjarne Stroustrup The correct number of tokens identified should be: 46; but your function identifies:47

6: Unit testkeyboard_arrow_up

0 / 9

Testing the getTokenFreqVec( const string& istr, vector & tfVec) function: can it handle a much longer string?

Test feedback

The input string is:No one wants to die. Even people who want to go to heaven dont want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Lifes change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true. Your time is limited, so dont waste it living someone elses life. Dont be trapped by dogma which is living with the results of other peoples thinking. Dont let the noise of others opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary. When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960s, before personal computers and desktop publishing, so it was all made with typewriters, scissors and Polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: It was idealistic, and overflowing with neat tools and great notions.Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: Stay Hungry. Stay Foolish. It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.Stay Hungry. Stay Foolish. The correct number of tokens identified should be: 226; but your function identifies:227

7: Unit testkeyboard_arrow_up

0 / 5

Testing 1. void selectionSort( vector & tfVec ) in ascending order of freq.

Test feedback

The input string is:Writing in C or C++ is like running a chain saw with all the safety guards removed. In C++, reinvention is its own reward. The correct number of tokens identified should be: 22; but your function identifies:23

8: Unit testkeyboard_arrow_up

0 / 5

Testing 2. void selectionSort( vector & tfVec ) in ascending order of freq.

Test feedback

The input string is:No one wants to die. Even people who want to go to heaven dont want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Lifes change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true. Your time is limited, so dont waste it living someone elses life. Dont be trapped by dogma which is living with the results of other peoples thinking. Dont let the noise of others opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary. When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960s, before personal computers and desktop publishing, so it was all made with typewriters, scissors and Polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: It was idealistic, and overflowing with neat tools and great notions.Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: Stay Hungry. Stay Foolish. It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.Stay Hungry. Stay Foolish. The correct number of tokens identified should be: 226; but your function identifies:227

9: Unit testkeyboard_arrow_up

0 / 5

Test 1. void insertionSort( vector & tfVec ) in descending order of freq.

Test feedback

The input string is:Writing in C or C++ is like running a chain saw with all the safety guards removed. In C++, reinvention is its own reward. The correct number of tokens identified should be: 22; but your function identifies:23

10: Unit testkeyboard_arrow_up

0 / 5

Test 2. void insertionSort( vector & tfVec ) in descending order of freq.

Test feedback

The input string is:No one wants to die. Even people who want to go to heaven dont want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Lifes change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true. Your time is limited, so dont waste it living someone elses life. Dont be trapped by dogma which is living with the results of other peoples thinking. Dont let the noise of others opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary. When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960s, before personal computers and desktop publishing, so it was all made with typewriters, scissors and Polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: It was idealistic, and overflowing with neat tools and great notions.Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: Stay Hungry. Stay Foolish. It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.Stay Hungry. Stay Foolish. The correct number of tokens identified should be: 226; but your function identifies:227

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!