Question: Can someone help me fix this code so it would count the white between the words ? Thanks #include #include #include #include //to use istringstream

Can someone help me fix this code so it would count the white between the words ? Thanks

#include

#include

#include

#include //to use istringstream

#include

using namespace std;

struct TokenFreq {

string token;

int freq = 1;

};

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

int i;

int j;

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

for(i = 0; i< numRows; i++ ){

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

matrix[i][j] = i*j;

}

}

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

string token;

int i;

int flag;

TokenFreq t;

istringstream isStream(istr);

while(getline(isStream, token,' ')){

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

flag =1;

for(i =0; i

if(tfVec[i].token == token){

tfVec[i].freq += 1;

flag =0;

}

}

if(flag){

t.token = token;

tfVec.push_back(t);

}

}

}

void selectionSort( vector &tokFreqVector ){

int i;

int j;

int minT;

TokenFreq token;

for(i =0; i

minT = i;

for (j =i + 1; j

if(tokFreqVector[j].freq < tokFreqVector[minT].freq){

token = tokFreqVector[minT];

tokFreqVector[minT]= tokFreqVector[j];

tokFreqVector[j] = token;

}

}

}

}

void insertionSort( vector &tokFreqVector ){

int i;

int j;

TokenFreq token;

for(i = 0; i

token = tokFreqVector[i];

for(j = i -1; j >= 0 && tokFreqVector[j].freq < token.freq; j++)

tokFreqVector[j+1] = tokFreqVector[j];

tokFreqVector[j+1] = token;

}

}

int main(){

string istr ="Writing in C or C++ is like running a chain saw with all the safety guards removed. In C++, reinvention is its own reward.";

vector tfVec;

vector > matrix;

int i;

int j;

matrixInit(matrix, 3,4);

cout <<" Size of matrix is: 3x4 ";

for(i = 0; i< 3; i++){

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

cout<<" matrix["<

}

getTokenFreqVec(istr, tfVec);

cout<<" Testing Tokenizer. Size = "<

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

cout<

selectionSort(tfVec);

cout<<" Testing selection sort. ";

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

cout<<" = (Token = "<

insertionSort(tfVec);

cout<<" Testing insertion sort. ";

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

cout<<" Token: "<

return 0;

}

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!