Guest User

Untitled

a guest
Jun 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <windows.h>
  5. #include <cstdlib>
  6. #include <ctime>
  7. using namespace std;
  8.  
  9. struct task {
  10. string question;
  11. string option_1;
  12. string option_2;
  13. string option_3;
  14. string option_4;
  15. string r_option;
  16. };
  17.  
  18. void ignore () {
  19. string dummy;
  20. getline(cin, dummy);
  21. }
  22.  
  23. class Tasks {
  24. private:
  25. int i, quant;
  26. task t[50];
  27.  
  28. public:
  29. Tasks(int k);
  30. Tasks();
  31. };
  32.  
  33. Tasks::Tasks() {
  34. int z = 0;
  35. cout << "вы находитесь в режиме добавления заданий" << endl;
  36. cout << "сколько заданий вы хотите добавить?" << endl;
  37. cin >> z;
  38. cout << "преступаю к добавлению заданий." << endl;
  39. string quest, opt1, opt2, opt3, opt4, r_opt;
  40. ofstream output("Questions.txt", ios_base::app);
  41. for (int j = 0; j < z; j++) {
  42. cout << "введите вопрос задания: ";
  43. ignore();
  44. getline(cin, quest);
  45. cout << "введите первый вариант ответа: ";
  46. getline(cin, opt1);
  47. cout << "введите второй вариант ответа: ";
  48. getline(cin, opt2);
  49. cout << "введите третий вариант ответа: ";
  50. getline(cin, opt3);
  51. cout << "введите четвертый вариант ответа: ";
  52. getline(cin, opt4);
  53. cout << "какой вариант ответа правильный (1, 2, 3 или 4)? - ";
  54. int zero = 0;
  55. string p;
  56. while (zero < 1) {
  57. cin >> p;
  58. if (p == "1") {
  59. r_opt = opt1;
  60. ++zero;
  61. } else if (p == "2") {
  62. r_opt = opt2;
  63. ++zero;
  64. } else if (p == "3") {
  65. r_opt = opt3;
  66. ++zero;
  67. } else if (p == "4") {
  68. r_opt = opt4;
  69. ++zero;
  70. } else {
  71. cout << "такого варианта ответа нет, введите 1, 2, 3 или 4 - ";
  72. }
  73. }
  74.  
  75. cout << "проверьте правильность задания" << endl;
  76. cout << "вопрос: " << quest << endl;
  77. cout << "первый вариант ответа: " << opt1 << endl;
  78. cout << "второй вариант ответа: " << opt2 << endl;
  79. cout << "третий вариант ответа: " << opt3 << endl;
  80. cout << "четвертый вариант ответа: " << opt4 << endl;
  81. cout << "правильный ответ: " << r_opt << endl;
  82. cout << "если все верно введите любой символ." << endl;
  83. cout << "если в задании есть ошибка, введите 1." << endl;
  84. cout << "если вы хотите пропустить добавление этого задания, введите 0" << endl;
  85. string yes;
  86. cin >> yes;
  87. if (yes == "1") {
  88. cout << "напишите задание еще раз, исправив ошибку" << endl;
  89. --j;
  90. } else if(yes == "0") {
  91. } else {
  92. ignore();
  93. output << quest << endl;
  94. output << opt1 << endl;
  95. output << opt2 << endl;
  96. output << opt3 << endl;
  97. output << opt4 << endl;
  98. output << r_opt << endl;
  99. cout << "задание добавлено" << endl;
  100. }
  101. }
  102. cout << "все задания добавлены" << endl;
  103. }
  104.  
  105. Tasks::Tasks(int pp) {
  106. i = 0;
  107. ifstream input("Questions.txt");
  108. while (!input.eof()) {
  109. getline(input, t[i].question);
  110. getline(input, t[i].option_1);
  111. getline(input, t[i].option_2);
  112. getline(input, t[i].option_3);
  113. getline(input, t[i].option_4);
  114. getline(input, t[i].r_option);
  115. i++;
  116. }
  117.  
  118. if ( i - 1 < 10 ) {
  119. quant = i - 1;
  120. } else {
  121. quant = 10;
  122. }
  123.  
  124. cout << "правила игры: " << endl;
  125. cout << "1) вам нужно ответить на " << quant <<" вопросов." << endl;
  126. cout << "2) чтобы ответить на вопрос нужно просто ввести верный, по вашему мнению, вариант ответа из четырех предложенных." << endl;
  127. cout << "если вы готовы, нажмите любую клавишу, и игра начнется" << endl;
  128. system("pause");
  129.  
  130. quant = 0;
  131. if ( i - 1 < 10 ) {
  132. quant = i - 1;
  133. } else {
  134. quant = 10;
  135. }
  136.  
  137. int s = 0;
  138. cout << "игра началась!" << endl;
  139. int u = i - 1;
  140. int q;
  141. srand(time(NULL));
  142. int random[u];
  143. for (q = 0; q < u; q++) {
  144. random[q] = q;
  145. }
  146. int j, k;
  147.  
  148. for (q = u; q > 0; q--) {
  149. j = rand() % q;
  150. k = random[q - 1];
  151. random[q - 1] = random[j];
  152. random[j] = k;
  153. }
  154.  
  155. string ans[i];
  156. string r;
  157. int n;
  158. for(n = 0; n < quant; n++) {
  159. cout << "вопрос № " << n+1 << ":" << endl;
  160. cout << t[random[n]].question << endl;
  161. cout << "а) " << t[random[n]].option_1 << endl;
  162. cout << "б) " << t[random[n]].option_2 << endl;
  163. cout << "в) " << t[random[n]].option_3 << endl;
  164. cout << "г) " << t[random[n]].option_4 << endl;
  165. cout << "введите ответ: ";
  166. cin >> r;
  167. ans [random[n]] = r;
  168. if (r == t[random[n]].r_option){
  169. s++;
  170. } else {}
  171. }
  172. cout << "игра окончена!" << endl;
  173. cout << "количество верных ответов: " << s << " из " << quant << endl;
  174. cout << "правильные ответы (ваши ответы):" << endl;
  175. for (n = 0; n < quant; n++) {
  176. cout << "вопрос №" << n + 1 <<" - " << t[random[n]].r_option << " (" << ans[random[n]] << ")" << endl;
  177. }
  178. }
  179.  
  180. int main() {
  181. setlocale (LC_ALL, "Russian");
  182. SetConsoleCP(1251);
  183. SetConsoleOutputCP(1251);
  184. string s;
  185. cout << "если вы хотите добавить новое задание, введите 1" << endl;
  186. cout << "иначе введите любой другой символ" << endl;
  187. cin >> s;
  188. if (s == "1") {
  189. Tasks start;
  190. }
  191. Tasks (0);
  192. cout << "спасибо за игру!" << endl;
  193. system("pause");
  194. return 0;
  195. }
Add Comment
Please, Sign In to add comment