Advertisement
Reykez

Quiz

Feb 21st, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. string temat, nick;
  10. string tresc[5];
  11. string odpA[5], odpB[5], odpC[5], odpD[5];
  12. string poprawna[5];
  13. string odpowiedz;
  14. int punkty=0;
  15.  
  16. class Question {
  17. private:
  18. string line;
  19. fstream plik;
  20. int j;
  21. public:
  22. string contents;
  23. string answer1, answer2, answer3, answer4, answerCorrect;
  24. void loadFromFile(int questionNumber) {
  25. plik.open("quiz.txt",ios::in);
  26. cout << "debug 0" << endl;
  27. j=0;
  28. if(questionNumber!=0) {
  29. while(j<=questionNumber*5+questionNumber-1) {
  30. j++;
  31. getline(plik, line);
  32. }
  33. }
  34. for(int i=0; i<=5; i++) {
  35. getline(plik,line);
  36. switch(i) {
  37. case 0: contents = line; break;
  38. case 1: answer1 = line; break;
  39. case 2: answer2 = line; break;
  40. case 3: answer3 = line; break;
  41. case 4: answer4 = line; break;
  42. case 5: answerCorrect = line; break;
  43.  
  44. default: cout<<"Lel'z, it's don't work!"<<endl;
  45. } // switch end
  46. } // loop end
  47. plik.close();
  48. } // loadFromFile end
  49. };
  50.  
  51. int main()
  52. {
  53. Question pytanie;
  54. for (int i=0; i<=4; i++)
  55. {
  56. pytanie.loadFromFile(i);
  57. cout<<endl<<pytanie.contents<<endl;
  58. cout<<"A. "<<pytanie.answer1<<endl;
  59. cout<<"B. "<<pytanie.answer2<<endl;
  60. cout<<"C. "<<pytanie.answer3<<endl;
  61. cout<<"D. "<<pytanie.answer4<<endl;
  62.  
  63. cout<<"Twoja odpowiedz: ";
  64. cin>>odpowiedz;
  65.  
  66. transform(odpowiedz.begin(), odpowiedz.end(), odpowiedz.begin(), ::tolower);
  67.  
  68. if (odpowiedz==pytanie.answerCorrect)
  69. {
  70. cout<<endl<<"Dobrze! Zdobywasz punkt!"<<endl;
  71. punkty++;
  72. }
  73. else cout<<"Zle! Brak punktu! Poprawna odpowiedz: "<<pytanie.answerCorrect<<endl;
  74.  
  75. }
  76.  
  77. cout<<"Koniec quizu. Zdobyte punkty: "<<endl<<punkty<<endl;
  78.  
  79. switch (punkty)
  80. {
  81. cout<<endl;
  82. case 5: cout<<"Dobrze ci poszlo,tak trzymaj"<<endl; break;
  83.  
  84. case 4: cout<<"Jest okej choc popelniles jeden blad"<<endl; break;
  85.  
  86. case 3: cout<<"Nie jest zle, dopracuj jeszcze pare kwestii"<<endl; break;
  87.  
  88. case 2: cout<<"Nie poszlo ci najlepiej, popracuj jeszcze i popraw test"<<endl; break;
  89.  
  90. case 1: cout<<"Jestes pewny ze potrafisz zdac ten test?"<<endl; break;
  91.  
  92. case 0: cout<<"Nie zdales, 0 punktow ;("<<endl; break;
  93.  
  94. exit(0);
  95. }
  96.  
  97. cout<<endl;
  98. cout<<"Chcesz sprobowac jeszcze raz?"<<endl;
  99.  
  100.  
  101.  
  102. return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement