1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
void add_question_details(void)
{
struct question quiz;
fstream out_quiz;
char reply;
bool ok; //true false data type
out_quiz.open("E:\\pupilfiles\\questions.dat",ios::binary|ios::in|ios::out);
if ( out_quiz.good())
{
if( !out_quiz.eof())
{
out_quiz.seekg( (long) sizeof(struct question) * -1, ios::app);
out_quiz.read ((char*)& quiz, sizeof(struct question));
quiz.question_no = quiz.question_no+1;
}
else
quiz.question_no = 1;
do
{
set_up_interface("E:\\pupilfiles\\add_question.txt");
do
{
ok = true;
gotoxy(17,7); cout << "______________________________________________________________";
gotoxy(17,7); cin.getline(quiz.question,100,'\n');
if ( strlen(quiz.question) < 3)
{
ok=false;
message(30,24,"Question must be at least 3 Characters");
}
}while( ! ok);
do
{
ok =true;
gotoxy(35,10); cout << "________________________";
gotoxy(35,10); cin.getline(quiz.ansa,20,'\n');
if ( strlen(quiz.ansa) < 3)
{
ok=false;
message(30,24,"Answer A must be at least 3 Characters");
}
} while (! ok);
do
{
ok =true;
gotoxy(35,12); cout << "________________________";
gotoxy(35,12); cin.getline(quiz.ansb,20,'\n');
if ( strlen(quiz.ansb) < 3)
{
ok=false;
message(30,24,"Answer B must be at least 3 Characters");
}
} while (! ok);
do
{
ok =true;
gotoxy(35,14); cout << "________________________";
gotoxy(35,14); cin.getline(quiz.ansc,20,'\n');
if ( strlen(quiz.ansc) < 3)
{
ok=false;
message(30,24,"Answer C must be at least 3 Characters");
}
} while (! ok);
do
{
ok =true;
gotoxy(35,16); cout << "________________________";
gotoxy(35,16); cin.getline(quiz.ansd,20,'\n');
if ( strlen(quiz.ansd) < 3)
{
ok=false;
message(30,24,"Answer D must be at least 3 Characters");
}
} while (! ok);
gotoxy(53,18);cout<< "_";
gotoxy(53,18); cin.getline(quiz.right_answer,20,'\n');
quiz.right_answer[0] = toupper (quiz.right_answer[0]);
quiz.quiz_level= get_option(53,20,1,5);
out_quiz.write((char *) & quiz, sizeof(struct question));
if ( out_quiz.good())
message(30,24,"Question Written to File");
else
message(30,24,"Question NOT Written to File");
reply = again(53,22);
} while ( reply=='Y');
out_quiz.close();
}
else
message(30,24,"Cannot Open Question File");
}
|