1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
void testError(ifstream& fin, string correctWord, string userWord,spelling_error errorType, ofstream& fout)
{
int correct = 0;
int substitution =0;
int transposition =0;
int deletion = 0;
int insertion =0;
int error =0;
char ch;
fout << "*****Starting a new line*****" << endl;
fin >> correctWord;
fout << "The correct word is " << correctWord << endl << endl;
while(!fin.eof())
{
ch = ' ';
while(ch != '\n')
{
fin >> userWord;
fout << "The user word is " << userWord << endl;
if(correctWord.length() == userWord.length())
{
if(correctWord == userWord)
{
errorType = CORRECT;
printError(errorType,correct,substitution,transposition,deletion,insertion,error, fout);
}
else if (isSubstitution(correctWord, userWord))
{
errorType = SUBSTITUTION;
printError(errorType,correct,substitution,transposition,deletion,insertion,error, fout);
}
else if (isTransposition(correctWord, userWord))
{
errorType = TRANSPOSITION;
printError(errorType,correct,substitution,transposition,deletion,insertion,error, fout);
}
}
else if(correctWord.length() != userWord.length())
{
if (isDeletion(correctWord, userWord))
{
errorType = DELETION;
printError(errorType,correct,substitution,transposition,deletion,insertion,error, fout);
}
else if(isInsertion(correctWord, userWord))
{
errorType = INSERTION;
printError(errorType,correct,substitution,transposition,deletion,insertion,error, fout);
}
else
{
errorType = ERROR;
printError(errorType,correct,substitution,transposition,deletion,insertion,error, fout);
}
}
fin.get(ch);
}
fout << "*****Starting a new line*****" << endl;
fin >> correctWord;
fout << "The correct word is " << correctWord << endl << endl;
}
fout << "There were " << correct << " correct words." << endl;
fout << "There were " << substitution << " substitution errors." << endl;
fout << "There were " << transposition << " transposition errors." << endl;
fout << "There were " << deletion << " deletion errors." << endl;
fout << "There were " << insertion << " insertion errors." << endl;
fout << "There were " << error << " words with many mispellings." << endl;
}
|