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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
enum eType {Sub, Trans, Del, Insert, Err, Corr};
void get_cWord(ifstream& fin, string cWord)
{
fin >> cWord;
}
void get_bWords(ifstream& fin, string bWords)
{
fin >> bWords;
}
void display(eType e)
{
switch(e)
{
case Sub: cout << "User word is " << bWords << endl
<< "The user word has one character substituted" << endl << endl; break;
case Trans: cout << "User word is " << bWords << endl
<< "The user word contains a transpostion" << endl << endl; break;
case Del: cout << "User word is " << bWords << endl
<< "The user word has one character delected" << endl <<; break;
case Insert: cout << "User word is " << bWords << endl
<< "The user word has one character inserted" << endl << endl; break;
case Err: cout << "The user word is to bad to be a misspelling" << endl << endl; break;
case Corr: cout << "The user word is Correct" << endl << endl; break;
}
}
void findeType(eType e)
{
int a = 0, x = 0, h = 0;
int counter1 = 0, counter2 = 0, counter3 = 0;
if(cWord == bWord)
{
a = cWord.size;
for(int b = 0; b <= a; b++)
{
if(cWord.at(b) = bWords.at(b))
{
}else if(cWord.at(b) != bWords.at(b))
{
counter1++;
}
}
if(counter1 = 0)
{
e = Corr;
}else if(counter1 = 1)
{
e = Sub;
}else if(counter1 = 2)
{
e = Trans;
}
}else if(cWord == bWord+1)
{
x = cWord.size + 1;
for(int y = 0; y <= x; y++)
{
if(cWord.at(y) = bWords.at(y))
{
}else if(cWord.at(y) != bWords.at(y))
{
counter2++;
}
}
if(counter2 = 1)
{
e = Del;
}else if(counter2 <= 2)
{
e = Err;
}
}else if(cWord == bWord-1)
{
h = cWord.size;
for(int i = 0; i <= h; i++)
{
if(cWord.at(i) = bWords.at(i))
{
}else if(cWord.at(i) != bWords.at(i))
{
counter3++;
}
}
if(counter3 = 1)
{
e = Insert;
}else if(counter3 <= 2)
{
e = Err;
}
}
}
void main()
{
ifstream fin;
string cWord = "", bWords = "";
eType e = Corr;
while(cWord != "/n")
{
get_cWord(fin, cWord);
cout << "The word being checked is " << cWord << "." << endl << endl;
while(bWords != "/n")
{
get_bWords(fin, bWords);
findeType(e);
display(e);
}
}
system("pause");
}
|