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 }