Advertisement
Reykez

Questions 2

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