Sei sulla pagina 1di 12

//***************************************************************

//
HEADER FILE USED IN PROJECT
//****************************************************************
#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
#include<conio.h>
#include<time.h>
using namespace std;
ifstream in;
ofstream out1;
int i;
void main();
//****************************************************************
//
Question class
//****************************************************************
class question
{
int dificulty_level, q1_n1, q1_n2, q1_a, q1_tf, q2_n1, q2_n2, q2_a, q2_t
f, q3_n1, q3_n2, q3_a, q3_tf, q4_n1, q4_n2, q4_a, q4_tf, q5_n1, q5_n2, q5_a, q5_
tf;
public:

void get_data(question *&ptr)


{
char temp;
in >> temp;
in.putback(temp);
for (i = 0; !in.eof(); i++)
{
system("cls");
in
in
in
in
in

>>
>>
>>
>>
>>

ptr[i].dificulty_level;
ptr[i].q1_n1;
ptr[i].q1_n2;
ptr[i].q1_a;
ptr[i].q1_tf;

//
in
in
in
in

>>
>>
>>
>>

in >> ptr[i].dificulty_level;
ptr[i].q2_n1;
ptr[i].q2_n2;
ptr[i].q2_a;
ptr[i].q2_tf;

//
in
in
in
in

>>
>>
>>
>>

in >> ptr[i].dificulty_level;
ptr[i].q3_n1;
ptr[i].q3_n2;
ptr[i].q3_a;
ptr[i].q3_tf;

//
in
in
in
in

>>
>>
>>
>>

in >> ptr[i].dificulty_level;
ptr[i].q4_n1;
ptr[i].q4_n2;
ptr[i].q4_a;
ptr[i].q4_tf;

//
in
in
in
in

>>
>>
>>
>>

in >> ptr[i].dificulty_level;
ptr[i].q5_n1;
ptr[i].q5_n2;
ptr[i].q5_a;
ptr[i].q5_tf;

}
in.close();
}
void show_data(question *&ptr)
{
system("cls");
int j;
for (j = 0; j < i; j++)
{
cout << "Dificulty Level " << ptr[j].dificulty_level <<
endl;
cout << ptr[j].q1_n1 << " + " << ptr[j].q1_n2 << " = " <
< ptr[j].q1_a <<" Corrrect is "<<ptr[j].q1_n1 + ptr[j].q1_n2 << "\t";
if (ptr[j].q1_tf == 1){ cout << "Your answer is correct"
<< endl; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[j].q2_n1 << " - " << ptr[j].q2_n2 << " = " <
< ptr[j].q2_a <<" Correct is "<< ptr[j].q2_n1 - ptr[j].q2_n2 << "\t";
if (ptr[j].q2_tf == 1){ cout << "Your answer is correct"
<< endl; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[j].q3_n1 << " * " << ptr[j].q3_n2 << " = " <
< ptr[j].q3_a << " Correct is " << ptr[j].q3_n1 * ptr[j].q3_n2 << "\t";
if (ptr[j].q3_tf == 1){ cout << "Your answer is correct"
<< endl; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[j].q4_n1 << " / " << ptr[j].q4_n2 << " = " <
< ptr[j].q4_a << " Correct is " << ptr[j].q4_n1 / ptr[j].q4_n2 << "\t";
if (ptr[j].q4_tf == 1){ cout << "Your answer is correct"
<< endl; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[j].q5_n1 << " % " << ptr[j].q5_n2 << " = " <
< ptr[j].q5_a << " Correct is " << ptr[j].q5_n1 % ptr[j].q5_n2 << "\t";
if (ptr[j].q5_tf == 1){ cout << "Your answer is correct"
<< endl; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;

int count = 0;
if (ptr[j].q1_tf == 1){ count++; } if (ptr[j].q2_tf == 1
){ count++; } if (ptr[j].q3_tf == 1){ count++; } if (ptr[j].q4_tf == 1){ count++
; } if (ptr[j].q5_tf == 1){ count++; }
cout << "Your score is " << count << endl;
} system("pause"); main();
}
void dificulty1(question *&ptr)
{
srand(time(NULL));
ptr[i].dificulty_level = 1;
ptr[i].q1_n1 = rand() % 10; ptr[i].q1_n2 = rand() % 10;
cout << endl <<" "<< ptr[i].q1_n1 << endl << "+ " << ptr[i].q1_
n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q1_a;
if ((ptr[i].q1_n1 + ptr[i].q1_n2) == ptr[i].q1_a) { ptr[i].q1_tf
= 1; }
else { ptr[i].q1_tf = 0; }
srand(time(NULL));
ptr[i].q2_n1 = rand() % 10; ptr[i].q2_n2 = rand() % 10;
cout << endl <<" "<< ptr[i].q2_n1 << endl << "- " << ptr[i].q2_n
2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q2_a;
if ((ptr[i].q2_n1 - ptr[i].q2_n2) == ptr[i].q2_a) { ptr[i].q2_tf
= 1; }
else { ptr[i].q2_tf = 0; }
srand(time(NULL));
ptr[i].q3_n1 = rand() % 10; ptr[i].q3_n2 = rand() % 10;
cout << endl <<" "<< ptr[i].q3_n1 << endl << "* " << ptr[i].q3_n
2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q3_a;
if ((ptr[i].q3_n1 * ptr[i].q3_n2) == ptr[i].q3_a) { ptr[i].q3_tf
= 1; }
else { ptr[i].q3_tf = 0; }
srand(time(NULL));
ptr[i].q4_n1 = rand() % 10; ptr[i].q4_n2 = 0; while (ptr[i].q4_n
2 == 0){ ptr[i].q4_n2 = rand() % 10; }
cout << endl <<" "<< ptr[i].q4_n1 << endl << "/ " << ptr[i].q4_n
2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q4_a;
if ((ptr[i].q4_n1 / ptr[i].q4_n2) == ptr[i].q4_a) { ptr[i].q4_tf
= 1; }
else { ptr[i].q4_tf = 0; }

srand(time(NULL));
ptr[i].q5_n1 = rand() % 10; ptr[i].q5_n2 = 0; while (ptr[i].q5_n
2 == 0){ ptr[i].q5_n2 = rand() % 10; }
cout << endl <<" "<< ptr[i].q5_n1 << endl << "% " << ptr[i].q5_n
2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q5_a;
if ((ptr[i].q5_n1 % ptr[i].q5_n2) == ptr[i].q5_a) { ptr[i].q5_tf
= 1; }
else { ptr[i].q5_tf = 0; }
out1.open("in.txt", ios::app);
out1 << endl;
out1 << ptr[i].dificulty_level << " " << ptr[i].q1_n1
ptr[i].q1_n2 << " " << ptr[i].q1_a << " " << ptr[i].q1_tf << " ";
out1 << ptr[i].q2_n1 << " " << ptr[i].q2_n2 << " " <<
a << " " << ptr[i].q2_tf << " ";
out1 << ptr[i].q3_n1 << " " << ptr[i].q3_n2 << " " <<
a << " " << ptr[i].q3_tf << " ";
out1 << ptr[i].q4_n1 << " " << ptr[i].q4_n2 << " " <<
a << " " << ptr[i].q4_tf << " ";
out1 << ptr[i].q5_n1 << " " << ptr[i].q5_n2 << " " <<
a << " " << ptr[i].q5_tf;

<< " " <<


ptr[i].q2_
ptr[i].q3_
ptr[i].q4_
ptr[i].q5_

out1.close();
cout << "Dificulty Level " << ptr[i].dificulty_level << endl;
cout << ptr[i].q1_n1 << " + " << ptr[i].q1_n2 << " = " << ptr[i]
.q1_a << " Corrrect is " << ptr[i].q1_n1 + ptr[i].q1_n2 << "\t";
if (ptr[i].q1_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q2_n1 << " - " << ptr[i].q2_n2 << " = " << ptr[i]
.q2_a << " Correct is " << ptr[i].q2_n1 - ptr[i].q2_n2 << "\t";
if (ptr[i].q2_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q3_n1 << " * " << ptr[i].q3_n2 << " = " << ptr[i]
.q3_a << " Correct is " << ptr[i].q3_n1 * ptr[i].q3_n2 << "\t";
if (ptr[i].q3_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q4_n1 << " / " << ptr[i].q4_n2 << " = " << ptr[i]
.q4_a << " Correct is " << ptr[i].q4_n1 / ptr[i].q4_n2 << "\t";
if (ptr[i].q4_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q5_n1 << " % " << ptr[i].q5_n2 << " = " << ptr[i]
.q5_a << " Correct is " << ptr[i].q5_n1 % ptr[i].q5_n2 << "\t";
if (ptr[i].q5_tf == 1){ cout << "Your answer is correct" << endl
; }

else { cout << "Your answer is wrong" << endl; }


cout << endl;
int count = 0;
if (ptr[i].q1_tf == 1){ count++; } if (ptr[i].q2_tf == 1){ count
++; } if (ptr[i].q3_tf == 1){ count++; } if (ptr[i].q4_tf == 1){ count++; } if (
ptr[i].q5_tf == 1){ count++; }
cout << "Your score is " << count << endl;
system("pause");
main();

}
void dificulty2(question *&ptr)
{
srand(time(NULL));
ptr[i].dificulty_level = 2;
ptr[i].q1_n1 = rand() % 100; ptr[i].q1_n2 = rand() % 100;
cout << endl << " " << ptr[i].q1_n1 << endl << "+ " << ptr[i].q
1_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q1_a;
if ((ptr[i].q1_n1 + ptr[i].q1_n2) == ptr[i].q1_a) { ptr[i].q1_tf
= 1; }
else { ptr[i].q1_tf = 0; }
srand(time(NULL));
ptr[i].q2_n1 = rand() % 100; ptr[i].q2_n2 = rand() % 100;
cout << endl << " " << ptr[i].q2_n1 << endl << "- " << ptr[i].q2
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q2_a;
if ((ptr[i].q2_n1 - ptr[i].q2_n2) == ptr[i].q2_a) { ptr[i].q2_tf
= 1; }
else { ptr[i].q2_tf = 0; }
srand(time(NULL));
ptr[i].q3_n1 = rand() % 100; ptr[i].q3_n2 = rand() % 100;
cout << endl << " " << ptr[i].q3_n1 << endl << "* " << ptr[i].q3
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q3_a;
if ((ptr[i].q3_n1 * ptr[i].q3_n2) == ptr[i].q3_a) { ptr[i].q3_tf
= 1; }
else { ptr[i].q3_tf = 0; }
srand(time(NULL));
ptr[i].q4_n1 = rand() % 100; ptr[i].q4_n2 = 0; while (ptr[i].q4_
n2 == 0){ ptr[i].q4_n2 = rand() % 100; }

cout << endl << " " << ptr[i].q4_n1 << endl << "/ " << ptr[i].q4
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q4_a;
if ((ptr[i].q4_n1 / ptr[i].q4_n2) == ptr[i].q4_a) { ptr[i].q4_tf
= 1; }
else { ptr[i].q4_tf = 0; }
srand(time(NULL));
ptr[i].q5_n1 = rand() % 100; ptr[i].q5_n2 = 0; while (ptr[i].q5_
n2 == 0){ ptr[i].q5_n2 = rand() % 100; }
cout << endl << " " << ptr[i].q5_n1 << endl << "% " << ptr[i].q5
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q5_a;
if ((ptr[i].q5_n1 % ptr[i].q5_n2) == ptr[i].q5_a) { ptr[i].q5_tf
= 1; }
else { ptr[i].q5_tf = 0; }
out1.open("in.txt", ios::app);
out1 << endl;
out1 << ptr[i].dificulty_level << " " << ptr[i].q1_n1
ptr[i].q1_n2 << " " << ptr[i].q1_a << " " << ptr[i].q1_tf << " ";
out1 << ptr[i].q2_n1 << " " << ptr[i].q2_n2 << " " <<
a << " " << ptr[i].q2_tf << " ";
out1 << ptr[i].q3_n1 << " " << ptr[i].q3_n2 << " " <<
a << " " << ptr[i].q3_tf << " ";
out1 << ptr[i].q4_n1 << " " << ptr[i].q4_n2 << " " <<
a << " " << ptr[i].q4_tf << " ";
out1 << ptr[i].q5_n1 << " " << ptr[i].q5_n2 << " " <<
a << " " << ptr[i].q5_tf;

<< " " <<


ptr[i].q2_
ptr[i].q3_
ptr[i].q4_
ptr[i].q5_

out1.close();
cout << "Dificulty Level " << ptr[i].dificulty_level << endl;
cout << ptr[i].q1_n1 << " + " << ptr[i].q1_n2 << " = " << ptr[i]
.q1_a << " Corrrect is " << ptr[i].q1_n1 + ptr[i].q1_n2 << "\t";
if (ptr[i].q1_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q2_n1 << " - " << ptr[i].q2_n2 << " = " << ptr[i]
.q2_a << " Correct is " << ptr[i].q2_n1 - ptr[i].q2_n2 << "\t";
if (ptr[i].q2_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q3_n1 << " * " << ptr[i].q3_n2 << " = " << ptr[i]
.q3_a << " Correct is " << ptr[i].q3_n1 * ptr[i].q3_n2 << "\t";
if (ptr[i].q3_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q4_n1 << " / " << ptr[i].q4_n2 << " = " << ptr[i]
.q4_a << " Correct is " << ptr[i].q4_n1 / ptr[i].q4_n2 << "\t";

if (ptr[i].q4_tf == 1){ cout << "Your answer is correct" << endl


; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q5_n1 << " % " << ptr[i].q5_n2 << " = " << ptr[i]
.q5_a << " Correct is " << ptr[i].q5_n1 % ptr[i].q5_n2 << "\t";
if (ptr[i].q5_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
int count = 0;
if (ptr[i].q1_tf == 1){ count++; } if (ptr[i].q2_tf == 1){ count
++; } if (ptr[i].q3_tf == 1){ count++; } if (ptr[i].q4_tf == 1){ count++; } if (
ptr[i].q5_tf == 1){ count++; }
cout << "Your score is " << count << endl;
system("pause");

main();
}
void dificulty3(question *&ptr)
{
srand(time(NULL));
ptr[i].dificulty_level = 3;
ptr[i].q1_n1 = rand() % 1000; ptr[i].q1_n2 = rand() % 1000;
cout << endl << " " << ptr[i].q1_n1 << endl << "+ " << ptr[i].q
1_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q1_a;
if ((ptr[i].q1_n1 + ptr[i].q1_n2) == ptr[i].q1_a) { ptr[i].q1_tf
= 1; }
else { ptr[i].q1_tf = 0; }
srand(time(NULL));
ptr[i].q2_n1 = rand() % 1000; ptr[i].q2_n2 = rand() % 1000;
cout << endl << " " << ptr[i].q2_n1 << endl << "- " << ptr[i].q2
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q2_a;
if ((ptr[i].q2_n1 - ptr[i].q2_n2) == ptr[i].q2_a) { ptr[i].q2_tf
= 1; }
else { ptr[i].q2_tf = 0; }
srand(time(NULL));
ptr[i].q3_n1 = rand() % 1000; ptr[i].q3_n2 = rand() % 1000;
cout << endl << " " << ptr[i].q3_n1 << endl << "* " << ptr[i].q3
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q3_a;

if ((ptr[i].q3_n1 * ptr[i].q3_n2) == ptr[i].q3_a) { ptr[i].q3_tf


= 1; }
else { ptr[i].q3_tf = 0; }
srand(time(NULL));
ptr[i].q4_n1 = rand() % 1000; ptr[i].q4_n2 = 0; while (ptr[i].q4
_n2 == 0){ ptr[i].q4_n2 = rand() % 1000; }
cout << endl << " " << ptr[i].q4_n1 << endl << "/ " << ptr[i].q4
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q4_a;
if ((ptr[i].q4_n1 / ptr[i].q4_n2) == ptr[i].q4_a) { ptr[i].q4_tf
= 1; }
else { ptr[i].q4_tf = 0; }
srand(time(NULL));
ptr[i].q5_n1 = rand() % 1000; ptr[i].q5_n2 = 0; while (ptr[i].q5
_n2 == 0){ ptr[i].q5_n2 = rand() % 1000; }
cout << endl << " " << ptr[i].q5_n1 << endl << "% " << ptr[i].q5
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q5_a;
if ((ptr[i].q5_n1 % ptr[i].q5_n2) == ptr[i].q5_a) { ptr[i].q5_tf
= 1; }
else { ptr[i].q5_tf = 0; }
out1.open("in.txt", ios::app);
out1 << endl;
out1 << ptr[i].dificulty_level << " " << ptr[i].q1_n1
ptr[i].q1_n2 << " " << ptr[i].q1_a << " " << ptr[i].q1_tf << " ";
out1 << ptr[i].q2_n1 << " " << ptr[i].q2_n2 << " " <<
a << " " << ptr[i].q2_tf << " ";
out1 << ptr[i].q3_n1 << " " << ptr[i].q3_n2 << " " <<
a << " " << ptr[i].q3_tf << " ";
out1 << ptr[i].q4_n1 << " " << ptr[i].q4_n2 << " " <<
a << " " << ptr[i].q4_tf << " ";
out1 << ptr[i].q5_n1 << " " << ptr[i].q5_n2 << " " <<
a << " " << ptr[i].q5_tf;

<< " " <<


ptr[i].q2_
ptr[i].q3_
ptr[i].q4_
ptr[i].q5_

out1.close();
cout << "Dificulty Level " << ptr[i].dificulty_level << endl;
cout << ptr[i].q1_n1 << " + " << ptr[i].q1_n2 << " = " << ptr[i]
.q1_a << " Corrrect is " << ptr[i].q1_n1 + ptr[i].q1_n2 << "\t";
if (ptr[i].q1_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q2_n1 << " - " << ptr[i].q2_n2 << " = " << ptr[i]
.q2_a << " Correct is " << ptr[i].q2_n1 - ptr[i].q2_n2 << "\t";
if (ptr[i].q2_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;

cout << ptr[i].q3_n1 << " * " << ptr[i].q3_n2 << " = " << ptr[i]
.q3_a << " Correct is " << ptr[i].q3_n1 * ptr[i].q3_n2 << "\t";
if (ptr[i].q3_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q4_n1 << " / " << ptr[i].q4_n2 << " = " << ptr[i]
.q4_a << " Correct is " << ptr[i].q4_n1 / ptr[i].q4_n2 << "\t";
if (ptr[i].q4_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q5_n1 << " % " << ptr[i].q5_n2 << " = " << ptr[i]
.q5_a << " Correct is " << ptr[i].q5_n1 % ptr[i].q5_n2 << "\t";
if (ptr[i].q5_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
int count = 0;
if (ptr[i].q1_tf == 1){ count++; } if (ptr[i].q2_tf == 1){ count
++; } if (ptr[i].q3_tf == 1){ count++; } if (ptr[i].q4_tf == 1){ count++; } if (
ptr[i].q5_tf == 1){ count++; }
cout << "Your score is " << count << endl;
system("pause");
main();
}
void dificulty4(question *&ptr)
{
srand(time(NULL));
ptr[i].dificulty_level = 4;
ptr[i].q1_n1 = rand() % 10000; ptr[i].q1_n2 = rand() % 10000;
cout << endl << " " << ptr[i].q1_n1 << endl << "+ " << ptr[i].q
1_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q1_a;
if ((ptr[i].q1_n1 + ptr[i].q1_n2) == ptr[i].q1_a) { ptr[i].q1_tf
= 1; }
else { ptr[i].q1_tf = 0; }
srand(time(NULL));
ptr[i].q2_n1 = rand() % 10000; ptr[i].q2_n2 = rand() % 10000;
cout << endl << " " << ptr[i].q2_n1 << endl << "- " << ptr[i].q2
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q2_a;
if ((ptr[i].q2_n1 - ptr[i].q2_n2) == ptr[i].q2_a) { ptr[i].q2_tf
= 1; }
else { ptr[i].q2_tf = 0; }

srand(time(NULL));
ptr[i].q3_n1 = rand() % 10000; ptr[i].q3_n2 = rand() % 10000;
cout << endl << " " << ptr[i].q3_n1 << endl << "* " << ptr[i].q3
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q3_a;
if ((ptr[i].q3_n1 * ptr[i].q3_n2) == ptr[i].q3_a) { ptr[i].q3_tf
= 1; }
else { ptr[i].q3_tf = 0; }
srand(time(NULL));
ptr[i].q4_n1 = rand() % 10000; ptr[i].q4_n2 = 0; while (ptr[i].q
4_n2 == 0){ ptr[i].q4_n2 = rand() % 10000; }
cout << endl << " " << ptr[i].q4_n1 << endl << "/ " << ptr[i].q4
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q4_a;
if ((ptr[i].q4_n1 / ptr[i].q4_n2) == ptr[i].q4_a) { ptr[i].q4_tf
= 1; }
else { ptr[i].q4_tf = 0; }
srand(time(NULL));
ptr[i].q5_n1 = rand() % 10000; ptr[i].q5_n2 = 0; while (ptr[i].q
5_n2 == 0){ ptr[i].q5_n2 = rand() % 10000; }
cout << endl << " " << ptr[i].q5_n1 << endl << "% " << ptr[i].q5
_n2 << endl;
cout << "--------" << endl;
cin >> ptr[i].q5_a;
if ((ptr[i].q5_n1 % ptr[i].q5_n2) == ptr[i].q5_a) { ptr[i].q5_tf
= 1; }
else { ptr[i].q5_tf = 0; }
out1.open("in.txt", ios::app);
out1 << endl;
out1 << ptr[i].dificulty_level << " " << ptr[i].q1_n1
ptr[i].q1_n2 << " " << ptr[i].q1_a << " " << ptr[i].q1_tf << " ";
out1 << ptr[i].q2_n1 << " " << ptr[i].q2_n2 << " " <<
a << " " << ptr[i].q2_tf << " ";
out1 << ptr[i].q3_n1 << " " << ptr[i].q3_n2 << " " <<
a << " " << ptr[i].q3_tf << " ";
out1 << ptr[i].q4_n1 << " " << ptr[i].q4_n2 << " " <<
a << " " << ptr[i].q4_tf << " ";
out1 << ptr[i].q5_n1 << " " << ptr[i].q5_n2 << " " <<
a << " " << ptr[i].q5_tf;

<< " " <<


ptr[i].q2_
ptr[i].q3_
ptr[i].q4_
ptr[i].q5_

out1.close();
cout << "Dificulty Level " << ptr[i].dificulty_level << endl;
cout << ptr[i].q1_n1 << " + " << ptr[i].q1_n2 << " = " << ptr[i]
.q1_a << " Corrrect is " << ptr[i].q1_n1 + ptr[i].q1_n2 << "\t";
if (ptr[i].q1_tf == 1){ cout << "Your answer is correct" << endl
; }

else { cout << "Your answer is wrong" << endl; }


cout << endl;
cout << ptr[i].q2_n1 << " - " << ptr[i].q2_n2 << " = " << ptr[i]
.q2_a << " Correct is " << ptr[i].q2_n1 - ptr[i].q2_n2 << "\t";
if (ptr[i].q2_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q3_n1 << " * " << ptr[i].q3_n2 << " = " << ptr[i]
.q3_a << " Correct is " << ptr[i].q3_n1 * ptr[i].q3_n2 << "\t";
if (ptr[i].q3_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q4_n1 << " / " << ptr[i].q4_n2 << " = " << ptr[i]
.q4_a << " Correct is " << ptr[i].q4_n1 / ptr[i].q4_n2 << "\t";
if (ptr[i].q4_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
cout << ptr[i].q5_n1 << " % " << ptr[i].q5_n2 << " = " << ptr[i]
.q5_a << " Correct is " << ptr[i].q5_n1 % ptr[i].q5_n2 << "\t";
if (ptr[i].q5_tf == 1){ cout << "Your answer is correct" << endl
; }
else { cout << "Your answer is wrong" << endl; }
cout << endl;
int count = 0;
if (ptr[i].q1_tf == 1){ count++; } if (ptr[i].q2_tf == 1){ count
++; } if (ptr[i].q3_tf == 1){ count++; } if (ptr[i].q4_tf == 1){ count++; } if (
ptr[i].q5_tf == 1){ count++; }
cout << "Your score is " << count << endl;
system("pause");
main();
}
};
question o1;
string str1;
question *ptr, *o = new question[100];
//****************************************************************
//
MAIN FUNCTION
//****************************************************************
void main()
{
int d;
ptr = o;

//main function

system("color 0A");
in.open("in.txt");
//open infile++;
o1.get_data(ptr);
cout << "\t\t\tMENU\t\t\t"<<endl;
cout << "\t\t1: Show previous data"<<endl;
cout << "\t\t2: Go to question session" << endl;
cout << "\t\t3: Terminate"<<endl;
cout << "Enter (1 - 3) : "; cin >> d;
if (d == 1){ o1.show_data(ptr); }
if (d == 2){
system("cls");
system("color 3F");
again:;
cout << "Enter difficulty level : "; cin >> d;
if (d == 1){ system("color 70"); o1.dificulty1(ptr); }
else if (d == 2){ system("color 72"); o1.dificulty2(ptr); }
else if (d == 3){ system("color 73"); o1.dificulty3(ptr); }
else if (d == 4){ system("color 74"); o1.dificulty4(ptr); }
else { cout << "Wrong selection " << endl; goto again; }
}
system("pause");
}

Potrebbero piacerti anche