Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Token errors in C++: 2-dimensional arrays, a string tokenizer, insertion sort, a

ID: 3587207 • Letter: T

Question

Token errors in C++: 2-dimensional arrays, a string tokenizer, insertion sort, and selection sort

Hello, I have a code written for this assignment. It runs fine on my IDE but I recieve token errors when I submit it on my textbook software. I'm really not sure what to do. Any help would be appreciated. Thank you.

Code:

Errors:

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

The correct number of tokens identified should be: 0; but your function identifies:1

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

The correct number of tokens identified should be: 22; but your function identifies:23

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

The correct number of tokens identified should be: 46; but your function identifies:47

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

The correct number of tokens identified should be: 226; but your function identifies:227

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

The correct number of tokens identified should be: 22; but your function identifies:23

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

The correct number of tokens identified should be: 226; but your function identifies:227

Edit:

The textbook software is zyBooks.

Explanation / Answer

After analyzing your code and the errors, I think the mistake lies in the frequency of the tokens. Its always showing 1 extra in the answer and this is because at the start in

here, you initialised freq=1 (instead of 0) and everytime in the function

getTokenFreqVec(), the statement

tfVec[i].freq += 1;

you increase freq count, so it increases to 2 (instead of 1) when it finds first token.

Just do

int freq=0;

in struct TokenFreq.