Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <windows.h>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- struct task {
- string question;
- string option_1;
- string option_2;
- string option_3;
- string option_4;
- string r_option;
- };
- void ignore () {
- string dummy;
- getline(cin, dummy);
- }
- class Tasks {
- private:
- int i, quant;
- task t[50];
- public:
- Tasks(int k);
- Tasks();
- };
- Tasks::Tasks() {
- int z = 0;
- cout << "вы находитесь в режиме добавления заданий" << endl;
- cout << "сколько заданий вы хотите добавить?" << endl;
- cin >> z;
- cout << "преступаю к добавлению заданий." << endl;
- string quest, opt1, opt2, opt3, opt4, r_opt;
- ofstream output("Questions.txt", ios_base::app);
- for (int j = 0; j < z; j++) {
- cout << "введите вопрос задания: ";
- ignore();
- getline(cin, quest);
- cout << "введите первый вариант ответа: ";
- getline(cin, opt1);
- cout << "введите второй вариант ответа: ";
- getline(cin, opt2);
- cout << "введите третий вариант ответа: ";
- getline(cin, opt3);
- cout << "введите четвертый вариант ответа: ";
- getline(cin, opt4);
- cout << "какой вариант ответа правильный (1, 2, 3 или 4)? - ";
- int zero = 0;
- string p;
- while (zero < 1) {
- cin >> p;
- if (p == "1") {
- r_opt = opt1;
- ++zero;
- } else if (p == "2") {
- r_opt = opt2;
- ++zero;
- } else if (p == "3") {
- r_opt = opt3;
- ++zero;
- } else if (p == "4") {
- r_opt = opt4;
- ++zero;
- } else {
- cout << "такого варианта ответа нет, введите 1, 2, 3 или 4 - ";
- }
- }
- cout << "проверьте правильность задания" << endl;
- cout << "вопрос: " << quest << endl;
- cout << "первый вариант ответа: " << opt1 << endl;
- cout << "второй вариант ответа: " << opt2 << endl;
- cout << "третий вариант ответа: " << opt3 << endl;
- cout << "четвертый вариант ответа: " << opt4 << endl;
- cout << "правильный ответ: " << r_opt << endl;
- cout << "если все верно введите любой символ." << endl;
- cout << "если в задании есть ошибка, введите 1." << endl;
- cout << "если вы хотите пропустить добавление этого задания, введите 0" << endl;
- string yes;
- cin >> yes;
- if (yes == "1") {
- cout << "напишите задание еще раз, исправив ошибку" << endl;
- --j;
- } else if(yes == "0") {
- } else {
- ignore();
- output << quest << endl;
- output << opt1 << endl;
- output << opt2 << endl;
- output << opt3 << endl;
- output << opt4 << endl;
- output << r_opt << endl;
- cout << "задание добавлено" << endl;
- }
- }
- cout << "все задания добавлены" << endl;
- }
- Tasks::Tasks(int pp) {
- i = 0;
- ifstream input("Questions.txt");
- while (!input.eof()) {
- getline(input, t[i].question);
- getline(input, t[i].option_1);
- getline(input, t[i].option_2);
- getline(input, t[i].option_3);
- getline(input, t[i].option_4);
- getline(input, t[i].r_option);
- i++;
- }
- if ( i - 1 < 10 ) {
- quant = i - 1;
- } else {
- quant = 10;
- }
- cout << "правила игры: " << endl;
- cout << "1) вам нужно ответить на " << quant <<" вопросов." << endl;
- cout << "2) чтобы ответить на вопрос нужно просто ввести верный, по вашему мнению, вариант ответа из четырех предложенных." << endl;
- cout << "если вы готовы, нажмите любую клавишу, и игра начнется" << endl;
- system("pause");
- quant = 0;
- if ( i - 1 < 10 ) {
- quant = i - 1;
- } else {
- quant = 10;
- }
- int s = 0;
- cout << "игра началась!" << endl;
- int u = i - 1;
- int q;
- srand(time(NULL));
- int random[u];
- for (q = 0; q < u; q++) {
- random[q] = q;
- }
- int j, k;
- for (q = u; q > 0; q--) {
- j = rand() % q;
- k = random[q - 1];
- random[q - 1] = random[j];
- random[j] = k;
- }
- string ans[i];
- string r;
- int n;
- for(n = 0; n < quant; n++) {
- cout << "вопрос № " << n+1 << ":" << endl;
- cout << t[random[n]].question << endl;
- cout << "а) " << t[random[n]].option_1 << endl;
- cout << "б) " << t[random[n]].option_2 << endl;
- cout << "в) " << t[random[n]].option_3 << endl;
- cout << "г) " << t[random[n]].option_4 << endl;
- cout << "введите ответ: ";
- cin >> r;
- ans [random[n]] = r;
- if (r == t[random[n]].r_option){
- s++;
- } else {}
- }
- cout << "игра окончена!" << endl;
- cout << "количество верных ответов: " << s << " из " << quant << endl;
- cout << "правильные ответы (ваши ответы):" << endl;
- for (n = 0; n < quant; n++) {
- cout << "вопрос №" << n + 1 <<" - " << t[random[n]].r_option << " (" << ans[random[n]] << ")" << endl;
- }
- }
- int main() {
- setlocale (LC_ALL, "Russian");
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- string s;
- cout << "если вы хотите добавить новое задание, введите 1" << endl;
- cout << "иначе введите любой другой символ" << endl;
- cin >> s;
- if (s == "1") {
- Tasks start;
- }
- Tasks (0);
- cout << "спасибо за игру!" << endl;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment