Created
December 15, 2017 19:02
-
-
Save sienki-jenki/10d3e8507e2badaa24826082bb9146fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "pytanie.h" | |
using namespace std; | |
int main() | |
{ | |
Pytanie p[5]; | |
int suma=0; | |
for(int i=0; i<=4;i++){ | |
p[i].nr_pytania=i+1; | |
p[i].wczytaj(); | |
p[i].zadaj(); | |
p[i].sprawdz(); | |
suma+=p[i].punkt; | |
} | |
cout<<"Koniec quizu! punkty = "<<suma; | |
return 0; | |
} | |
\\\\\\\\\ | |
#include <iostream> | |
using namespace std; | |
class Pytanie{ | |
public: | |
string tresc; | |
string a,b,c,d; | |
int nr_pytania; | |
string poprawna; | |
string odpowiedz; | |
int punkt; | |
void wczytaj(); | |
void zadaj(); | |
void sprawdz(); | |
}; | |
/////////////////// | |
#include <iostream> | |
#include "pytanie.h" | |
#include <fstream> | |
#include <cstdlib> | |
using namespace std; | |
void Pytanie::wczytaj(){ | |
fstream plik; | |
plik.open("quiz.txt",ios::in); | |
if(plik.good()==false){ | |
cout<<"Blad podczas otwierania pliku"<<endl; | |
exit(0); | |
} | |
int nr_lini=(nr_pytania-1)*6+1; | |
int aktualny_nr=1; | |
string linia; | |
while(getline(plik,linia)){ | |
if(aktualny_nr==nr_lini){ | |
tresc=linia; | |
} | |
if(aktualny_nr==nr_lini+1){ | |
a=linia; | |
} | |
if(aktualny_nr==nr_lini+2){ | |
b=linia; | |
} | |
if(aktualny_nr==nr_lini+3){ | |
c=linia; | |
} | |
if(aktualny_nr==nr_lini+4){ | |
d=linia; | |
} | |
if(aktualny_nr==nr_lini+5){ | |
poprawna=linia; | |
} | |
aktualny_nr++; | |
} | |
plik.close(); | |
} | |
void Pytanie::zadaj(){ | |
cout<<endl<<tresc<<endl; | |
cout<<a<<endl; | |
cout<<b<<endl; | |
cout<<c<<endl; | |
cout<<d<<endl; | |
cout<<"=================="<<endl; | |
cout<<endl<<"Odpowiedz: "; | |
cin>>odpowiedz; | |
} | |
void Pytanie::sprawdz(){ | |
if(odpowiedz==poprawna){ | |
punkt=1; | |
} | |
else{ | |
punkt=0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment