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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
#include <fstream>
#include <cstring>
#include <iostream>
using namespace std;
struct DictionaryWords{
char words[25];
};
struct PassageWords{
char pWords[25];
};
void printMenu(){
cout <<" Spell Checker for the Different Languages" <<endl;
cout <<"--------------------------------------------"<<endl;
cout <<"1. Load Dictionary [English, French, Spanish]"<<endl;
cout <<"2. Load Passage"<<endl;
cout <<"3. Display Passage"<<endl;
cout <<"4. Spell Check Passage"<<endl;
cout <<"5. Exit"<<endl;
cout <<endl;
cout <<"Please enter your choice (1-5): ";
}
int loadEng(DictionaryWords dictionary[]){
ifstream in;
int i=0;
int wordCount=0;
char ch;
DictionaryWords d;
in.open("dictionary-en.txt");
if(!in.is_open()){
cout<<"Error opening file..exiting"<<endl;
return 0;
}
while(!in.eof()){
in>>dictionary[i].words;
i= i+1;
wordCount=wordCount+1;
}
wordCount=wordCount-1;
cout<<wordCount<<" words read successfully."<<endl;
cout<<endl;
in.close();
return wordCount;
}
int loadEs(DictionaryWords dictionary[]){
ifstream in;
int i=0;
int wordCount=0;
char ch;
DictionaryWords d;
in.open("dictionary-es.txt");
if(!in.is_open()){
cout<<"Error opening file..exiting"<<endl;
return 0;
}
while(!in.eof()){
in>>dictionary[i].words;
i= i+1;
wordCount=wordCount+1;
}
wordCount=wordCount-1;
cout<<wordCount<<" words read successfully."<<endl;
cout<<endl;
in.close();
return wordCount;
}
int loadFr(DictionaryWords dictionary[]){
ifstream in;
int i=0;
int wordCount=0;
char ch;
DictionaryWords d;
in.open("dictionary-fr.txt");
if(!in.is_open()){
cout<<"Error opening file..exiting"<<endl;
return 0;
}
while(!in.eof()){
in>>dictionary[i].words;
i= i+1;
wordCount=wordCount+1;
}
wordCount=wordCount-1;
cout<<wordCount<<" words read successfully."<<endl;
cout<<endl;
in.close();
return wordCount;
}
int loadPassage(char passage[], char file[]){
ifstream in;
int i;
int numCount;
numCount=0;
i=0;
in.open(file); //or filename.txt
in>>noskipws;
while(!in.eof()){
in>>passage[i];
i=i+1;
numCount=numCount+1;
}
passage[i]='\0';
cout<<"Passage loaded successfully"<<endl;
cout<<endl;
return numCount;
}
void readPassage(char passage[]){
cout<<passage;
cout<<"\n\n"<<endl;
cout<<" ****End of passage****";
cout<<"\n\n";
}
int countPassage(PassageWords pass[], char file[]){
ifstream in;
int i=0;
int passCount=0;
char ch;
PassageWords p;
in.open(file);
if(!in.is_open()){
cout<<"Error opening file..exiting"<<endl;
return 0;
}
while(!in.eof()){
in>>pass[i].pWords;
i= i+1;
passCount=passCount+1;
}
passCount=passCount-1;
cout<<"(a)Total number of words in passage: "<<passCount<<endl;
cout<<endl;
in.close();
return passCount;
}
void compare(DictionaryWords dictionary[], PassageWords pass[], int numWords, int wordCount){
int i=0;
if (dictionary[i].words==pass[i].pWords){
i=i+1;
}
cout<<i;
}
int main(){
ifstream in;
DictionaryWords dictionary[300];
DictionaryWords words[300];
PassageWords pass[300];
char file[300];
char passage[300];
int choice;
int numWords=0;
int wordCount=0;
printMenu();
cin>>choice;
while(choice!=5){
if(choice==1){
char op1;
cout<<"Enter E for English, S for Spanish, F for French or m for Menu: ";
cin>>op1;
if(op1=='E'){
wordCount=loadEng(dictionary);
//option1(words, op1);
}
else if(op1=='S'){
wordCount= loadEs(dictionary);
}
else if(op1=='F'){
wordCount=loadFr(dictionary);
}
else if(op1=='m'){
printMenu();
cin>>choice;
}
/*if(op1!='E'||'S'||'F'||'M'){
cout<<op1<<" is not a valid choice."<<endl;
printMenu();
cin>>choice;
}*/
} //choice 1
if(choice==2){
cout<<"Enter the name of the passage or m for Menu: ";
cin>>file;
in.open(file); //or filename.txt
if(!in.is_open()){
cout<<"Error opening file..exiting"<<endl;
cout<<endl;
}else
numWords=loadPassage(passage, file);
} //choice 2
if(choice==3){
if(strlen(passage)==0){
cout<<"Error: No passage was loaded"<<endl;
}else
cout<<"The passage reads: "<<endl;
readPassage(passage);
//cout<<numWords;
} //choice 3
if(choice==4){
countPassage(pass, file);
compare(dictionary, pass, numWords, wordCount);
} //choice 4
printMenu();
cin>>choice;
}
return 0;
}
|