Advertisement
modlicha

Prodżekt

Mar 26th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <string>
  5. #include <thread>
  6. #include <fstream>
  7. #include <algorithm>
  8. #include <vector>
  9. #include <cstdio>
  10. #include <cerrno>
  11. #include <stdio.h>
  12. #include <map>
  13. #include <iterator>
  14. #include <windows.h>
  15.  
  16. using namespace std;
  17.  
  18. void starter();
  19. void menu();
  20. void wybor();
  21. void listaslowek();
  22. void noweslowko();
  23. void informacje();
  24. void powrot();
  25. void koniec();
  26. void usunslowko();
  27. void test();
  28. void zasady();
  29. void pytania();
  30. void listawybor();
  31. void wyborpolang();
  32. void wyborpol();
  33. void wyborang();
  34.  
  35. int losuj(vector<int> v)
  36. {
  37. int losik = rand() % 10 + 1;
  38.  
  39. for (int i = 0; i < v.size(); i++)
  40. if (losik == v[i])
  41. while(losik==v[i])
  42. int losik = rand() % 10 + 1;
  43. return losik;
  44. }
  45.  
  46. int main()
  47. {
  48. starter();
  49. menu();
  50.  
  51. }
  52.  
  53. void starter()
  54. {
  55. system("CLS");
  56.  
  57. for (int i=0; i < 3; i++)
  58. {
  59. Sleep(1000);
  60. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  61. SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | BACKGROUND_GREEN);
  62. cout << " " << endl; Sleep(1000);
  63. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  64. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  65. cout << "||||||||||||||||||||||| ||||||||||||||||||||||||" << endl; Sleep(1000);
  66. cout << "||||||||||||||||||||||| ENGLISH ||||||||||||||||||||||||" << endl; Sleep(1000);
  67. cout << "||||||||||||||||||||||| TEST ||||||||||||||||||||||||" << endl; Sleep(1000);
  68. cout << "||||||||||||||||||||||| ||||||||||||||||||||||||" << endl; Sleep(1000);
  69. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  70. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  71. cout << " " << endl; Sleep(1000);
  72. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  73. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  74. cout << "||||||||||||||||||||||| ||||||||||||||||||||||||" << endl; Sleep(1000);
  75. cout << "||||||||||||||||||||||| WELCOME ||||||||||||||||||||||||" << endl; Sleep(1000);
  76. cout << "||||||||||||||||||||||| ||||||||||||||||||||||||" << endl; Sleep(1000);
  77. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  78. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  79. }
  80.  
  81. system("pause");
  82. }
  83.  
  84. void koniec()
  85. {
  86. system("CLS");
  87. for (int i = 5; i > 0; i--)
  88. {
  89. cout << i;
  90. this_thread::sleep_for(chrono::seconds(1));
  91. system("CLS");
  92. }
  93. cout << " " << endl; Sleep(1000);
  94. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  95. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  96. cout << "||||||||||||||||||||| ||||||||||||||||||||||||||" << endl; Sleep(1000);
  97. cout << "||||||||||||||||||||| Goodbye! ||||||||||||||||||||||||||"<< endl;
  98. cout << "||||||||||||||||||||| ||||||||||||||||||||||||||" << endl; Sleep(1000);
  99. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  100. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
  101. cout << " " << endl; Sleep(1000);
  102. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl;
  103. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  104. cout << "|||||||||||||| |||||||||||||||||" << endl; Sleep(1000);
  105. cout << "|||||||||||||| Press any button to exit! |||||||||||||||||" << endl;
  106. cout << "|||||||||||||| |||||||||||||||||" << endl; Sleep(1000);
  107. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  108. cout << "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" << endl; Sleep(1000);
  109. cout << " " << endl;
  110. }
  111.  
  112. void powrot()
  113. {
  114. system("PAUSE");
  115.  
  116. menu();
  117. }
  118.  
  119. void listaslowek()
  120. {
  121. system("CLS");
  122.  
  123. vector<string>slowka;
  124.  
  125. ifstream lista("lista.txt");
  126. string line;
  127. while (getline(lista, line))
  128. {
  129. slowka.push_back(line);
  130. }
  131. sort(slowka.begin(), slowka.end());
  132.  
  133. cout << "[ANG - PL] List of words:" << endl;
  134.  
  135. for (int i = 0; i < slowka.size(); i++)
  136. {
  137. cout << slowka[i] << endl;
  138. }
  139. cout << endl;
  140. listawybor();
  141. }
  142.  
  143. void listawybor()
  144. {
  145.  
  146. cout << endl;
  147. cout << "1. [ANG - POL]" << endl;
  148. cout << "2. [POL-ANG]" << endl;
  149. cout << "3. [ANG]" << endl;
  150. cout << "4. [POL]" << endl;
  151. cout << "0. Back" << endl;
  152. cout << "--> ";
  153.  
  154. char znak;
  155. cin >> znak;
  156.  
  157. switch (znak)
  158. {
  159. case '1': listaslowek(); break;
  160. case '2': wyborpolang(); break;
  161. case '3': wyborang(); break;
  162. case '4': wyborpol(); break;
  163. case '0': menu(); break;
  164. }
  165. }
  166.  
  167. void wyborpolang()
  168. {
  169. system("CLS");
  170.  
  171. vector<string>slowka;
  172.  
  173. ifstream lista("lista2.txt");
  174. string line;
  175. while (getline(lista, line))
  176. {
  177. slowka.push_back(line);
  178. }
  179. sort(slowka.begin(), slowka.end());
  180.  
  181. cout << "[PL - ANG] List of words:" << endl;
  182.  
  183. for (int i = 0; i < slowka.size(); i++)
  184. {
  185. cout << slowka[i] << endl;
  186. }
  187. cout << endl;
  188. listawybor();
  189. }
  190.  
  191. void wyborpol()
  192. {
  193. system("CLS");
  194.  
  195. vector<string>slowka;
  196.  
  197. ifstream lista("listaPOL.txt");
  198. string line;
  199. while (getline(lista, line))
  200. {
  201. slowka.push_back(line);
  202. }
  203. sort(slowka.begin(), slowka.end());
  204.  
  205. cout << "[POL] List of words:" << endl;
  206.  
  207. for (int i = 0; i < slowka.size(); i++)
  208. {
  209. cout << slowka[i] << endl;
  210. }
  211. cout << endl;
  212. listawybor();
  213. }
  214.  
  215. void wyborang()
  216. {
  217. system("CLS");
  218.  
  219. vector<string>slowka;
  220.  
  221. ifstream lista("listaANG.txt");
  222. string line;
  223. while (getline(lista, line))
  224. {
  225. slowka.push_back(line);
  226. }
  227. sort(slowka.begin(), slowka.end());
  228.  
  229. cout << "[ANG] List of words:" << endl;
  230.  
  231. for (int i = 0; i < slowka.size(); i++)
  232. {
  233. cout << slowka[i] << endl;
  234. }
  235. cout << endl;
  236. listawybor();
  237. }
  238.  
  239. void noweslowko()
  240. {
  241. system("CLS");
  242.  
  243. string NewWordAng;
  244. string NewWordPol;
  245. cout << "Write new word in english: ";
  246. cin >> NewWordAng;
  247. cout << "In polish: ";
  248. cin >> NewWordPol;
  249. map<string, string> list;
  250. list.insert(pair < string, string > (NewWordAng, NewWordPol));
  251.  
  252. ifstream sprawdzanie("listaANG.txt");
  253. string slowo;
  254. while (getline(sprawdzanie, slowo))
  255. {
  256. if (NewWordAng == slowo)
  257. {
  258. cout << endl << "This word is currently in the list of words!!" << endl;
  259. system("PAUSE");
  260. menu();
  261. }
  262. }
  263.  
  264. ofstream lista;
  265. lista.open("lista.txt", ofstream::app);
  266. lista << endl << NewWordAng << " - " << list[NewWordAng];
  267. lista.close();
  268.  
  269. ofstream lista2;
  270. lista2.open("lista2.txt", ofstream::app);
  271. lista2 << endl << list[NewWordAng] << " - " << NewWordAng;
  272. lista2.close();
  273.  
  274. ofstream listaANG;
  275. listaANG.open("listaANG.txt", ofstream::app);
  276. listaANG << endl << NewWordAng;
  277. listaANG.close();
  278.  
  279. ofstream listaPOL;
  280. listaPOL.open("listaPOL.txt", ofstream::app);
  281. listaPOL << endl << list[NewWordAng];
  282. listaPOL.close();
  283.  
  284. cout << endl << "Word '" << NewWordAng << "' has been successfully added" << endl;
  285.  
  286.  
  287. powrot();
  288. }
  289.  
  290. void usunslowko()
  291. {
  292. system("CLS");
  293.  
  294. string decyzja;
  295.  
  296. cout << "Remove all words?? [Y/N]: ";
  297. cin >> decyzja;
  298.  
  299. if (decyzja == "Y")
  300. {
  301. fstream usuwanieall;
  302. usuwanieall.open("listaANG.txt", ios::out | ios::trunc);
  303. usuwanieall.close();
  304. fstream usuwanieall2;
  305. usuwanieall2.open("listaPOL.txt", ios::out | ios::trunc);
  306. usuwanieall2.close();
  307. fstream usuwanieall3;
  308. usuwanieall3.open("lista.txt", ios::out | ios::trunc);
  309. usuwanieall3.close();
  310. fstream usuwanieall4;
  311. usuwanieall4.open("lista2.txt", ios::out | ios::trunc);
  312. usuwanieall4.close();
  313. system("CLS");
  314. cout << "All words have been deleted successfully!" << endl;
  315. powrot();
  316. }
  317. else if(decyzja == "N")
  318. {
  319. system("CLS");
  320. }
  321. else
  322. {
  323. usunslowko();
  324. }
  325. string DeletedWord;
  326. char myslnik = '-';
  327. cout << "Write a word to delete: ";
  328. cin >> DeletedWord;
  329.  
  330. map<string, string>dousuniecia;
  331. string slowko1;
  332. string slowko2;
  333.  
  334. ifstream sprawdzanie("listaANG.txt");
  335. string slowo;
  336. while (getline(sprawdzanie, slowo))
  337. {
  338. if (DeletedWord != slowo)
  339. {
  340. cout << endl << "The given word is not in the list!! You must add it before!!" << endl;
  341. system("PAUSE");
  342. menu();
  343. }
  344. }
  345.  
  346. ifstream lista;
  347. lista.open("lista.txt");
  348.  
  349. while (lista >> slowko1 >> myslnik >> slowko2)
  350. {
  351. dousuniecia.insert(pair<string, string>(slowko1, slowko2));
  352. }
  353.  
  354. ofstream listaANG;
  355. listaANG.open("listaANG.txt");
  356. for (auto it = dousuniecia.begin(); it != dousuniecia.end(); it++)
  357. {
  358. if ( it->first!= DeletedWord)
  359. {
  360. listaANG << endl << it->first;
  361. }
  362. }
  363. listaANG.close();
  364.  
  365. ofstream listaPOL;
  366. listaPOL.open("listaPOL.txt");
  367. for (auto it = dousuniecia.begin(); it != dousuniecia.end(); it++)
  368. {
  369. if (it->first != DeletedWord)
  370. {
  371. listaPOL << endl << it->second;
  372. }
  373. }
  374. listaPOL.close();
  375.  
  376. ofstream lista1;
  377. lista1.open("lista.txt");
  378. for (auto it = dousuniecia.begin(); it != dousuniecia.end(); it++)
  379. {
  380. if (it->first != DeletedWord)
  381. {
  382. lista1 << endl << it->first << " - " << it->second;
  383. }
  384. }
  385. lista1.close();
  386.  
  387. ofstream lista2;
  388. lista2.open("lista2.txt");
  389. for (auto it = dousuniecia.begin(); it != dousuniecia.end(); it++)
  390. {
  391. if (it->first != DeletedWord)
  392. {
  393. lista2 << endl << it->second << " - " << it->first;
  394. }
  395. }
  396. lista2.close();
  397.  
  398.  
  399. cout << endl << "Word '" << DeletedWord << "' has been successfully deleted" << endl;
  400. powrot();
  401. }
  402.  
  403. void test()
  404. {
  405. system("CLS");
  406.  
  407. zasady();
  408. pytania();
  409.  
  410. powrot();
  411. }
  412.  
  413. void zasady()
  414. {
  415. string potwierdzenie;
  416. cout << "RULES: " << endl;
  417. cout << "1. You have to translate words from English into Polish and vice versa" << endl;
  418. cout << "2. You have to start each word with a capital letter" << endl;
  419. cout << "3. Do not use Polish characters" << endl;
  420. cout << "READY? WRITE 'YES': ";
  421. cin >> potwierdzenie;
  422. if (potwierdzenie != "YES")
  423. {
  424. cout << endl << "Ok, maybe next time :)" << endl;
  425. powrot();
  426. }
  427. }
  428.  
  429. void pytania()
  430. {
  431. system("CLS");
  432.  
  433. map<string, string>pula;
  434. string ang;
  435. string pol;
  436. char znak = '-';
  437.  
  438. ifstream pytania;
  439. pytania.open("lista.txt");
  440.  
  441. while (pytania >> ang >> znak >> pol)
  442. {
  443. pula.insert(pair<string, string>(ang, pol));
  444. }
  445.  
  446. ifstream testlista("listaANG.txt");
  447. string testslowo;
  448. vector<string> testslowa;
  449. while (getline(testlista, testslowo))
  450. {
  451. testslowa.push_back(testslowo);
  452. }
  453.  
  454. int slowa = testslowa.size()-1;
  455.  
  456. string *pytanie = new string[slowa];
  457. string odpowiedz;
  458. vector<int>liczby;
  459. int temp2 = -1;
  460. liczby.push_back(temp2);
  461. int pop = 0;
  462. int np = 0;
  463. int i = 0;
  464. int *temp = new int[slowa + 1];
  465. for (auto it = pula.begin(); it != pula.end(); it++)
  466. {
  467. pytanie[i] = it->first;
  468. i++;
  469. }
  470.  
  471.  
  472. cout << "DIFFICULTY LEVELS: " << endl;
  473. cout << "1. Easy (" << (slowa / 3) << " word[s])" << endl;
  474. cout << "2. Normal (" << (slowa / 2) << " words)" << endl;
  475. cout << "3. Hard (" << (slowa) << " words)" << endl;
  476. cout << endl << "Choose the difficulty: ";
  477. char wybor;
  478. cin >> wybor;
  479. switch (wybor)
  480. {
  481. case '1':
  482. system("CLS");
  483. srand(time(NULL));
  484. for (int i = 0; i < slowa/3; i++)
  485. {
  486.  
  487. int los = losuj(liczby);
  488.  
  489. cout << i + 1 << ". " << pytanie[los] << endl;
  490. cin >> odpowiedz;
  491. if (odpowiedz == pula[pytanie[los]])
  492. {
  493. cout << endl << "Correct!" << endl;
  494. pop += 1;
  495. liczby.push_back(los);
  496. this_thread::sleep_for(chrono::seconds(2));
  497. }
  498. else
  499. {
  500. cout << endl << "Incorrect!" << endl;
  501. np += 1;
  502. liczby.push_back(los);
  503. this_thread::sleep_for(chrono::seconds(2));
  504. }
  505. system("CLS");
  506. }
  507. cout << "THE END" << endl << endl;
  508. cout << "Correct answers: " << pop << endl;
  509. cout << "Incorrect answers: " << np << endl << endl;
  510. break;
  511.  
  512. case '2':
  513. system("CLS");
  514. srand(time(NULL));
  515. for (int i = 0; i < slowa/2; i++)
  516. {
  517. int los = losuj(liczby);
  518.  
  519. for (int j = 0; j < slowa + 1; j++) {
  520.  
  521. los = rand() % slowa;
  522.  
  523. while (los == temp[j]) {
  524. los = rand() % slowa;
  525. }
  526. }
  527.  
  528. cout << i + 1 << ". " << pytanie[los] << endl;
  529. cin >> odpowiedz;
  530. if (odpowiedz == pula[pytanie[los]])
  531. {
  532. cout << endl << "Correct!" << endl;
  533. pop += 1;
  534. liczby.push_back(los);
  535. this_thread::sleep_for(chrono::seconds(2));
  536. }
  537. else
  538. {
  539. cout << endl << "Incorrect!" << endl;
  540. np += 1;
  541. liczby.push_back(los);
  542. this_thread::sleep_for(chrono::seconds(2));
  543. }
  544. system("CLS");
  545. }
  546. cout << "THE END" << endl << endl;
  547. cout << "Correct answers: " << pop << endl;
  548. cout << "Incorrect answers: " << np << endl << endl;
  549. break;
  550.  
  551.  
  552. case '3':
  553. system("CLS");
  554. srand(time(NULL));
  555. for (int i = 0; i < slowa; i++)
  556. {
  557. int los = losuj(liczby);
  558.  
  559. for (int j = 0; j < slowa + 1; j++) {
  560.  
  561. los = rand() % slowa;
  562.  
  563. while (los == temp[j]) {
  564. los = rand() % slowa;
  565. }
  566. }
  567.  
  568. cout << i + 1 << ". " << pytanie[los] << endl;
  569. cin >> odpowiedz;
  570. if (odpowiedz == pula[pytanie[los]])
  571. {
  572. cout << endl << "Correct!" << endl;
  573. pop += 1;
  574. liczby.push_back(los);
  575. this_thread::sleep_for(chrono::seconds(2));
  576. }
  577. else
  578. {
  579. cout << endl << "Incorrect!" << endl;
  580. np += 1;
  581. liczby.push_back(los);
  582. this_thread::sleep_for(chrono::seconds(2));
  583. }
  584. system("CLS");
  585. }
  586. cout << "THE END" << endl << endl;
  587. cout << "Correct answers: " << pop << endl;
  588. cout << "Incorrect answers: " << np << endl << endl;
  589. break;
  590. }
  591.  
  592. }
  593.  
  594. void informacje()
  595. {
  596. system("CLS");
  597.  
  598. ifstream infolista("listaANG.txt");
  599. string infoslowo;
  600. vector<string> infoslowa;
  601. while (getline(infolista, infoslowo))
  602. {
  603. infoslowa.push_back(infoslowo);
  604. }
  605.  
  606. cout << "The English test made for a math class!" << endl;
  607. cout << endl << "List of words: " << (infoslowa.size()-1) << endl;
  608. cout << "Creators: Przemek Szumczyk & Bartek Modliszewski" << endl;
  609. cout << "License: GNU General Public License" << endl;
  610. powrot();
  611. }
  612.  
  613. void wybor()
  614. {
  615. char liczba;
  616. cout << "Select the tab: ";
  617. cin >> liczba;
  618. switch (liczba)
  619. {
  620. case '1': listaslowek(); break;
  621. case '2': noweslowko(); break;
  622. case '3': usunslowko(); break;
  623. case '4': test(); break;
  624. case '5': informacje(); break;
  625. case '6': koniec(); break;
  626. default: cout << endl << "ERROR!! Please choose another option! " << endl; system("PAUSE"); menu();
  627. }
  628. }
  629.  
  630. void menu()
  631. {
  632. system("CLS");
  633.  
  634. cout << "1. List of words" << endl;
  635. cout << "2. Add word" << endl;
  636. cout << "3. Remove word" << endl;
  637. cout << "4. TEST!!!" << endl;
  638. cout << "5. Informations" << endl;
  639. cout << "6. Shut down" << endl;
  640. wybor();
  641. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement