Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- #include <algorithm>
- #include <string>
- using namespace std;
- class Question {
- private:
- string line;
- fstream plik;
- int j;
- public:
- string contents;
- string answer1, answer2, answer3, answer4, answerCorrect;
- void loadFromFile(int questionNumber) {
- plik.open("quiz.txt",ios::in);
- cout << "debug 0" << endl;
- j=0;
- if(questionNumber!=0) {
- while(j<=questionNumber*5+questionNumber-1) {
- j++;
- getline(plik, line);
- }
- }
- for(int i=0; i<=5; i++) {
- getline(plik,line);
- switch(i) {
- case 0: contents = line; break;
- case 1: answer1 = line; break;
- case 2: answer2 = line; break;
- case 3: answer3 = line; break;
- case 4: answer4 = line; break;
- case 5: answerCorrect = line; break;
- default: cout<<"Lel'z, it's don't work!"<<endl;
- } // switch end
- } // loop end
- plik.close();
- } // loadFromFile end
- };
- int main()
- {
- string odpowiedz;
- int punkty;
- Question pytanie;
- for (int i=0; i<=4; i++)
- {
- pytanie.loadFromFile(i);
- cout<<endl<<pytanie.contents<<endl;
- cout<<"A. "<<pytanie.answer1<<endl;
- cout<<"B. "<<pytanie.answer2<<endl;
- cout<<"C. "<<pytanie.answer3<<endl;
- cout<<"D. "<<pytanie.answer4<<endl;
- cout<<"Twoja odpowiedz: ";
- cin>>odpowiedz;
- transform(odpowiedz.begin(), odpowiedz.end(), odpowiedz.begin(), ::tolower);
- if (odpowiedz==pytanie.answerCorrect)
- {
- cout<<endl<<"Dobrze! Zdobywasz punkt!"<<endl;
- punkty++;
- }
- else cout<<"Zle! Brak punktu! Poprawna odpowiedz: "<<pytanie.answerCorrect<<endl;
- }
- cout<<"Koniec quizu. Zdobyte punkty: "<<endl<<punkty<<endl;
- switch (punkty)
- {
- cout<<endl;
- case 5: cout<<"Dobrze ci poszlo,tak trzymaj"<<endl; break;
- case 4: cout<<"Jest okej choc popelniles jeden blad"<<endl; break;
- case 3: cout<<"Nie jest zle, dopracuj jeszcze pare kwestii"<<endl; break;
- case 2: cout<<"Nie poszlo ci najlepiej, popracuj jeszcze i popraw test"<<endl; break;
- case 1: cout<<"Jestes pewny ze potrafisz zdac ten test?"<<endl; break;
- case 0: cout<<"Nie zdales, 0 punktow ;("<<endl; break;
- exit(0);
- }
- cout<<endl;
- cout<<"Chcesz sprobowac jeszcze raz?"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement