标签:
无聊写的,结果越写越大。。。词典是网上找的,跟我的设想有点不一样所以修改了一下它的格式用的下面的代码。
1 #include <iostream> 2 #include <fstream> 3 #include <vector> 4 using namespace std; 5 6 int main() 7 { 8 ifstream fileRead("temp.dat"); 9 vector<int> num; 10 vector<string> en; 11 vector<string> cn; 12 int numbuffer; 13 string enbuffer, cnbuffer; 14 while(fileRead >> numbuffer >> enbuffer >> cnbuffer) 15 { 16 num.push_back(numbuffer); 17 en.push_back(enbuffer); 18 cn.push_back(cnbuffer); 19 } 20 fileRead.close(); 21 ofstream fileWrite("data.dat", ios::out); 22 for(int i = 0; i < cn.size(); i++) 23 { 24 fileWrite << en[i] << " " << cn[i] << " " << 0 << endl; //初始化词典 25 } 26 }
接下来是程序部分。
1 #pragma once 2 3 #include <iostream> 4 #include <string> 5 #include <cstring> 6 7 using namespace std; 8 9 typedef class __WORDLIST 10 { 11 public: /*构造析构函数*/ 12 __WORDLIST(); //默认必须是空,否则在getWord函数返回的就不是NULL指针了 13 __WORDLIST(string, string, int); //用于初始化新增单词的构造函数 14 __WORDLIST(string, string); //用于修改单词的构造函数 15 ~__WORDLIST(); 16 public: 17 const string &getEnglish() const; //获取单词信息,为了dataBase中的排序闭包,因此返回const 18 const string &getChinese() const; 19 const int &getWrongTimes() const; 20 void changeEnglish(string); //修改单词成员 21 void changeChinese(string); 22 void changeWrongTimes(int); 23 void addWrongTimes(); 24 protected: //单词双意 25 string English; 26 string Chinese; 27 int WrongTimes; //单词错的次数 28 }wordList;
1 #include "wordList.h" 2 3 __WORDLIST::__WORDLIST() {} 4 5 __WORDLIST::__WORDLIST(string en, string cn, int tm = 0) : English(en), Chinese(cn), WrongTimes(tm){} 6 7 __WORDLIST::__WORDLIST(string en, string cn) : English(en), Chinese(cn){} 8 9 __WORDLIST::~__WORDLIST() {} 10 11 const string &wordList::getEnglish() const 12 { 13 return English; 14 } 15 16 const string &wordList::getChinese() const 17 { 18 return Chinese; 19 20 } 21 const int &wordList::getWrongTimes() const 22 { 23 return WrongTimes; 24 } 25 26 void wordList::changeEnglish(string curEnglish) 27 { 28 English = curEnglish; 29 } 30 void wordList::changeChinese(string curChinese) 31 { 32 Chinese = curChinese; 33 } 34 35 void wordList::changeWrongTimes(int curWrongTime) 36 { 37 WrongTimes = curWrongTime; 38 } 39 40 void wordList::addWrongTimes() 41 { 42 WrongTimes++; 43 }
1 /*直接对文件操作的类*/ 2 3 #pragma once 4 5 #include <iostream> 6 #include <vector> 7 #include "wordList.h" 8 9 using namespace std; 10 11 typedef class __DATABASE 12 { 13 public: 14 __DATABASE(); //读取文件 15 ~__DATABASE(); //保存文件 16 public: 17 int wordSize(); //统计单词数,返回值为单词数 18 bool wordIsEmpty(); //判断词典是否为空,返回值为判断是否为空 19 void sortWord(); //按字典序对词典进行排序 20 void addWord(__WORDLIST); //添加新单词 21 bool removeWord(int); //根据英文序号查找并删除单词 22 __WORDLIST getWord(int); //根据英文序号对应单词,返回值为单词类 23 int getWordWrongTime(int); //根据英文序号获取对应单词错的次数 24 int searchWord(string); //根据英文查找对应单词,返回值为单词序号(二分) 25 bool changeWordNum(int, __WORDLIST);//按序号对应单词并修改,返回是否成功 26 string getChinese(int); //获取对应单词的中文信息 27 void addWrongTimes(int); //增加错误次数 28 vector<__WORDLIST> getWrongWords(); //获取错词的信息(只要错了就获取) 29 int getWordNum(string); //获取单词序号,用于统计错词 30 void rmFromWrong(string); //从错词库中删除 31 protected: 32 vector<__WORDLIST> word; 33 __WORDLIST wordlist; 34 }DATABASE;
1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #include <fstream> 5 #include "dataBase.h" 6 7 #define NOTFOUND_INT -1 8 #define NOTFOUND_BOOL false 9 #define CHANGESUCCESS true 10 11 using namespace std; 12 13 __DATABASE::__DATABASE() /*初始化操作*/ 14 { 15 string enBuffer; 16 string cnBuffer; 17 int tmBuffer; 18 19 ifstream fileRead("Data/dictionary.dat"); //打开词典 20 if (!fileRead) 21 { 22 /*提示错误信息*/ 23 cerr << "找不到词典文件!请将词典文件放入Data文件夹内!" << endl; 24 system("pause"); 25 exit(EXIT_FAILURE); 26 } 27 sortWord(); 28 while (fileRead >> enBuffer >> cnBuffer >> tmBuffer) //硬盘文件转入内存 29 { 30 wordlist.changeChinese(cnBuffer); 31 wordlist.changeEnglish(enBuffer); 32 wordlist.changeWrongTimes(tmBuffer); 33 34 word.push_back(wordlist); //扔入容器中以备操作 35 } 36 fileRead.close(); 37 } 38 39 __DATABASE::~__DATABASE() //保存词典 40 { 41 ofstream fileWrite("Data/dictionary.dat", ios::out); 42 for (int i = 0; i < wordSize(); i++) 43 { 44 fileWrite << word[i].getEnglish() << " " 45 << word[i].getChinese() << " " 46 << word[i].getWrongTimes() << endl; 47 } 48 fileWrite.close(); 49 } 50 51 int DATABASE::wordSize() //统计单词数,返回值为单词数 52 { 53 return word.size(); 54 } 55 56 bool DATABASE::wordIsEmpty() //判断词典是否为空,返回值为判断是否为空 57 { 58 return wordSize() == 0 ? true : false; 59 } 60 61 void DATABASE::sortWord() //按字典序对词典进行排序 62 { 63 sort(begin(word), end(word), [](const wordList &a, const wordList &b) //闭包解决sort传值问题 64 { 65 return a.getEnglish() < b.getEnglish(); 66 }); 67 } 68 69 void DATABASE::addWord(wordList curwordlist) //添加新单词 70 { 71 word.push_back(curwordlist); 72 sortWord(); 73 } 74 75 wordList DATABASE::getWord(int num) //根据英文序号对应单词,返回值为单词节点 76 { 77 if (num < 0 || num > wordSize() - 1) 78 { 79 wordList *null = new wordList(); 80 return *null; //下表不合法,返回一个空节点 81 } 82 return word[num]; 83 } 84 85 bool DATABASE::removeWord(int num) //删除单词 86 { 87 if(num < 0 || num > wordSize()) 88 { 89 return NOTFOUND_BOOL; 90 } 91 else 92 { 93 word.erase(begin(word) + num - 1); 94 return CHANGESUCCESS; 95 } 96 } 97 98 int DATABASE::searchWord(string curEnglish) //根据英文查找对应单词,返回值为单词序号(二分) 99 { 100 sortWord(); //想二分,先排序 101 int left = 0; 102 int right = wordSize() - 1; 103 int middle; 104 while (left <= right) 105 { 106 middle = (left + right) / 2; 107 if (word[middle].getEnglish() == curEnglish) 108 { 109 return middle; 110 } 111 else if (word[middle].getEnglish() > curEnglish) //在左 112 { 113 right = middle - 1; 114 } 115 else //在右 116 { 117 left = middle + 1; 118 } 119 } 120 return NOTFOUND_INT; 121 } 122 123 bool DATABASE::changeWordNum(int num, wordList curwordlist) //按序号对应单词并修改,返回是否成功 124 { 125 if (num < 0 || num > wordSize() - 1) 126 { 127 return NOTFOUND_BOOL; 128 } 129 word[num] = curwordlist; 130 sortWord(); //排序 131 return CHANGESUCCESS; 132 } 133 134 int DATABASE::getWordWrongTime(int num) //获取该词错次数 135 { 136 return word[num].getWrongTimes(); 137 } 138 139 string DATABASE::getChinese(int num) //获取中文翻译 140 { 141 return word[num].getChinese(); 142 } 143 144 145 void DATABASE::addWrongTimes(int num) 146 { 147 word[num].addWrongTimes(); 148 } 149 150 vector<__WORDLIST> DATABASE::getWrongWords() //获取错词信息 151 { 152 vector<__WORDLIST> wrongWords; 153 int LEN = wordSize(); 154 for (int i = 0; i < LEN; i++) 155 { 156 if (word[i].getWrongTimes() != 0) 157 { 158 wrongWords.push_back(word[i]); 159 } 160 } 161 sort(begin(wrongWords), end(wrongWords), [](const wordList &a, const wordList &b) 162 {//sort闭包,按照单词的错误次数从小到大排出来 163 return a.getWrongTimes() < b.getWrongTimes(); 164 }); 165 return wrongWords; 166 } 167 168 int DATABASE::getWordNum(string curEnglish) //获取单词序号,用于统计错词 169 { 170 return searchWord(curEnglish); 171 } 172 173 void DATABASE::rmFromWrong(string curEnglish) //从错词库中删除 174 { 175 int temp = searchWord(curEnglish); 176 word[temp].changeWrongTimes(0); 177 } 178 179 //bool DATABASE::changeWordWod(wordList tarwordlist, wordList curwordlist)//按单词对应单词并修改,返回是否成功 180 //{ 181 // int LEN = wordSize() - 1; 182 // bool FOUND = false; 183 // for (int i = 0; i < LEN; i++) 184 // { 185 // if () 186 // } 187 // if (FOUND) 188 // { 189 // return FOUND; 190 // } 191 // else 192 // { 193 // return NOTFOUND_BOOL; 194 // } 195 //}
1 #pragma once 2 3 #include "dataBase.h" 4 5 typedef class __KILLEDLIST : public __DATABASE 6 { 7 public: 8 __KILLEDLIST(); 9 ~__KILLEDLIST(); 10 }killedList;
1 #include "killedList.h" 2 #include <fstream> 3 4 using namespace std; 5 6 7 __KILLEDLIST::__KILLEDLIST() : __DATABASE() 8 { 9 string enBuffer; 10 string cnBuffer; 11 int tmBuffer; 12 ifstream fileRead("Data/killed.dat"); //打开已斩词典 13 if (!fileRead) 14 { 15 /*提示错误信息*/ 16 cerr << "找不到斩词文件!" << endl; 17 system("pause"); 18 exit(EXIT_FAILURE); 19 } 20 vector<wordList>().swap(word);//由于是继承来的,所以在调用子类构造函数时一定会调用父类的。 21 //这时候vector内非空,用这个方法清空vector。 22 // word.clear(); //不可行,得到的值不一定是0(word不一定是空) 23 // cout << word.capacity() << endl; 24 sortWord(); 25 while (fileRead >> enBuffer >> cnBuffer >> tmBuffer) //硬盘文件转入内存 26 { 27 wordlist.changeChinese(cnBuffer); 28 wordlist.changeEnglish(enBuffer); 29 wordlist.changeWrongTimes(tmBuffer); 30 31 word.push_back(wordlist); //扔入容器中以备操作 32 } 33 fileRead.close(); 34 } 35 36 __KILLEDLIST::~__KILLEDLIST() 37 { 38 ofstream fileWrite("Data/killed.dat", ios::out); 39 for (int i = 0; i < wordSize(); i++) 40 { 41 fileWrite << word[i].getEnglish() << " " 42 << word[i].getChinese() << " " 43 << word[i].getWrongTimes() << endl; 44 } 45 fileWrite.close(); 46 }
1 #pragma once 2 3 #include <vector> 4 #include <string> 5 #include <fstream> 6 #include <iostream> 7 #include <cstdlib> 8 #include <iomanip> 9 #include "dataBase.h" 10 #include "killedList.h" 11 12 using namespace std; 13 14 typedef class __MAINFRAME 15 { 16 public: /*构造、析构函数*/ 17 __MAINFRAME(); 18 ~__MAINFRAME(); 19 public: /*功能*/ 20 int CLIwordInit(); //初始化界面 21 void wordInput(); //录入新单词 22 void wordShow(); //显示词典 23 void killShow(); //显示已斩单词 24 void sortWord(); //单词排序 25 void wordChange(); //修改单词 26 void wordDelete(); //删除单词 27 void wordLooking();//查询单词 28 void wordKiller(int);//斩词 29 void killedRescue();//恢复已斩单词 30 void wordExercise();//背单词(可斩词) 31 void wordExam(); //呵呵哒模式 32 void wordReview(); //复习单词功能 33 void aboutMe(); //关于作者 34 void famousMotto(); //打印名言 ** 35 void wordExit(); //退出本软件 36 //public: //test 37 // __DATABASE getDatabase(); //test 38 protected: 39 __DATABASE dataBase; //单词数据库 40 __KILLEDLIST killedBase;//已斩单词数据库 41 }mainFrame;
1 #include "mainframe.h" 2 #include <random> 3 #include <algorithm> 4 #include <iomanip> 5 6 __MAINFRAME::__MAINFRAME() {} 7 8 __MAINFRAME::~__MAINFRAME() {} 9 10 void outputBlank(int n) //输出回车,规划界面。 11 { 12 for (int i = 0; i < n; i++) 13 { 14 cout << endl; 15 } 16 } 17 18 void mainFrame::famousMotto() //打印名言 19 { 20 ifstream fileOpen("Data\\motto.dat"); 21 string temp; 22 vector<string> motto; 23 while (fileOpen >> temp) 24 { 25 motto.push_back(temp); 26 } 27 random_device rd; //种子 28 uniform_int_distribution<int> dicSeed(0, 10); //生成从词典取单词的随机数的种子 29 int mtrdm = dicSeed(rd); 30 cout << "*********今日名言: " << motto[mtrdm] << "*********" << endl; 31 fileOpen.close(); 32 } 33 34 void mainFrame::aboutMe() //关于作者 35 { 36 system("cls"); 37 outputBlank(10); 38 cout << " HitomiSAMA发现了彩蛋,Young man!" << endl; 39 outputBlank(10); 40 system("pause"); 41 } 42 43 int mainFrame::CLIwordInit() //命令行版初始化界面 44 { 45 int choice; 46 bool initFlag = true; 47 bool exitflag = false; 48 // system("cls"); 49 while (1) 50 { 51 if (exitflag == true) 52 { 53 outputBlank(12); 54 cout << setw(50) << "谢谢HitomiSAMA的使用!" << setw(20); 55 outputBlank(12); 56 return EXIT_SUCCESS; 57 } 58 // famousMotto(); 59 cout << "*******************************欢迎进入wordKiller*******************************" << endl; 60 cout << "**** ****" << endl; 61 cout << "**** 0.单词查询 ****" << endl; 62 cout << "**** 1.录入新单词 ****" << endl; 63 cout << "**** 2.显示词典 ****" << endl; 64 cout << "**** 3.显示已斩单词 ****" << endl; 65 cout << "**** 4.恢复已斩单词 ****" << endl; 66 cout << "**** 5.背单词 ****" << endl; 67 cout << "**** 6.呵呵哒模式 ****" << endl; 68 cout << "**** 7.修改单词 ****" << endl; 69 cout << "**** 8.删除单词 ****" << endl; 70 cout << "**** 9.复习错词 ****" << endl; 71 cout << "**** 10.退出软件 ****" << endl; 72 outputBlank(1); 73 if (initFlag == true) 74 { 75 cout << "请选择HitomiSAMA想要使用的功能: "; 76 } 77 else 78 { 79 cout << "HitomiSAMA的输入有误,请重试!" << endl; 80 } 81 cin >> choice; 82 if (choice == 12345 || (choice >= 0 && choice <= 10)) 83 { 84 initFlag = true; 85 } 86 else 87 { 88 initFlag = false; 89 system("cls"); 90 continue; 91 } 92 switch (choice) 93 { 94 case 1: wordInput(); break; 95 case 2: wordShow(); break; 96 case 3: killShow(); break; 97 case 4: killedRescue(); break; 98 case 5: wordExercise(); break; 99 case 6: wordExam(); break; 100 case 7: wordChange(); break; 101 case 8: wordDelete(); break; 102 case 9: wordReview(); break; 103 case 0: wordLooking(); break; 104 case 10: exitflag = true; break; 105 case 12345: aboutMe(); break; 106 } 107 system("cls"); 108 } 109 } 110 void mainFrame::wordLooking()//查询单词 111 { 112 system("cls"); 113 string curEnglish = "!"; 114 cout << "**** 0.单词查询 ****" << endl; 115 outputBlank(2); 116 while (curEnglish != "#") 117 { 118 cout << "请输入HitomiSAMA想要查询的单词的拼写,输入\"#\"退出查询功能: "; 119 cin >> curEnglish; 120 fflush(stdin); 121 int wd = dataBase.searchWord(curEnglish); 122 if (wd == -1) 123 { 124 cout << "并没有找到该单词!" << endl << endl; 125 } 126 else 127 { 128 cout << "单词 " << curEnglish << " 的中文解释为: " << dataBase.getChinese(wd) << endl << endl; 129 } 130 } 131 } 132 void mainFrame::wordInput() //录入新单词 133 { 134 string curEnglish = "!"; 135 string curChinese; 136 137 system("cls"); 138 cout << "**** 1.录入新单词 ****" << endl; 139 outputBlank(2); 140 while (curEnglish != "#") 141 { 142 cout << "请输入HitomiSAMA想要录入的英文单词,按#退出: "; 143 cin >> curEnglish; 144 if (curEnglish == "#") 145 { 146 break; 147 } 148 if (dataBase.searchWord(curEnglish) >= 0) //存在 149 { 150 /*提示单词已存在,不需要添加,返回*/ 151 cout << "单词已存在,并不需要再次添加。" << endl; 152 } 153 else 154 { 155 /*输出提示信息,并且输入 中文单词*/ 156 cout << "请输入汉语释意: "; 157 cin >> curChinese; 158 int flag = 0; 159 cout << "HitomiSAMA要录入的单词为: " << curEnglish << ", 它的解释为: " << curChinese << "确认录入本单词吗?(1确认0再想想)" << endl; 160 cin >> flag; 161 if (flag == 1) 162 { 163 wordList BUFFER(curEnglish, curChinese, 0); 164 dataBase.addWord(BUFFER); 165 cout << "录入完毕,HitomiSAMA录入的单词为: " << curEnglish << ", 它的解释为: " << curChinese << endl; 166 } 167 else if (flag == 0) 168 { 169 cout << "撤销成功!" << endl << endl; 170 } 171 else 172 { 173 cout << "HitomiSAMA输入的信息有误!" << endl; 174 } 175 } 176 } 177 } 178 179 void mainFrame::wordShow() //显示词典信息 180 { 181 int LEN = dataBase.wordSize(); 182 /*输出提示信息:查看完单词表后请关闭*/ 183 system("cls"); 184 cout << "**** 2.显示词典 ****" << endl; 185 outputBlank(2); 186 cout << "HitomiSAMA的词典里一共有 " << dataBase.wordSize() << "个单词。" << endl; 187 for (int i = 0; i < LEN; i++) 188 { 189 wordList BUFFER; 190 BUFFER = dataBase.getWord(i); 191 cout << BUFFER.getEnglish() << " " << BUFFER.getChinese() << endl; 192 } 193 // system("notepad Data\\dictionary.dat"); //读取文件 194 outputBlank(2); 195 cout << "按任意键返回。 " << endl; 196 fflush(stdin); 197 getchar(); 198 } 199 200 void mainFrame::sortWord() //单词排序 201 { 202 dataBase.sortWord(); 203 } 204 205 void mainFrame::wordChange() //修改单词 206 { 207 int Num; 208 int flag = 1; 209 string curEnglish = "!"; 210 string curChinese; 211 system("cls"); 212 cout << "**** 7.修改单词 ****" << endl; 213 outputBlank(2); 214 while (curEnglish != "#") 215 { 216 if (dataBase.wordIsEmpty()) 217 { 218 bool ADD; 219 cout << endl << "HitomiSAMA还没有添加任何单词,是否要添加单词(1添加/0不添加)?" << endl; 220 cin >> ADD; 221 fflush(stdin); 222 if (ADD) 223 { 224 wordInput(); 225 break; 226 } 227 else 228 { 229 return; 230 } 231 } 232 while (flag == 1 || curEnglish != "#") 233 { 234 cout << "请输入HitomiSAMA想要修改的单词的拼写,输入#退出: "; //词库太大,不提供序号修改服务 235 cin >> curEnglish; 236 fflush(stdin); //清空缓冲区 237 if (dataBase.searchWord(curEnglish) < 0) 238 { 239 /*提示单词不存在,输入错误,返回*/ 240 cout << "此单词并不能存在,请重试。" << endl; 241 } 242 else 243 { 244 Num = dataBase.searchWord(curEnglish); 245 cout << "此单词的中文解释为: " << dataBase.getChinese(Num) << endl; 246 cout << "请输入HitomiSAMA想要修改单词对应的中文解释: "; 247 cin >> curChinese; 248 fflush(stdin); 249 wordList BUFFER(curEnglish, curChinese, dataBase.getWordWrongTime(Num)); /*写*/ 250 dataBase.changeWordNum(Num, BUFFER); 251 cout << "修改成功! 是否继续修改(1是/0否)? "; 252 cin >> flag; 253 } 254 } 255 getchar(); 256 return; 257 /*提示修改成功*/ 258 } 259 } 260 261 void mainFrame::wordDelete() //删除单词 262 { 263 system("cls"); 264 string curEnglish = "!"; 265 string curChinese; 266 int Num; 267 cout << "**** 8.删除单词 ****" << endl; 268 outputBlank(2); 269 while (curEnglish != "#") 270 { 271 cout << "请输入HitomiSAMA想删除的单词的英文,输入#退出: "; 272 cin >> curEnglish; 273 if (curEnglish == "#") 274 { 275 break; 276 } 277 if (dataBase.searchWord(curEnglish) < 0) //不存在 278 { 279 cout << "HitomiSAMA选的单词并不存在,请重新选择! " << endl; 280 } 281 else 282 { 283 int flag; 284 cout << "确认要删除它吗?(1是/0否) "; 285 cin >> flag; 286 fflush(stdin); 287 if (flag == 1) 288 { 289 Num = dataBase.searchWord(curEnglish) + 1; 290 dataBase.removeWord(Num); 291 cout << "删除成功!HitomiSAMA再也见不到它了" << endl; 292 } 293 else 294 { 295 cout << "撤销成功!" << endl; 296 } 297 } 298 } 299 } 300 301 void mainFrame::wordExercise() //背单词 302 { 303 system("cls"); 304 cout << "**** 5.背单词 ****" << endl; 305 random_device rd; 306 uniform_int_distribution<int> dicSeed(0, dataBase.wordSize() - 1); //生成从词典取单词的随机数的种子 307 dicSeed(rd); 308 vector<wordList> answers; 309 int flag = 1; 310 while (flag == 1) 311 { 312 if (flag != 1) 313 { 314 return; 315 } 316 int TIME; 317 cout << "HitomiSAMA的词典里有" << dataBase.wordSize() << "个单词,HitomiSAMA想背几个单词? "; 318 cin >> TIME; 319 fflush(stdin); 320 for (int i = 0; i < TIME; i++) 321 { 322 int chosen = dicSeed(rd); 323 wordList word = dataBase.getWord(chosen); 324 answers.push_back(word); 325 cout << "Round " << i + 1 << ": " << answers[i].getEnglish() << setw(10) << answers[i].getChinese() << endl; 326 wordKiller(chosen); //斩词功能 327 } 328 cout << endl << "不尽兴?还要再来一发吗?(1来一发/0不用了) "; 329 cin >> flag; 330 } 331 } 332 333 void mainFrame::wordExam() //呵呵哒模式 334 { 335 system("cls"); 336 cout << "**** 6.呵呵哒模式 ****" << endl; 337 random_device rd; //种子 338 uniform_int_distribution<int> dicSeed(0, dataBase.wordSize() - 1); //生成从词典取单词的随机数的种子 339 uniform_int_distribution<int> ansSeed(0, 3); //生成四个数中的一个作为答案的种子 340 uniform_int_distribution<int> exaSeed(0, 1); //生成题目是汉译英还是英译汉的种子 341 dicSeed(rd); 342 wordList optAns[4]; //存储四个备选答案 343 wordList temp; //用于存储错的单词 344 string answer; //用来存放答案 345 int ansNum, chsNum; 346 int score = 0, count = 1; 347 int range; //单词数目 348 int exam; 349 double ratio; 350 cout << "欢迎进入\"呵呵哒\"模式,HitomiSAMA希望考几个单词呢? "; 351 cin >> range; 352 //range = 5; //test 353 cout << "Link start!" << endl << endl; 354 for (int i = 0; i < range; i++) 355 { 356 exam = exaSeed(rd); 357 if (exam == 0) /*题干中文选项英语*/ 358 { 359 for (int i = 0; i < 4; i++) //给四个答案赋值 360 { 361 optAns[i] = dataBase.getWord(dicSeed(rd)); 362 } 363 ansNum = ansSeed(rd); //生成随机答案 364 for (int i = 0; i < 4; i++) 365 { 366 cout << i + 1 << ": " << left << setw(10) << optAns[i].getEnglish(); 367 if ((i + 1) % 2 == 0) 368 { 369 cout << endl; 370 } 371 } 372 cout << "Round " << count++ << ": 请选择英文为\"" << optAns[ansNum].getChinese() << "\"的单词。 "; 373 374 cin >> chsNum; 375 chsNum--; //匹配存放数字习惯 376 if (chsNum == ansNum) 377 { 378 score++; 379 cout << "HitomiSAMA答对了" << endl; 380 } 381 else 382 { 383 int wr = dataBase.searchWord(optAns[ansNum].getEnglish()); //记下错词在词典vector中的位置 384 cout << "对不起,HitomiSAMA答错了。" << endl; 385 dataBase.addWrongTimes(wr); 386 //cout << "+1" << endl; 387 } 388 } 389 else if (exam == 1) /*题干英语选项中文*/ 390 { 391 for (int i = 0; i < 4; i++) //给四个答案赋值 392 { 393 optAns[i] = dataBase.getWord(dicSeed(rd)); 394 } 395 ansNum = ansSeed(rd); //生成随机答案 396 for (int i = 0; i < 4; i++) 397 { 398 cout << i + 1 << ": " << left << setw(10) << optAns[i].getChinese(); 399 if ((i + 1) % 2 == 0) 400 { 401 cout << endl; 402 } 403 } 404 cout << "Round " << count++ << ": 请选择中文为\"" << optAns[ansNum].getEnglish() << "\"的汉语。 "; 405 406 cin >> chsNum; 407 chsNum--; //匹配存放数字习惯 408 if (chsNum == ansNum) 409 { 410 score++; 411 cout << "HitomiSAMA答对了" << endl; 412 } 413 else 414 { 415 int wr = dataBase.searchWord(optAns[ansNum].getEnglish()); //记下错词在词典vector中的位置 416 cout << "对不起,HitomiSAMA答错了。" << endl; 417 dataBase.addWrongTimes(wr); 418 //cout << "+1" << endl; 419 } 420 } 421 } 422 ratio = double(score) / double(range); 423 cout << "Stop,HitomiSAMA一共得了 " << score << "分" << "正确率为 " << ratio * 100 << "%,请再接再厉!" << endl; 424 cout << endl << "按任意键退出。" << endl; 425 fflush(stdin); 426 getchar(); 427 } 428 429 void mainFrame::killShow() //显示已斩单词 430 { 431 system("cls"); 432 cout << "**** 3.显示已斩单词 ****" << endl; 433 if (killedBase.wordSize() == 0) 434 { 435 int flag; 436 cout << endl << "HitomiSAMA还没有斩任何单词!HitomiSAMA想斩个痛快吗?(1是/0否) "; 437 cin >> flag; 438 if (flag) 439 { 440 wordExercise(); 441 return; 442 } 443 else 444 { 445 return; 446 } 447 } 448 cout << "HitomiSAMA一共斩了: " << killedBase.wordSize() << " 个单词,请务必再接再厉!" << endl; 449 // system("notepad Data\\killed.dat"); //读取文件 450 for (int i = 0; i < killedBase.wordSize(); i++) 451 { 452 wordList BUFFER; 453 BUFFER = killedBase.getWord(i); 454 cout << BUFFER.getEnglish() << " " << BUFFER.getChinese() << endl; 455 } 456 outputBlank(2); 457 cout << "按任意键返回。 " << endl; 458 fflush(stdin); 459 getchar(); 460 } 461 462 void mainFrame::wordKiller(int Num) //斩词 463 { 464 int judge; 465 cout << "输入1斩掉它,输入0饶了它! "; 466 cin >> judge; 467 if (judge == 1) 468 { 469 killedBase.addWord(dataBase.getWord(Num)); 470 dataBase.removeWord(Num + 1); 471 } 472 } 473 474 void mainFrame::killedRescue() //恢复已斩单词 475 { 476 system("cls"); 477 bool FLAG = true; 478 string temp = "!"; 479 cout << "**** 4.恢复已斩单词 ****" << endl; 480 outputBlank(2); 481 while (temp != "#") 482 { 483 if (killedBase.wordIsEmpty()) 484 { 485 int goKill; 486 cout << "HitomiSAMA的斩杀名单是空的!想斩个痛快吗?(1去/0不去) "; 487 cin >> goKill; 488 fflush(stdin); 489 if (goKill) 490 { 491 wordExercise(); 492 return; 493 } 494 else 495 { 496 return; 497 } 498 } 499 if (FLAG) 500 { 501 cout << "HitomiSAMA一共斩了: " << killedBase.wordSize() << " 个单词。" << endl; 502 for (int i = 0; i < killedBase.wordSize(); i++) 503 { 504 wordList BUFFER; 505 BUFFER = killedBase.getWord(i); 506 cout << BUFFER.getEnglish() << " " << BUFFER.getChinese() << endl; 507 } 508 FLAG = false; 509 } 510 else 511 { 512 cout << "还剩下 " << killedBase.wordSize() << " 个单词。" << endl; 513 for (int i = 0; i < killedBase.wordSize(); i++) 514 { 515 wordList BUFFER; 516 BUFFER = killedBase.getWord(i); 517 cout << BUFFER.getEnglish() << " " << BUFFER.getChinese() << endl; 518 } 519 } 520 outputBlank(2); 521 cout << "请输入HitomiSAMA想恢复的单词的英文拼写,输入#退出恢复功能:" << endl; 522 cin >> temp; 523 if (temp == "#") 524 { 525 return; 526 } 527 int Num = killedBase.searchWord(temp); 528 if (Num == -1) 529 { 530 cerr << "没有找到该单词!" << endl << endl; 531 } 532 else 533 { 534 wordList wtmp = killedBase.getWord(Num); 535 killedBase.removeWord(Num + 1); //删掉已斩词中的单词 536 dataBase.addWord(wtmp); //放回词典中 537 } 538 } 539 fflush(stdin); 540 getchar(); 541 } 542 543 void mainFrame::wordReview() //复习单词功能 544 { 545 int fuck = 1; 546 bool flag = true; 547 string curEnglish = "!"; 548 system("cls"); 549 cout << "**** 9.复习错词 ****" << endl; 550 outputBlank(2); 551 vector<__WORDLIST> temp = dataBase.getWrongWords(); //获取错词的容器 552 int LEN = temp.size(); 553 if (LEN == 0) 554 { 555 cout << "HitomiSAMA一个错词都没有!你一定是没有好好背单词!快去背单词!" << endl; 556 system("pause"); 557 wordExam(); 558 return; 559 } 560 cout << "在过去的日子里,HitomiSAMA一共错了 " << temp.size() << "个单词,它们分别是: " << endl; 561 for (int i = LEN - 1; i >= 0; i--) 562 { 563 cout << temp[i].getEnglish() << " \"" 564 << temp[i].getChinese() << "\" " 565 << "错了 " << temp[i].getWrongTimes() << "次。" << endl; 566 } 567 outputBlank(5); 568 while (fuck == 1) 569 { 570 if (flag) 571 { 572 cout << "现在HitomiSAMA有一次挑战他们的机会,是否迎战?(提示:此类挑战非同一般)(1是/0否) "; 573 flag = false; 574 } 575 else if (!flag && curEnglish != "#") 576 { 577 cout << "HitomiSAMA爽哉?是否再来一次?(1是/0否)" << endl; 578 } 579 else 580 { 581 outputBlank(5); 582 cout << "*******************HitomiSAMA真怂!*******************" << endl; 583 outputBlank(5); 584 fflush(stdin); 585 system("pause"); 586 return; 587 } 588 cin >> fuck; 589 if (fuck == 1) 590 { 591 system("cls"); 592 random_device rd; //种子 593 uniform_int_distribution<int> dicSeed(0, LEN - 1); //生成从词典取单词的随机数的种子 594 dicSeed(rd); 595 int rdm; 596 cout << "HitomiSAMA好爽快!来战20个回合!想撤退的话可以使用\"#\"" << endl; 597 for (int i = 0; i < 20; i++) 598 { 599 if (curEnglish == "#") 600 { 601 break; 602 } 603 rdm = dicSeed(rd); 604 cout << "Round " << i + 1 << ": 请写出意思为 \"" << temp[rdm].getChinese() << "\" 的单词的拼写: "; 605 cin >> curEnglish; 606 fflush(stdin); 607 if (curEnglish != temp[rdm].getEnglish()) 608 { 609 cout << "HitomiSAMA回答错了,正确答案应该是: " << temp[rdm].getEnglish() << endl; 610 } 611 else if (curEnglish == temp[rdm].getEnglish()) 612 { 613 int choice; 614 cout << "HitomiSAMA回答正确,是否把它放回(放回就不会出现在这里了!)?(1放了吧/0留着) "; 615 cin >> choice; 616 if (choice == 1) 617 { 618 dataBase.rmFromWrong(curEnglish); 619 LEN--; 620 } 621 if (LEN == 0) 622 { 623 cout << "HitomiSAMA没有任何错词了唷~" << endl; 624 system("pause"); 625 return ; 626 } 627 } 628 } 629 } 630 else 631 { 632 return; 633 } 634 } 635 fflush(stdin); 636 getchar(); 637 }
1 /*Unit Testing in CLI*/ 2 3 //* 4 #include "mainframe.h" 5 6 int main() 7 { 8 mainFrame testmode; 9 testmode.CLIwordInit(); 10 //DATABASE test = testmode.dataBase; 11 //__WORDLIST temp = test.getWord(0); 12 13 return EXIT_FAILURE; //未正常从mainframe中退出 14 } 15 //*/
转载请声明本站地址,谢谢。
标签:
原文地址:http://www.cnblogs.com/vencentX/p/4550603.html