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
#include
using namespace std;
struct TokenFreq {
string token;
int freq = 1;
};
void matrixInit( vector< vector
int i;
int j;
matrix.resize(numRows, vector
for(i = 0; i< numRows; i++ ){
for(j = 0; j < numCols; j++ )
matrix[i][j] = i*j;
}
}
void getTokenFreqVec(const string &istr, vector
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 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 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 vector 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
Get step-by-step solutions from verified subject matter experts
