Quiz-J.G

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.8 kB
4
Indexable
Never
#include <iostream>

#include <string>

#include <stdlib.h>

using namespace std;

const int QUSTION_COUNT = 3;
struct sQuestions {
  string data;
  string a, b, c;
  char correct;
};

sQuestions data[QUSTION_COUNT] = {
  {
    "Jaki dzwiek wydaje kot?",
    "miau",
    "hau",
    "muu",
    'a'
  },
  {
    "Najwazniejsza osoba w Polsce?",
    "premier",
    "prezes",
    "prezydent",
    'c'
  },
  {
    "Ktora godzina to polnoc?",
    "11:00",
    "12:00",
    "0:00",
    'c'
  }
};

class Question {
  private:
    sQuestions currentQuestion;

  char getAnswer() {
    char answer;
    cout << "Podaj odp:" << endl;
    cin >> answer;
    return answer;
  }

  public:
    bool validateAnswer() {
      return getAnswer() == currentQuestion.correct;
    }

  void displayQuestion(int index) {
    cout << to_string(index + 1) + ") " << currentQuestion.data << endl;
    cout << " a) " + currentQuestion.a << endl;
    cout << " b) " + currentQuestion.b << endl;
    cout << " c) " + currentQuestion.c << endl;
  }

  Question(sQuestions question) {
    currentQuestion = question;
  }

};

class Quiz {
  public:
    void start() {
      showQuestions();
      showResult();
    }

  private:
    char selectedOption;
  int points;

  void showQuestions() {
    cout << "Quiz: " << endl;
    for (int i = 0; i < QUSTION_COUNT; i++) {
      Question question = Question(data[i]);
      question.displayQuestion(i);
      incrementPointIfAnswerValid(question.validateAnswer());
    }
  }

  void showResult() {
    cout << "Gratulacje!!! " << endl;
    cout << "Twój wynik to: " << points;
  }

  void incrementPointIfAnswerValid(bool isValid) {
    if (isValid) {
      points++;
    }
  }

};

int main() {
  Quiz quiz = Quiz();
  quiz.start();
  return 0;
}