October 6, 2002 ******************************************************************************** CALL THIS FILE EFC.CPP ******************************************************************************** #include #include #include #include #include #include #include "helpers.cpp" int main() { char *sure7="k"; int choice; DiskCheck(); cout<<" *****************************************\n" <<" *****************************************\n" <<" *** ***\n" <<" *** ****** ****** ***** ***\n" <<" *** ** * ** * ** ** ***\n" <<" *** ** ** ** ***\n" <<" *** **** **** ** ***\n" <<" *** ** ** ** ***\n" <<" *** ** * ** ** ** ***\n" <<" *** ****** ** ***** ***\n" <<" *** ***\n" <<" *****************************************\n" <<" *****************************************\n"; do { // MAIN LOOP BEGINS int error; do { // MENU CHOICE LOOP BEGINS char *ChoiceC="aa", *lang1="Native", *lang2="Foreign"; error=0; cout<<"Enter your choice:"<"<"< "; cin>>ChoiceC; if (strlen(ChoiceC) > 1) {cerr<<"\n Error! Improper entry!\n\n";error=1; goto endMenuLoop;} choice=TransC(ChoiceC[0]); cin.get(); endMenuLoop: } while (error==1); // END OF MENU CHOICE LOOP if (choice==0) HelpMenu(); if (choice==1) { char * ch1="vocabXX.txt"; ch1 = File(); if (check(ch1)==1) { int size1, i1=0, randomnumber1=105, time1a, time1b, count1=0; char foreign1[36], native1[36], flag1; size1 = ChapterSize(ch1); cout<<"\nTo see the answer and to go to the next word hit ENTER.\n"; cout<<"To quit enter 'q'.\n"; time1a=time(0); srand(time1a); cin.get(); do { randomnumber1 = random(size1); i1=0; ifstream fromVocabFile1(ch1, ios::in); while (i1<=randomnumber1) { fromVocabFile1 >> foreign1 >> native1; i1++; } flag1 = Quiz(native1, foreign1); count1++; fromVocabFile1.close(); } while (flag1!='q'); time1b=time(0)-time1a; cout<<"\n\n\n\n\n\n\n\n"; QuizTime(time1b); cout<<"\n Number of words is "<> foreign2 >> native2; i2++; } flag2 = Quiz(foreign2, native2); count2++; fromVocabFile2.close(); } while (flag2!='q'); time2b=time(0)-time2a; cout<<"\n\n\n\n\n\n\n\n"; QuizTime(time2b); cout<<"\n Number of words is "<> foreign3 >> native3; outputVocab( counter3+1, foreign3, native3); } cout<<"\nTo see the next page hit ENTER. To quit enter 'q' -> "; next3=cin.get(); cout< "; cin>>sure4; if (sure4[0]=='y' && strlen(sure4)==1) { ofstream intoVocab4(ch4, ios::app); if (!intoVocab4) { cerr<<"\n\n\n Could not open file.\n" <<" Make sure disk is not full or write protected.\n\n\n"; goto end4;} entry: cout<<"<===============35================> "; cout<<"<===============35================>\n"; cin>>foreign4>>native4; if (strlen(foreign4)>35 || strlen(native4)>35) {cerr<<"\n\n\n Entries should not be longer than 35 symbols.\n\n\n"; goto entry;} intoVocab4<> chapter5 >> descriptor5 >> words5; outputGuide( chapter5, descriptor5, words5);} cout<<"\n\nTo see the next page hit ENTER. To quit enter 'q' -> "; next5 = cin.get(); cout< "; cin>>sure7; if (sure7[0]=='y' && strlen(sure7)==1) { ofstream intoGuide7("guide.txt", ios::out); char * text7="empty.file.................................................."; int words7=0; for (int i7=0; i7<=99; i7++) {intoGuide7<>ChoiceFile; if (strlen(ChoiceFile) > 2) {cerr<<"\n Error! Improper entry!\n\n"; goto endGuide;} if (strlen(ChoiceFile)==1) {temp1='0'; temp2=ChoiceFile[0];} else {temp1=ChoiceFile[0]; temp2=ChoiceFile[1];} if (TransC(temp1)==12 || TransC(temp2)==12) {cerr<<"\n Error! Improper entry!\n\n"; goto endGuide;} chapter=10*TransC(temp1)+TransC(temp2); cout<<"\n You selected "<>ChoiceFile; if (strlen(ChoiceFile) > 2) {cerr<<"\n Error! Improper entry!\n\n"; goto endFile;} if (strlen(ChoiceFile)==1) {temp1='0'; temp2=ChoiceFile[0];} else {temp1=ChoiceFile[0]; temp2=ChoiceFile[1];} if (TransC(temp1)==12 || TransC(temp2)==12) {cerr<<"\n Error! Improper entry!\n\n"; goto endFile;} chapter[5]=temp1; chapter[6]=temp2; cout<<"\n You selected "< int checkNM(char * file) { int result; fstream test(file, ios::in); if (!test) result=0; else result=1; return result;} // CHECKING IF FILE EXISTS WITH AN ERROR MESSAGE int check(char * file) { int checkNM(char * file); int result; result=checkNM(file); if (result==0) {cout<<"\n I/O Error! File does not exist.\n\n";} return result; } // DISPLAYS A QUIZ - SHOWS ONE WORD AND AFTER 'ENTER' ANOTHER char Quiz(char * Word1, char * Word2) { char flag; cout << Word1 <<" "; flag = cin.get(); cout <<" " << Word2 << endl; return flag; } // DISPLAYS TIME void QuizTime(int time) { int minutes, seconds; minutes = time / 60; seconds = time % 60; cout<<"\n Quiz time is "<>ForeignWord>>NativeWord; i++;} inFile.close(); return (i-1); } // PROMPT FOR A HELP SYSTEM MENU void HelpMenu() {char more; cout<<"\n\n\n\n HELP SYSTEM FOR ELECTRONIC FLASHCARDS (EFC 2002.9)\n\n"; cout<<"\nEFC operates with vocabulary files which are located" <<"\nin the same directory as the EXE file itself, and are" <<"\ncalled vocab00.txt, vocab01.txt, ... vocab99.txt." <<"\n\nEach file can contain 'infinity' of entries (a word/sentence" <<"\nin one language and its translation in another)." <<"\n\nYou can add vocabulary entries using EFC." <<"\nTo edit or delete entries, open vocabulary files using Notepad." <<"\n\n\n\n\n\n\n\n\n" <<"\nTo see the next page hit ENTER. To quit enter 'q' -> "; more = cin.get(); if (more=='q') goto endhelp; cout<<"\n\n\n HELP SYSTEM FOR ELECTRONIC FLASHCARDS (EFC 2002.9)\n"; cout<<"\n\nEach vocabulary file is structured as follows:\n" <<"\na.word.in.Foreign.Language a.word.in.Native.Language" <<"\na.word.in.Foreign.Language a.word.in.Native.Language" <<"\na.word.in.Foreign.Language a.word.in.Native.Language" <<"\n <---EMPTY LINE" <<"\n\nAs long as you maintain the structure of the file, the" <<"\nprogram will function properly. The length of each entry" <<"\ncannot exceed 35 symbols." <<"\n\nAn entry in Foreign Language is separated from an entry " <<"\nin Native Language by a space symbol. Because of that" <<"\nthere can be no spaces, tabulations, etc within the entries." <<"\nYou may use underscores or dots in order to separate the" <<"\nwords." <<"\n\n" <<"\nTo see the next page hit ENTER. To quit enter 'q' -> "; more = cin.get(); if (more=='q') goto endhelp; cout<<"\n\n\n HELP SYSTEM FOR ELECTRONIC FLASHCARDS (EFC 2002.9)\n"; cout<<"\n\nEFC also creates a guide file (guide.txt) which contains" <<"\ninformation about the vocabulary files such as a description" <<"\nof a topic for the words within it and the number of them:\n" <<"\n0 empty.file 0" <<"\n1 family 271" <<"\n2 apartment 104" <<"\n3 shopping 101" <<"\n..." <<"\n\nThe length of a descriptor cannot exceed 60 symbols and" <<"\ncannot contain space, tabulation or other similar symbols." <<"\n\nNote that the guide file automatically updates the" <<"\nnumber of entries if you are editing vocabulary files using" <<"\nEFC, but not if you are using an outside editor." <<"\n\n\nTo see the next page hit ENTER. To quit enter 'q' -> "; more = cin.get(); if (more=='q') goto endhelp; cout<<"\n\n\n\n HELP SYSTEM FOR ELECTRONIC FLASHCARDS (EFC 2002.9)\n" <<"\n\nEFC allows you to run quizes in both directions (from" <<"\nNative Language to Foreign and vice versa)." <<"\n\nIt randomly picks the entries from a selected file" <<"\nand displays them on the screen. Pressing ENTER allows" <<"\nyou to see a translation and go to the next word." <<"\nPressing 'q' terminates the quiz and displays time spent" <<"\non it." <<"\n\nYou can download EFC from " <<"\n http://www.econ.jhu.edu/people/tchaidze/efc." <<"\nIf you have any comments, questions, or suggestions email " <<"\n robert@jhu.edu." <<"\n" <<"\n\n\n\n\nHit ENTER. -> ";cin.get(); endhelp: cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n"; return;} // END OF HELP SYSTEM // EDITS AN ENTRY IN THE GUIDE FILE VIA TEMPORARY FILE void updateGuide(int size, char * chapter) { int ChapterNumber, i=0, number, words; char Descriptor[60]; ofstream intoTemp("temp.txt", ios::out); ifstream fromGuide("guide.txt", ios::in); ChapterNumber = 10*TransC(chapter[5])+TransC(chapter[6]); while (i>number>>Descriptor>>words; intoTemp<>number>>Descriptor>>words; intoTemp<>number>>Descriptor>>words; intoTemp<>number>>Descriptor>>words; intoGuide< "; cin.get(); } else { intoTemp<<"THIS FILE WAS CREATED FOR TEMPORARY USE."; intoTemp<<"\nYOU CAN SAFELY DELETE IT."; if( remove( "temp.txt" ) == -1 ) cerr<<"\n\n Error deleting temp.txt. Please remove file manually.\n\n"; } return; }