Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <map>
  4. #include <string>
  5. #include <vector>
  6. #include <cstdlib>
  7. #include <ctime>
  8. using namespace std;
  9.  
  10. fstream polskie;
  11. fstream angielskie;
  12. map<string,string> vpol;
  13. map<string,string> vang;
  14. map<string,string>::iterator p;
  15. map<string,string>::iterator an;
  16. vector<string> slavic;
  17. vector<string> germanic;
  18. vector<string> :: iterator s;
  19. vector<string> :: iterator g;
  20. /*typedef map<string,string> StringFloatMap;
  21. StringFloatMap napol;
  22. StringFloatMap::iterator pol;*/
  23.  
  24. void menu()
  25. {
  26. cout << "Menu:" << endl;
  27. cout << "1) Przeglad slowek" << endl;
  28. cout << "2) Dodawanie slowek" << endl;
  29. cout << "3) Usuwananie slowek" << endl;
  30. cout << "4) Test" << endl;
  31. cout << "5) Koniec" << endl;
  32. }
  33. void jeden()
  34. {
  35. /*for (pol = napol.begin(); pol != napol.end(); ++pol) {
  36. cout << "ANG: \"" << pol->first << "\" "
  37. << "POL: " << pol->second << endl;*/
  38. cout << "Oto twoja lista slowek:" << endl;
  39. polskie.open ("polskie.txt", std::fstream::in);
  40. angielskie.open ("angielskie.txt", std::fstream::in);
  41. string a,b;
  42. while(polskie >> a && angielskie >> b)
  43. {
  44. cout << a << " "<< b << endl;
  45. }
  46. polskie.close();
  47. angielskie.close();
  48. }
  49.  
  50. void dwa()
  51. {
  52. string a,b;
  53. cout << "Jakie slowka chcesz dodac?" << endl;
  54. cout << "Polskie slowo: \n";
  55. cin >> a;
  56. cout << "Angielskie slowo: \n";
  57. cin >> b;
  58. polskie.open ("polskie.txt", std::fstream::app);
  59. angielskie.open ("angielskie.txt", std::fstream::app);
  60. polskie << a << endl;
  61. angielskie << b << endl;
  62. cout << "ok \n";
  63. /*napol["Monday"] = "Poniedzialek";
  64. napol["Tuesday"]= "Wtorek";
  65. napol["STFU"]= "Zamknij morde";
  66. napol["Wednesday"]="Sroda";
  67. napol["Thursday"]="Czwartek";
  68. napol["Friday"]="Piatek";*/
  69. polskie.close();
  70. angielskie.close();
  71.  
  72. }
  73. void trzy()
  74. {
  75. //map<string,string> vpol;
  76. //map<string,string> vang;
  77. //map<string,string>::iterator p;
  78. //map<string,string>::iterator an;
  79. string a,b;
  80. polskie.open ("polskie.txt", std::fstream::in | std::fstream::out);
  81. angielskie.open ("angielskie.txt", std::fstream::in | std::fstream::out);
  82. while(polskie >> a && angielskie >> b)
  83. {
  84. vpol[a] = b;
  85. //vang[b] = a;
  86. }
  87. //an = vang.begin();
  88. cout << "Ktory element chcesz usunac?:" << endl;
  89. for (p = vpol.begin(); p != vpol.end(); p++)
  90. {
  91. cout << p->first << " " << p->second << endl;
  92.  
  93. }
  94. cout << endl;
  95. /* polskie.close();
  96. angielskie.close();
  97. polskie.open ("polskie.txt");
  98. angielskie.open ("angielskie.txt"); */
  99. string u;
  100. cin >> u;
  101. cout << endl;
  102. vpol.erase(u);
  103. for (p = vpol.begin(); p != vpol.end(); p++)
  104. {
  105. cout << p->first << " " << p->second << endl;
  106. }
  107. cout << endl;
  108. /*for (p = vpol.begin(); p != vpol.end(); p++)
  109. {
  110. a = p->first;
  111. b = p->second;
  112. polskie << a << endl;
  113. angielskie << b << endl;
  114.  
  115. }*/
  116. polskie.close();
  117. angielskie.close();
  118.  
  119. }
  120. void pomocniczy()
  121. {
  122. polskie.open ("polskie.txt");
  123. angielskie.open ("angielskie.txt");
  124. string a,b;
  125. p = vpol.begin();
  126. while ( p != vpol.end())
  127. {
  128. a = p->first;
  129. b = p->second;
  130. polskie << a << endl;
  131. angielskie << b << endl;
  132. p++;
  133.  
  134. }
  135. polskie.close();
  136. angielskie.close();
  137. }
  138.  
  139. void cztery()
  140. {
  141. polskie.open ("polskie.txt", std::fstream::in | std::fstream::out);
  142. angielskie.open ("angielskie.txt", std::fstream::in | std::fstream::out);
  143. string a, b;
  144. int iteratorek = 0;
  145. int dlugosc = 0;
  146. int wynik = 0;
  147. while(polskie >> a && angielskie >> b)
  148. {
  149. slavic.push_back(a);
  150. germanic.push_back(b);
  151.  
  152. }
  153. srand(time(NULL));
  154. for(s = slavic.begin(); s != slavic.end(); s++)
  155. {
  156. dlugosc++;
  157. }
  158. for(int i = 0; i < 10; i++)
  159. {
  160. iteratorek = rand() % dlugosc;
  161. cout << germanic[iteratorek] << " - ";
  162. cin >> a;
  163. if(a == slavic[iteratorek])
  164. {
  165. cout << " " << "DOBRZE" << endl;
  166. wynik ++;
  167. }
  168. else
  169. cout << " " << "ZLE! Poprawna odpowiedz to: " << slavic[iteratorek] << endl;
  170. }
  171. cout << endl << "Twoj wynik to: " << wynik << "/10" << endl;
  172. polskie.close();
  173. angielskie.close();
  174. }
  175. int main()
  176. {
  177. menu();
  178. int x = 1;
  179. cout << endl;
  180.  
  181. //dwa();
  182. //jeden();
  183. /*map<string,string>naang;
  184. naang["Poniedzialek"] = "Monday";
  185. naang["Wtorek"]= "Tuesday";
  186. naang["Zamknij morde"]= "STFU";
  187. naang["Sroda"]="Wednesday";
  188. naang["Czwartek"]="Thursday";
  189. naang["Piatek"]="Friday";*/
  190. while(x != 0)
  191. {
  192. switch(getchar())
  193. {
  194. case '1':
  195. jeden();
  196. break;
  197. case '2':
  198. dwa();
  199. break;
  200. case '3':
  201. trzy();
  202. pomocniczy();
  203. break;
  204. case '4':
  205. cztery();
  206. break;
  207. case '5':
  208. return 0;
  209. break;
  210. }
  211. }
  212. return 0;
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement