Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <fstream>
  5. //#include <cstdlib>
  6. //#include <cctype>
  7. #include <Windows.h>
  8.  
  9. using namespace std;
  10.  
  11. string path1 = "vocabulary_rus.txt";
  12. string path2 = "vocabulary_eng.txt";
  13. ifstream fin;
  14. ofstream fout1;
  15. ofstream fout2;
  16.  
  17. char ch;
  18. int stateX; //мини-меню
  19. string word, word_fn;
  20. int con = 1; //переменная для главного меню
  21.  
  22. vector <string> vector1;
  23.  
  24. class menu {
  25. protected:
  26. int state = 0;
  27. virtual bool init() = 0;
  28. virtual int button() = 0;
  29. virtual void print() = 0;
  30. };
  31.  
  32. class MainMenu : public menu{
  33. public:
  34. virtual bool init() { return 0; }
  35. virtual void print() {
  36. system("cls");
  37. cout << "Выберите язык/Choose language " << endl;
  38. cout << "____________________________" << endl;
  39. cout << "(1) Русский" << endl;
  40. cout << "(2) English" << endl;
  41. cout << "(0) Выход/Exit" << endl;
  42. }
  43. virtual int button() {
  44. cin >> state;
  45. return state;
  46. }
  47. };
  48.  
  49. class RusVoc : public menu {
  50. public:
  51. virtual bool init() {
  52. fin.open(path1);
  53. if (!fin.is_open())
  54. {
  55. cout << "Ошибка считывания!" << endl;
  56. return 1;
  57. }
  58. return 0;
  59. }
  60. virtual void print() {
  61. system("cls");
  62. cout << "Русский словарь" << endl;
  63. cout << "____________________________" << endl;
  64. cout << "(1) Добавить новое слово" << endl;
  65. cout << "(2) Найти слово" << endl;
  66. cout << "(3) Вывести весь словарь" << endl;
  67. cout << "(4) Узнать о слове больше в переводчике" << endl;
  68. cout << "(0) Выход в меню" << endl;
  69. }
  70.  
  71. virtual int button() {
  72. cin >> state;
  73. return state;
  74. }
  75.  
  76. };
  77.  
  78. class EngVoc : public menu {
  79. public:
  80. virtual bool init() {
  81. fin.open(path2);
  82. if (!fin.is_open())
  83. {
  84. cout << "Ошибка считывания!" << endl;
  85. return 1;
  86. }
  87. return 0;
  88. }
  89.  
  90. virtual void print() {
  91. system("cls");
  92. cout << "English vocabulary" << endl;
  93. cout << "____________________________" << endl;
  94. cout << "(1) Add a new word" << endl;
  95. cout << "(2) Find the word" << endl;
  96. cout << "(3) Display the entire dictionary" << endl;
  97. cout << "(4) Check out more about the word on translator" << endl;
  98. cout << "(0) Exit to menu" << endl;
  99. }
  100.  
  101. virtual int button() {
  102. cin >> state;
  103. return state;
  104. }
  105. };
  106.  
  107. int MianMenu_start();
  108. int RusMenu_start();
  109. int EngMenu_start();
  110.  
  111. MainMenu Main;
  112. EngVoc EngMenu;
  113. RusVoc RusMenu;
  114.  
  115. int MianMenu_start() {
  116. Main.print();
  117. switch (Main.button())
  118. {
  119. case 1:
  120. RusMenu_start();
  121. return 1;
  122. break;
  123. case 2:
  124. EngMenu_start();
  125. return 2;
  126. break;
  127. case 0:
  128. return 0;
  129. break;
  130. default:
  131. cout << " Ошибка ввода!" << endl;
  132. return -1;
  133. break;
  134. }
  135. }
  136.  
  137. int RusMenu_start() {
  138. RusMenu.init();
  139. RusMenu.print();
  140. switch (RusMenu.button()) {
  141. case 1:
  142. cin >> word;
  143. fout2 << word;
  144. fout2 << "\n";
  145. fin.close();
  146. return 1;
  147. break;
  148. case 2:
  149. //поиск через функцию find()
  150. return 2;
  151. break;
  152. case 3:
  153. while (fin.get(ch))
  154. {
  155. cout << ch;
  156. }
  157. return 3;
  158. break;
  159. case 4:
  160. cout << "https://translate.google.com/?hl=ru#view=home&op=translate&sl=auto&tl=en&text=", word; cout << endl;
  161. return 4;
  162. break;
  163. case 0:
  164. MianMenu_start();
  165. return 0;
  166. break;
  167. default:
  168. cout << " Ошибка ввода!" << endl;
  169. return -1;
  170. break;
  171. }
  172. }
  173.  
  174. int EngMenu_start() {
  175. EngMenu.init();
  176. EngMenu.print();
  177. switch (EngMenu.button()) {
  178. case 1:
  179. cin >> word;
  180. fout2 << word;
  181. fout2 << "\n";
  182. fin.close();
  183. return 1;
  184. break;
  185. case 2:
  186. //поиск через функцию find()
  187. return 2;
  188. break;
  189. case 3:
  190. while (fin.get(ch))
  191. {
  192. cout << ch;
  193. }
  194. return 3;
  195. break;
  196. case 4:
  197. cout << "https://translate.google.com/?hl=ru#view=home&op=translate&sl=auto&tl=en&text=", word; cout << endl;
  198. return 4;
  199. break;
  200. case 0:
  201. MianMenu_start();
  202. return 0;
  203. break;
  204. default:
  205. cout << " Ошибка ввода!" << endl;
  206. return -1;
  207. break;
  208. }
  209. }
  210.  
  211. int main()
  212. {
  213. setlocale(LC_ALL, "ru");
  214. SetConsoleCP(1251);
  215. SetConsoleOutputCP(1251); //кодировка вывода на консоль;
  216.  
  217. MianMenu_start();
  218.  
  219. return 0;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement