SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Made By :-

Sushil Kumar Mishra (05311502809)

Of ECE-I




                       1|Page
INTRODUCTION
The Online Quiz is basically for the school and college goers, where a user can give an online test for a
subject(s). According to the number of marks his/her evaluation has to be done. Where the students at large,
this Online Quiz scrutinize the universities/Institutions problems at once and produce a quick response in a
limited time.
It can be further extended to any organization or company who want to conduct the examination using
online.
The project keeps four different data files such as :
 􀂈 Computer.dat
 􀂈 Maths.dat
 􀂈 Science.data
 􀂈 General.dat
All the above files have the common fields, but the records are appended according to the examination
option.
ques_no : Question number
ques : Name of the question
ans1 : First answer of the question
ans2 : Second answer of the question
ans3 : Third answer of the question
sol : Correct answer of the question
The Online Quiz system displays the result immediately after a quiz is completed. The Online Quiz system
keeps track of the following options for maintaining its database and quiz.
QUIZ
OPTIONS
PLAY
ADD QUESTIONS
EDIT
QUIT
PLAY : This option opens a sub-menu as :
SUB – MENU
COMPUTER
MATHEMATICS
SCIENCE
GENERAL
(Uparrow DownArrow)=Move <ENTER> = Select <ESC>Exit
From the above menus when you select any one option, you will be used to enter your name. After
entering your name, it will display the question one-by-one and you have to give the answer in a specified time
limit. If the time limit is over, it will display the next question and zero will be added to your score, otherwise,
your score will be incremented by one. In the end, you will see a score board as shown in Fig. 1.9. Similarly, you
can attend all the sub-menu options, as required by you.
ADD QUESTIONS : In this option, you can add different questions to your previous sub-menu options. For
example, you select COMPUTER, you will see a screen for adding a question with its question number and
question details.
Here, the question number generates automatically. After entering three answers and its right solution,
you will be asked for updating the database for next quiz.
EDIT : In this option, you can delete, modify your previously entered questions as required. Here, all the
process will transact through the question number.
Class Description
- lines. It controls function related to draw horizontal and vertical line and boxes.
- menu. It control the overall functioning of Online Quiz project. It displays all menus and submenus.
- quiz. It controls overall function related to quiz, like adding, deleting or modifying questions
in the database.

                                                                                                            2|Page
SOURCE CODE
//**********************************************************
// PROJECT COMPUTER QUIZ
//**********************************************************
//**********************************************************
//        INCLUDED HEADER FILES
//**********************************************************
#include <iostream.h>
#include <conio.h>
#include <dos.h>
#include <string.h>
#include <fstream.h>
#include <process.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
//**********************************************************
//        CLASS NAME : lines
//        DETAILS : IT CONTROLS FUNCTIONS RELATED TO DRAW
//            LINES, BOXES, ETC.
//**********************************************************
class lines
{public :
                 void line_hor (int, int, int, char) ;
                 void line_ver (int, int, int, char) ;
                 void box (int,int,int,int,char) ;
};
//***************************************************************
//        CLASS NAME : menu
//        DETAILS : IT CONTROLS OVER ALL FUNCTIONING OF PROJECT
//***************************************************************
class menu
{public :
                 void main_menu(void) ;
                 char *sub_menu(void) ;
                 void start(void) ;
private :
                 void edit_menu(void) ;
};

                                                                    3|Page
//**********************************************************
//        CLASS NAME : quiz
//        DETAILS : IT CONTROLS OVER ALL THE FUNCTIONS
//             RELATED TO QUIZ
//**********************************************************
class quiz
{public :
                   void play(char filename[13]) ;
                   void add(char filename[13]) ;
                   void deletion(char filename[13]) ;
                   void modify(char filename[13]) ;
private :
                   void delete_record(char filename[13], int) ;
                   void modify_record(char filename[13], int) ;
                   void display_score(char name[20], int, int) ;
                   int recordno(char filename[13], int) ;
                   int record_count(char filename[13]) ;
                   int found_record(char filename[13], int) ;
                   void display_record(char filename[13], int) ;
                   int ques_no ;
                   char ques[60] ;
                   char ans1[50] ;
                   char ans2[50] ;
                   char ans3[50] ;
                   char sol ;
};
//**********************************************************
//        CLASS NAME : lines
//        FUNCTION NAME : line_hor
//        DETAILS      : IT ACCEPTS THE ROWS AND COLUMNS AND
//                                   DRAW THE HORIZONTAL LINE
//**********************************************************
void lines :: line_hor(int column1, int column2, int row, char c)
{ for ( column1; column1<=column2; column1++ )
  {
    gotoxy(column1,row) ;
    cout <<c ;
  }
}
//**********************************************************
//        CLASS NAME : lines
//        FUNCTION NAME : line_ver

                                                                    4|Page
//        DETAILS      : IT ACCEPTS THE ROWS AND COLUMNS AND
//                                  DRAW THE VERTICAL LINE
//**********************************************************
void lines :: line_ver(int row1, int row2, int column, char c)
{ for ( row1; row1<=row2; row1++ )
  { gotoxy(column,row1) ;
     cout <<c ;
  }}
//**********************************************************
//        CLASS NAME : lines
//        FUNCTION NAME : box
//        DETAILS      : IT ACCEPTS THE ROWS AND COLUMNS AND
//                                  DRAW THE BOX
//**********************************************************
void lines :: box(int column1, int row1, int column2, int row2, char c)
{ char ch=218 ;
  char c1, c2, c3, c4 ;
  char l1=196, l2=179 ;
  if (c == ch)
  {       c1 = 218 ;
          c2 = 191 ;
          c3 = 192 ;
          c4 = 217 ;
          l1 = 196 ;
          l2 = 179 ;
  }
else
  {       c1 = c ;
          c2 = c ;
          c3 = c ;
          c4 = c ;
          l1 = c ;
          l2 = c ; }
  gotoxy(column1,row1) ;
  cout <<c1 ;
  gotoxy(column2,row1) ;
  cout <<c2 ;
  gotoxy(column1,row2) ;
  cout <<c3 ;
  gotoxy(column2,row2) ;
  cout <<c4 ;
  column1++ ;

                                                                          5|Page
column2-- ;
   line_hor(column1,column2,row1,l1) ;
line_hor(column1,column2,row2,l1) ;
   column1-- ;
   column2++ ;
   row1++ ;
   row2-- ;
   line_ver(row1,row2,column1,l2) ;
   line_ver(row1,row2,column2,l2) ; }
//**********************************************************
//        CLASS NAME : menu
//        FUNCTION NAME : start
//        DETAILS      : IT CREATES THE OPENING SCREEN
//**********************************************************
void menu :: start(void)
{ lines line ;
   textmode(C80) ;
   clrscr() ;
   textbackground(LIGHTCYAN);
   textcolor(BLACK) ;
   clrscr() ;
   gotoxy(8,12) ;
   cout <<"C O M P U T E R" ;
   gotoxy(25,12) ;
   cout <<"Q U I Z" ;
   line.box(4,10,36,14,21) ;
   gotoxy(5,21);
   cout<<"MADE BY :";
   gotoxy(5,22);
   cout<<"SUSHIL MISHRA,SACHIN MISHRA(ECE-1)";
 line.box(2,19,40,24,219);
   gotoxy(4,10);
   getch() ;
   textbackground(BLACK) ;
   textcolor(LIGHTGRAY) ;
   clrscr() ; }
//**********************************************************
//        CLASS NAME : menu
//        FUNCTION NAME : main_menu
//        DETAILS      : IT CREATES THE MAIN MENU TO CONTROL
//              ALL THE FUNCTIONS
//**********************************************************

                                                               6|Page
void menu :: main_menu(void)
{ lines line ;
  textmode(C80) ;
  clrscr ;
  int valid ;
  int n = 4 ;
  int x = 14 ;
  char ch1, ch2 ;
  char chr1=219, chr=175 ;
  do
  {       line.box (1,1,39,25,219) ;
          line.line_hor(9,31,6,196) ;
          line.box (8,3,32,20,218) ;
          char c1=24, c2=25 ;
          gotoxy(3,24) ;
          cout <<c1 ;
          cout <<c2 ;
          cout <<"=Move <ENTER>=Select <ESC>=Exit" ;
          gotoxy(13,5) ;
          cout <<chr1 ;
          textbackground(WHITE) ;
          textcolor(BLACK) ;
          gotoxy(14,5) ;
          cprintf("Q U I Z ") ;
          textbackground(BLACK) ;
          textcolor(LIGHTGRAY) ;
          gotoxy(14,8) ;
          cout <<"OPTIONS" ;
          gotoxy(14,9) ;
          cout <<"-------" ;
          gotoxy(14,11) ;
          cout <<"PLAY" ;
          gotoxy(14,12) ;
          cout <<"ADD QUESTIONS" ;
          gotoxy(14,13) ;
          cout <<"EDIT" ;
          gotoxy(14,14) ;
          cout <<"QUIT" ;
          gotoxy(10,x) ;
          cout <<chr ;
          gotoxy(13,5) ;
          do

                                                       7|Page
{ do
  { do
   {
         ch1 = getch() ;
         if ( ch1 == 27 )
                   { textmode(C80) ;
                    clrscr() ;
                    exit(0) ;
                    } } while (( ch1 != 0 ) && ( ch1 != 13 )) ;
                   if ( ch1 != 13 )
                   { do
                     { ch2 = getch() ;
                      if ( ch2 == 27 )
                                       { textmode(C80) ;
                                                clrscr() ;
                                                exit(0) ; }
                              } while (( ch2 != 72 ) && ( ch2 != 80 )  && ( ch2 != 13 )) ;
                   }
} while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ;
         if (( ch1 == 0 ) && ( ch2 == 80 ))
         { gotoxy(10,x) ;
                   cout <<" " ;
                   if (n == 4)
                   {n=1;
                              x=x-3;}
                   else
                   {          n=n+1;
                              x=x+1;}
                   gotoxy(10,x) ;
                   cout <<chr ;
                   gotoxy(13,5) ;
                   sound(200) ;
                   delay(30) ;
                   nosound() ; }
         if (( ch1 == 0 ) && ( ch2 == 72 ))
         { gotoxy(10,x) ;
                   cout <<" " ;
                   if ( n == 1 )
                   {n=4;
                              x = x + 3 ;}
                   else
                   {n=n-1;

                                                                                               8|Page
x=x-1;
                              }gotoxy(10,x) ;
                              cout <<chr ;
                              gotoxy(13,5) ;
                              sound(200) ;
                              delay(30) ;
                              nosound() ; }
          } while (( ch1 != 13 ) && ( ch2 != 13 )) ;
          if (n == 1)
          { char filename[13] ;
                    strcpy(filename,sub_menu()) ;
                    if (strcmp(filename,"null"))
                    { quiz q ;
                              q.play(filename) ;
                              clrscr() ; } }
          if (n == 2)
          { char filename[13] ;
                    strcpy(filename,sub_menu()) ;
                    if (strcmp(filename,"null"))
                    { textmode(C80) ;
                              clrscr() ;
                              quiz q ;
                              q.add(filename) ;
                              textmode(C40) ;
                              clrscr() ;} }
          if (n == 3)
                    edit_menu() ;
  } while ( n != 4 ) ;
  textmode(C80) ;
  clrscr() ; }
//**********************************************************
//        CLASS NAME : menu
//        FUNCTION NAME : edit_menu
//        DETAILS        : IT CREATES THE EDIT MAIN MENU
//**********************************************************
void menu :: edit_menu(void)
{ lines line ;
  int valid ;
  static int n = 3 ;
  static int x = 19 ;
  char ch1, ch2 ;
  char chr1=219, chr=175 ;

                                                               9|Page
do
{    line.box(19,14,31,20,218) ;
     gotoxy(21,15) ;
     cout <<chr1 ;
     textbackground(WHITE) ;
     textcolor(BLACK) ;
     gotoxy(22,15) ;
     cprintf("E D I T ") ;
     textbackground(BLACK) ;
     textcolor(LIGHTGRAY) ;
     gotoxy(23,17) ;
     cout <<"DELETE" ;
     gotoxy(23,18) ;
     cout <<"MODIFY" ;
     gotoxy(23,19) ;
     cout <<"RETURN" ;
     gotoxy(20,x) ;
     cout <<chr ;
     gotoxy(21,15) ;
     do
     { do
              { do
                       { ch1 = getch() ;
                                 if ( ch1 == 27 )
                                 {         gotoxy(1,15) ; clreol() ;
                                           gotoxy(1,17) ; clreol() ;
                                           gotoxy(1,18) ; clreol() ;
                                           gotoxy(1,19) ; clreol() ;
                                           gotoxy(1,20) ; clreol() ;
                                           gotoxy(19,14) ; clreol() ;
                                           return ; }
                       } while (( ch1 != 0 ) && ( ch1 != 13 )) ;
                       if ( ch1 != 13 )
                       { do
                                 {         ch2 = getch() ;
                                           if ( ch2 == 27 )
                                           {         gotoxy(1,15) ; clreol() ;
                                                     gotoxy(1,17) ; clreol() ;
                                                     gotoxy(1,18) ; clreol() ;
                                                     gotoxy(1,19) ; clreol() ;
                                                     gotoxy(1,20) ; clreol() ;
                                                     gotoxy(19,14) ; clreol() ;

                                                                                  10 | P a g e
return ;
                                     } } while (( ch2 != 72 ) && ( ch2 != 80 ) && ( ch2 != 13 )) ;
}} while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ;
         if (( ch1 == 0 ) && ( ch2 == 80 ))
         {         gotoxy(20,x) ;
                   cout <<" " ;
                   if (n == 3)
                   {          n=1;
                              x=x-2;          }
                   else
                   {          n=n+1;
                              x=x+1;          }
                   gotoxy(20,x) ;
                   cout <<chr ;
                   gotoxy(21,15) ;
                   sound(200) ;
                   delay(30) ;
                   nosound() ;       }
         if (( ch1 == 0 ) && ( ch2 == 72 ))
         {         gotoxy(20,x) ;
                   cout <<" " ;
                   if ( n == 1 )
                   {          n=3;
                              x=x+2;}
                   else
                   {        n=n-1;
                              x=x-1;}
                   gotoxy(20,x) ;
                   cout <<chr ;
                   gotoxy(21,15) ;
                   sound(200) ;
                   delay(30) ;
                   nosound() ; }
} while (( ch1 != 13 ) && ( ch2 != 13 )) ;
if (n == 1)
{        char filename[13] ;
         strcpy(filename,sub_menu()) ;
         if (strcmp(filename,"null"))
         {         textmode(C80) ;
                   clrscr() ;
                   quiz q ;
                   q.deletion(filename) ;

                                                                                             11 | P a g e
textmode(C40) ;
                          clrscr() ;
      return ;            }
                 clrscr() ;
                 return ;}
          else
          if (n == 2)
          {        char filename[13] ;
                   strcpy(filename,sub_menu()) ;
                   if (strcmp(filename,"null"))
                   {         textmode(C80) ;
                              clrscr() ;
                              quiz q ;
                              q.modify(filename) ;
                              textmode(C40) ;
                              clrscr() ;
                              return ; }
                   clrscr() ;
                   return ; } } while ( n != 3 ) ;
  gotoxy(1,15) ; clreol() ;
  gotoxy(1,17) ; clreol() ;
  gotoxy(1,18) ; clreol() ;
  gotoxy(1,19) ; clreol() ;
  gotoxy(1,20) ; clreol() ;
  gotoxy(19,14) ; clreol() ;}
//**********************************************************
//        CLASS NAME : menu
//        FUNCTION NAME : sub_menu
//        DETAILS       : IT CREATES THE SUB MAIN MENU AND
//              RETURN FILE NAME
//**********************************************************
char *menu :: sub_menu(void)
{ lines line ;
  clrscr() ;
  int valid ;
  static int n = 1 ;
  static int x = 10 ;
  char ch1, ch2 ;
  char chr1=219, chr=175 ;
  line.box(1,1,39,25,219) ;
  line.line_hor(2,38,23,196) ;
  char c1=24, c2=25 ;

                                                               12 | P a g e
gotoxy(3,24) ;
 cout <<c1 ;
cout <<c2 ;
 cout <<"=Move <ENTER>=Select <ESC>=Exit" ;
 gotoxy(13,6) ;
 cout <<chr1 ;
 textbackground(WHITE) ;
 textcolor(BLACK) ;
 gotoxy(14,6) ;
 cprintf("S U B - M E N U ") ;
 textbackground(BLACK) ;
 textcolor(LIGHTGRAY) ;
 line.box(11,5,31,7,218) ;
 gotoxy(14,10) ;
 cout <<"COMPUTERS" ;
 gotoxy(14,12) ;
 cout <<"MATHEMATICS" ;
 gotoxy(14,14) ;
 cout <<"SCIENCE" ;
 gotoxy(14,16) ;
 cout <<"GENERAL" ;
 gotoxy(14,18) ;
 cout <<"RETURN" ;
 gotoxy(12,x) ;
 cout <<chr ;
 gotoxy(13,6) ;
 do
 {      do
        {        do
                 { ch1 = getch() ;
                           if ( ch1 == 27 )
                           {        clrscr() ;
                                     return("null") ; }
                 } while (( ch1 != 0 ) && ( ch1 != 13 )) ;
                 if ( ch1 != 13 )
                 { do
                           { ch2 = getch() ;
                                     if ( ch2 == 27 )
                                     { clrscr() ;
                                               return("null") ; }
                           } while (( ch2 != 72 ) && ( ch2 != 80 )   && ( ch2 != 13 )) ;
                 }

                                                                                           13 | P a g e
} while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ;
        if (( ch1 == 0 ) && ( ch2 == 80 ))
        { gotoxy(12,x) ;
                  cout <<" " ;
                  if (n == 5)
                  {         n=1;
                            x=x-8;}
                  else
                  {        n=n+1;
                            x = x + 2 ;}
                  gotoxy(12,x) ;
                  cout <<chr ;
                  gotoxy(13,6) ;
                  sound(200) ;
                  delay(30) ;
                  nosound() ; }
        if (( ch1 == 0 ) && ( ch2 == 72 ))
        {         gotoxy(12,x) ;
                  cout <<" " ;
                  if ( n == 1 )
                  {         n=5;
                            x = x + 8 ;}
                  else
                  {         n=n-1;
                            x = x - 2 ;}
                  gotoxy(12,x) ;
                  cout <<chr ;
                  gotoxy(13,6) ;
                  sound(200) ;
                  delay(30) ;
                  nosound() ;         }
} while (( ch1 != 13 ) && ( ch2 != 13 )) ;
clrscr() ;
if (n == 1)
        return("computer.dat") ;
else
if (n == 2)
        return("maths.dat") ;
else
if (n == 3)
        return("science.dat") ;
else

                                                                                                     14 | P a g e
if (n == 4)
          return("general.dat") ;
  return("null") ;}
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : record_count
//        DETAILS        : IT RETURNS THE NO. OF RECORD IN THE
//              GIVEN FILE
//**********************************************************
int quiz :: record_count(char filename[13])
{ fstream file ;
  file.open(filename, ios::in) ;
  file.seekg(0,ios::beg) ;
  int t=0 ;
  while (file.read((char *) this, sizeof(quiz)))
          t++ ;
  file.close() ;
  return t ;}
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : add
//        DETAILS        : IT ADDS THE RECORDS IN THE GIVEN FILE
//**********************************************************
void quiz :: add(char filename[13])
{ lines line ;
  int valid ;
  int t_ques_no ;
  t_ques_no = record_count(filename) ;
  t_ques_no++ ;
  if (t_ques_no == 1)
  { ques_no = t_ques_no ;
          strcpy(ques,"abc") ;
          strcpy(ans1,"-") ;
          strcpy(ans2,"-") ;
          strcpy(ans3,"-") ;
          sol = '0' ;
          fstream file ;
          file.open(filename, ios::out | ios::app ) ;
          file.write((char *) this, sizeof(quiz)) ;
          file.close() ;
          delete_record(filename,t_ques_no) ;
  }

                                                                   15 | P a g e
char ch ;
do{ clrscr() ;
      line.box(1,1,79,23,218) ;
      gotoxy(3,5) ;
      cout <<"question # " <<t_ques_no ;
      gotoxy(3,8) ;
      cout <<"question : " ;
      gotoxy(3,10) ;
      cout <<"answer 1 : " ;
      gotoxy(3,12) ;
      cout <<"answer 2 : " ;
      gotoxy(3,14) ;
      cout <<"answer 3 : " ;
      gotoxy(3,16) ;
      cout <<"solution : " ;
      do
      {        line.box(1,1,79,23,218) ;
               valid = 1 ;
               gotoxy(1,25) ; clreol() ;
               gotoxy(72,25) ;
               cout <<"<0>=EXIT" ;
               gotoxy(3,25) ;
               cout <<"ENTER QUESTION" ;
               gotoxy(14,8) ;
               gets(ques) ;
               strupr(ques) ;
               if (ques[0] == '0')
                         return ;
               if (strlen(ques) > 159 || strlen(ques) == 0)
               {         valid = 0 ;
                         sound(500) ;
                         delay(100) ;
                         nosound() ;
                         gotoxy(1,25) ; clreol() ;
                         gotoxy(1,24) ;
                         cout <<"LENGTH SHOULD NOT BE BLANK OR GREATER THAN 159" ;
                         gotoxy(1,25) ;
                         cout <<"Press any key to continue..." ;
                         getch() ;
                         gotoxy(1,24) ; clreol() ;
                         gotoxy(1,25) ; clreol() ;
                         gotoxy(14,8) ; clreol() ; }

                                                                                     16 | P a g e
} while ( !valid ) ;
do { line.box(1,1,79,23,218) ;
         valid = 1 ;
         gotoxy(1,25) ; clreol() ;
         gotoxy(72,25) ;
         cout <<"<0>=EXIT" ;
         gotoxy(3,25) ;
         cout <<"ENTER ANSWER FOR THE QUESTION" ;
         gotoxy(14,10) ;
         gets(ans1) ;
         strupr(ans1) ;
         if (ans1[0] == '0')
                   return ;
         if (strlen(ans1) > 49)
         {        valid = 0 ;
                   sound(500) ;
                   delay(100) ;
                   nosound() ;
                   gotoxy(1,25) ; clreol() ;
                   gotoxy(1,24) ;
                   cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
                   gotoxy(1,25) ;
                   cout <<"Press any key to continue..." ;
                   getch() ;
                   gotoxy(1,24) ; clreol() ;
                   gotoxy(1,25) ; clreol() ;
                   gotoxy(14,10) ; clreol() ; }
} while ( !valid ) ;
do {
         line.box(1,1,79,23,218) ;
         valid = 1 ;
         gotoxy(1,25) ; clreol() ;
         gotoxy(72,25) ;
         cout <<"<0>=EXIT" ;
         gotoxy(3,25) ;
         cout <<"ENTER ANSWER FOR THE QUESTION" ;
         gotoxy(14,12) ;
         gets(ans2) ;
         strupr(ans2) ;
         if (ans2[0] == '0')
                   return ;
         if (strlen(ans2) > 49)

                                                                  17 | P a g e
{ valid = 0 ;
                   sound(500) ;
                   delay(100) ;
                   nosound() ;
                   gotoxy(1,25) ; clreol() ;
                   gotoxy(1,24) ;
                   cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
                   gotoxy(1,25) ;
                   cout <<"Press any key to continue..." ;
                   getch() ;
                   gotoxy(1,24) ; clreol() ;
                   gotoxy(1,25) ; clreol() ;
                   gotoxy(14,12) ; clreol() ;}
} while ( !valid ) ;
do{ line.box(1,1,79,23,218) ;
         valid = 1 ;
         gotoxy(1,25) ; clreol() ;
         gotoxy(72,25) ;
         cout <<"<0>=EXIT" ;
         gotoxy(3,25) ;
         cout <<"ENTER ANSWER FOR THE QUESTION" ;
         gotoxy(14,14) ;
         gets(ans3) ;
         strupr(ans3) ;
         if (ans3[0] == '0')
                   return ;
         if (strlen(ans3) > 49)
         {         valid = 0 ;
                   sound(500) ;
                   delay(100) ;
                   nosound() ;
                   gotoxy(1,25) ; clreol() ;
                   gotoxy(1,24) ;
                   cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
                   gotoxy(1,25) ;
                   cout <<"Press any key to continue..." ;
                   getch() ;
                   gotoxy(1,24) ; clreol() ;
                   gotoxy(1,25) ; clreol() ;
                   gotoxy(14,14) ; clreol() ; }
} while ( !valid ) ;
do{ line.box(1,1,79,23,218) ;

                                                                  18 | P a g e
valid = 1 ;
         gotoxy(1,25) ; clreol() ;
         gotoxy(72,25) ;
         cout <<"<0>=EXIT" ;
         gotoxy(3,25) ;
         cout <<"ENTER CORRECT SOLUTION FOR THE QUESTION (1/2/3)" ;
         gotoxy(14,16) ;
         sol = getche() ;
         if (sol == '0')
                   return ;
         if (sol != '1' && sol != '2' && sol != '3')
         { valid = 0 ;
                   sound(500) ;
                   delay(100) ;
                   nosound() ;
                   gotoxy(14,16) ; clreol() ;}
} while ( !valid ) ;
gotoxy(1,25) ; clreol() ;
gotoxy(1,24) ; clreol() ;
gotoxy(72,25) ;
cout <<"<0>=EXIT" ;
gotoxy(3,19) ;
cout <<"Do you want to save the record (y/n) : " ;
do{       line.box(1,1,79,23,218) ;
         valid = 1 ;
         gotoxy(42,19) ;
         ch = getche() ;
         ch = toupper(ch) ;
         if (ch == '0')
                   return ;
         if (ch != 'Y' && ch != 'N')
         {         valid = 0 ;
                   sound(500) ;
                   delay(100) ;
                   nosound() ;
                   gotoxy(42,19) ; clreol() ; }
} while ( !valid ) ;
if (ch == 'Y')
{        ques_no = t_ques_no ;
         fstream file ;
         file.open(filename, ios::app ) ;
         file.write((char *) this, sizeof(quiz)) ;

                                                                      19 | P a g e
file.close() ;
                  t_ques_no++ ; }
          gotoxy(72,25) ;
          cout <<"<0>=EXIT" ;
          gotoxy(3,21) ;
          cout <<"Do you want to add more questions (y/n) : " ;
          do
          {       line.box(1,1,79,23,218) ;
                  valid = 1 ;
                  gotoxy(45,21) ;
                  ch = getche() ;
                  ch = toupper(ch) ;
                  if (ch == '0')
                            return ;
                  if (ch != 'Y' && ch != 'N')
                  {         valid = 0 ;
                            sound(500) ;
                            delay(100) ;
                            nosound() ;
                            gotoxy(45,21) ; clreol() ;}} while ( !valid ) ; } while (ch == 'Y') ;}
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : found_record
//        DETAILS      : IT SEARCH THE GIVEN RECORDS IN THE
//             GIVEN FILE AND RETURN 0 IF NOT FOUND
//**********************************************************
int quiz :: found_record(char filename[13], int t_ques_no)
{ fstream file ;
  file.open(filename, ios::in) ;
  file.seekg(0,ios::beg) ;
  int found=0 ;
  while (file.read((char *) this, sizeof(quiz)))
  {if (t_ques_no == ques_no)
          { found++ ;
                  break ;} }
  file.close() ;
  return found ;}
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : display_record
//        DETAILS      : IT DISPLAY THE RECORD FOR THE GIVEN
//             QUESTION NO. FROM THE GIVEN FILE

                                                                                                     20 | P a g e
//**********************************************************
void quiz :: display_record(char filename[13], int t_ques_no)
{ fstream file ;
  file.open(filename, ios::in) ;
  file.seekg(0,ios::beg) ;
  while (file.read((char *) this, sizeof(quiz)))
  {       if (t_ques_no == ques_no)
          {                    gotoxy(3,3) ;
                     cout <<"question # " <<t_ques_no ;
                     gotoxy(3,7) ;
                     cout <<"question : " <<ques ;
                     gotoxy(3,8) ;
                     cout <<"answer 1 : " <<ans1 ;
                     gotoxy(3,9) ;
                     cout <<"answer 2 : " <<ans2 ;
                     gotoxy(3,10) ;
                     cout <<"answer 3 : " <<ans3 ;
                     break ;}}
  file.close() ;}
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : delete_record
//        DETAILS         : IT DELETE THE RECORD FOR THE GIVEN
//                 QUESTION NO. FROM THE GIVEN FILE
//**********************************************************
void quiz :: delete_record(char filename[13], int t_ques_no)
{ fstream file ;
  file.open(filename, ios::in) ;
  fstream temp ;
  temp.open("temp.dat", ios::out) ;
  file.seekg(0,ios::beg) ;
  while (!file.eof())
  {       file.read((char *) this, sizeof(quiz)) ;
          if ( file.eof() )
                     break ;
          if (ques_no != t_ques_no)
                     temp.write((char *) this, sizeof(quiz)) ; }
  file.close() ;
  temp.close() ;
  file.open(filename, ios::out) ;
  temp.open("temp.dat", ios::in) ;
  temp.seekg(0,ios::beg) ;

                                                                   21 | P a g e
t_ques_no = 1 ;
  while (!temp.eof())
{ temp.read((char *) this, sizeof(quiz)) ;
          ques_no = t_ques_no ;
          if (temp.eof())
                   break ;
          file.write((char *) this, sizeof(quiz)) ;
          t_ques_no++ ; }
  file.close() ;
  temp.close() ;}
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : deletion
//        DETAILS      : IT GIVE THE QUESTION NO. TO DELETE
//              RECORD FROM THE GIVEN FILE
//**********************************************************
void quiz :: deletion(char filename[13])
{ lines line ;
  clrscr() ;
  int valid ;
  int t_ques_no=0, t;
  char t1_ques_no[5] ;
  char ch ;
  line.box(1,1,79,23,218) ;
  gotoxy(72,25) ;
  cout <<"<0>=EXIT" ;
  gotoxy(3,3) ;
  cout <<"Enter question no. to be deleted : " ;
  do
  {       gotoxy(38,3) ;
          gets(t1_ques_no) ;
  } while (strlen(t1_ques_no) == 0) ;
  t = atoi(t1_ques_no) ;
  t_ques_no = t ;
  if (t1_ques_no[0] == '0')
          return ;
  if (!found_record(filename,t_ques_no))
  {       sound(500) ;
          delay(100) ;
          nosound() ;
          gotoxy(3,15) ;
          cout <<"question not found" ;

                                                               22 | P a g e
line.line_hor(1,79,24,196) ;
          gotoxy(1,25) ;
          cout <<"Press any key to continue..." ;
          getch() ;
          return ; }
  clrscr() ;
  line.box(1,1,79,23,218) ;
  display_record(filename,t_ques_no) ;
  gotoxy(3,12) ;
  cout <<"Do you want to delete this Record (y/n) : " ;
  do {valid = 1 ;
          gotoxy(45,12) ;
          ch = getche() ;
          ch = toupper(ch) ;
          if (ch != 'Y' && ch != 'N')
          {valid = 0 ;
                    sound(500) ;
                    delay(100) ;
                    nosound() ;
                    gotoxy(45,10) ; clreol() ;} } while (!valid ) ;
  if (ch == 'N')
          return ;
  gotoxy(1,25) ;
  cout <<"Wait..." ;
  delete_record(filename,t_ques_no) ;
  clrscr() ;
  sound(500) ;
  delay(100) ;
  nosound() ;
  gotoxy(3,14) ;
  cout <<"Record Deleted" ;
  line.line_hor(1,79,24,196) ;
  gotoxy(1,25) ;
  cout <<"Press any key to continue...." ;
  getch() ;}
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : modify_record
//        DETAILS        : IT MODIFY THE RECORD FOR THE GIVEN
//                QUESTION NO. FROM THE GIVEN FILE
//**********************************************************
void quiz :: modify_record(char filename[13], int t_ques_no)

                                                                      23 | P a g e
{ lines line ;
  int valid, modified=0 ;
  char ch ;
  line.line_hor(2,78,12,196) ;
  line.box(1,1,79,23,218) ;
  gotoxy(3,14) ;
  cout <<"QUESTION # " <<t_ques_no ;
  gotoxy(3,16) ;
  cout <<"QUESTION : " ;
  gotoxy(3,17) ;
  cout <<"ANSWER 1 : " ;
  gotoxy(3,18) ;
  cout <<"ANSWER 2 : " ;
  gotoxy(3,19) ;
  cout <<"ANSWER 3 : " ;
  gotoxy(3,20) ;
  cout <<"SOLUTION : " ;
  gotoxy(1,25) ; clreol() ;
  line.line_hor(1,79,23,196) ;
  gotoxy(14,16) ;
  cout <<"Change (y/n) " ;
  do
  {       line.box(1,1,79,23,218) ;
          valid = 1 ;
          gotoxy(28,16) ;
          ch = getche() ;
          ch = toupper(ch) ;
          if (ch != 'Y' && ch != 'N')
          {         valid = 0 ;
                    sound(500) ;
                    delay(100) ;
                    nosound() ;
                    gotoxy(28,16) ; clreol() ; } } while (!valid) ;
  valid = 0 ;
  while (!valid && ch == 'Y')
  {        line.box(1,1,79,23,218) ;
          modified = 1 ;
          valid = 1 ;
          gotoxy(14,16) ; clreol() ;
          gotoxy(72,25) ;
          cout <<"<0>=EXIT" ;
          gotoxy(3,25) ;

                                                                      24 | P a g e
cout <<"ENTER QUESTION" ;
       gotoxy(14,16) ;
       gets(ques) ;
       strupr(ques) ;
       if (ques[0] == '0')
                 return ;
       if (strlen(ques) >159 || strlen(ques) == 0)
       { valid = 0 ;
                 sound(500) ;
                 delay(100) ;
                 nosound() ;
                 gotoxy(1,25) ; clreol() ;
                 gotoxy(1,24) ;
                 cout <<"LENGTH SHOULD NOT BLANK OR GREATER THAN 159" ;
                 gotoxy(1,25) ;
                 cout <<"Press any key to continue..." ;
                 getch() ;
                 gotoxy(1,24) ; clreol() ;
                 gotoxy(1,25) ; clreol() ;
                 gotoxy(14,16) ; clreol() ;} }
gotoxy(1,25) ; clreol() ;
gotoxy(14,17) ;
cout <<"Change (y/n) " ;
do{line.box(1,1,79,23,218) ;
       valid = 1 ;
       gotoxy(28,17) ;
       ch = getche() ;
       ch = toupper(ch) ;
       if (ch != 'Y' && ch != 'N')
       {         valid = 0 ;
                 sound(500) ;
                 delay(100) ;
                 nosound() ;
                 gotoxy(28,17) ; clreol() ; }
} while (!valid) ;
valid = 0 ;
while (!valid && ch == 'Y')
{      line.box(1,1,79,23,218) ;
       modified = 1 ;
       valid = 1 ;
       gotoxy(13,17) ; clreol() ;
       gotoxy(72,25) ;

                                                                          25 | P a g e
cout <<"<0>=EXIT" ;
       gotoxy(3,25) ;
       cout <<"ENTER ANSWER FOR THE QUESTION" ;
       gotoxy(14,17) ;
       gets(ans1) ;
       strupr(ans1) ;
       if (ans1[0] == '0')
                 return ;
       if (strlen(ans1) > 49)
       {       valid = 0 ;
                 sound(500) ;
                 delay(100) ;
                 nosound() ;
                 gotoxy(1,25) ; clreol() ;
                 gotoxy(1,24) ;
                 cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
                 gotoxy(1,25) ;
                 cout <<"Press any key to continue..." ;
                 getch() ;
                 gotoxy(1,24) ; clreol() ;
                 gotoxy(1,25) ; clreol() ;
                 gotoxy(14,17) ; clreol() ;} }
gotoxy(1,25) ; clreol() ;
gotoxy(14,18) ;
cout <<"Change (y/n) " ;
do{line.box(1,1,79,23,218) ;
       valid = 1 ;
       gotoxy(28,18) ;
       ch = getche() ;
       ch = toupper(ch) ;
       if (ch != 'Y' && ch != 'N')
       {         valid = 0 ;
                 sound(500) ;
                 delay(100) ;
                 nosound() ;
                 gotoxy(28,18) ; clreol() ;} } while (!valid) ;
valid = 0 ;
while (!valid && ch == 'Y')
{     line.box(1,1,79,23,218) ;
       modified = 1 ;
       valid = 1 ;
       gotoxy(14,18) ; clreol() ;

                                                                  26 | P a g e
gotoxy(72,25) ;
       cout <<"<0>=EXIT" ;
       gotoxy(3,25) ;
       cout <<"ENTER ANSWER FOR THE QUESTION" ;
       gotoxy(14,18) ;
       gets(ans2) ;
       strupr(ans2) ;
       if (ans2[0] == '0')
                 return ;
       if (strlen(ans2) > 49)
       {        valid = 0 ;
                 sound(500) ;
                 delay(100) ;
                 nosound() ;
                 gotoxy(1,25) ; clreol() ;
                 gotoxy(1,24) ;
                 cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
                 gotoxy(1,25) ;
                 cout <<"Press any key to continue..." ;
                 getch() ;
                 gotoxy(1,24) ; clreol() ;
                 gotoxy(1,25) ; clreol() ;
                 gotoxy(14,18) ; clreol() ;} }
gotoxy(1,25) ; clreol() ;
gotoxy(14,19) ;
cout <<"Change (y/n) " ;
do
{      line.box(1,1,79,23,218) ;
       valid = 1 ;
       gotoxy(28,19) ;
       ch = getche() ;
       ch = toupper(ch) ;
       if (ch != 'Y' && ch != 'N')
       {        valid = 0 ;
                 sound(500) ;
                 delay(100) ;
                 nosound() ;
                 gotoxy(28,19) ; clreol() ;} } while (!valid) ;
valid = 0 ;
while (!valid && ch == 'Y')
{       line.box(1,1,79,23,218) ;
       modified = 1 ;

                                                                  27 | P a g e
valid = 1 ;
       gotoxy(14,19) ; clreol() ;
       gotoxy(72,25) ;
       cout <<"<0>=EXIT" ;
       gotoxy(3,25) ;
       cout <<"ENTER ANSWER FOR THE QUESTION" ;
       gotoxy(14,19) ;
       gets(ans3) ;
       strupr(ans3) ;
       if (ans3[0] == '0')
                  return ;
       if (strlen(ans3) > 49)
       {         valid = 0 ;
                  sound(500) ;
                  delay(100) ;
                  nosound() ;
                  gotoxy(1,25) ; clreol() ;
                  gotoxy(1,24) ;
                  cout <<"LENGTH SHOULD NOT GREATER THAN 49" ;
                  gotoxy(1,25) ;
                  cout <<"Press any key to continue..." ;
                  getch() ;
                  gotoxy(1,24) ; clreol() ;
                  gotoxy(1,25) ; clreol() ;
                  gotoxy(14,19) ; clreol() ;} }
if (!modified)
       return ;
do{ line.box(1,1,79,23,218) ;
       gotoxy(1,25) ; clreol() ;
       valid = 1 ;
       gotoxy(72,25) ;
       cout <<"<0>=EXIT" ;
       gotoxy(3,25) ;
       cout <<"ENTER CORRECT SOLUTION FOR THE QUESTION (1/2/3)" ;
       gotoxy(14,20) ;
       sol = getche() ;
       if (sol == '0')
                  return ;
       if (sol != '1' && sol != '2' && sol != '3')
       { valid = 0 ;
                  sound(500) ;
                  delay(100) ;

                                                                    28 | P a g e
nosound() ;
                    gotoxy(14,20) ; clreol() ;} } while (!valid) ;
  gotoxy(1,25) ; clreol() ;
  gotoxy(1,24) ; clreol() ;
  gotoxy(1,22) ;
  cout <<"Do you want to save the record (y/n) : " ;
  do { line.box(1,1,79,23,218) ;
          valid = 1 ;
          gotoxy(41,22) ;
          ch = getche() ;
          ch = toupper(ch) ;
          if (ch != 'Y' && ch != 'N')
          {        valid = 0 ;
                    sound(500) ;
                    delay(100) ;
                    nosound() ;
                    gotoxy(41,22) ; clreol() ; } } while ( !valid ) ;
  if (ch == 'N')
          return ;
  fstream file ;
  file.open(filename, ios::out | ios::ate) ;
  int recno ;
  recno = t_ques_no ;
  int location ;
  location = (recno-1) * sizeof(quiz) ;
  file.seekp(location) ;
  file.write((char *) this, sizeof(quiz)) ;
  file.close() ;
  clrscr() ;
  sound(500) ;
  delay(100) ;
  nosound() ;
  gotoxy(1,14) ;
  cout <<"Record Modified" ;
  line.line_hor(1,79,24,196) ;
  gotoxy(1,25) ;
  cout <<"Press any key to continue..." ;
  getch() ; }
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : modify
//        DETAILS        : IT GIVE THE QUESTION NO. TO MODIFY

                                                                        29 | P a g e
//                RECORD FROM THE GIVEN FILE
//**********************************************************
void quiz :: modify(char filename[13])
{ lines line ;
  clrscr() ;
  int valid ;
  int t_ques_no=0, t;
  char t1_ques_no[5] ;
  char ch ;
  line.box(1,1,79,23,218) ;
  gotoxy(72,25) ;
  cout <<"<0>=EXIT" ;
  gotoxy(3,3) ;
  cout <<"Enter question no. to be modify : " ;
  do { gotoxy(38,3) ;
          gets(t1_ques_no) ; } while (strlen(t1_ques_no) == 0) ;
  t = atoi(t1_ques_no) ;
  t_ques_no = t ;
  if (t1_ques_no[0] == '0')
          return ;
  if (!found_record(filename,t_ques_no))
  {        sound(500) ;
          delay(100) ;
          nosound() ;
          gotoxy(3,15) ;
          cout <<"question not found" ;
          line.line_hor(2,78,24,196) ;
          gotoxy(1,25) ;
          cout <<"Press any key to continue..." ;
          getch() ;
          return ; }
  clrscr() ;
  display_record(filename,t_ques_no) ;
  gotoxy(3,12) ;
  cout <<"Do you want to modify this Record (y/n) : " ;
  do { valid = 1 ;
          gotoxy(45,12) ;
          ch = getche() ;
          ch = toupper(ch) ;
          if (ch != 'Y' && ch != 'N')
          { valid = 0 ;
                    sound(500) ;

                                                                   30 | P a g e
delay(100) ;
                   nosound() ;
                   gotoxy(45,10) ; clreol() ;}
  } while (!valid ) ;
  if (ch == 'N')
          return ;
  modify_record(filename,t_ques_no) ; }
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : display_score
//        DETAILS      : IT DISPLAY THE SCORE FOR THE GIVEN
//               PLAYER'S NAME
//**********************************************************
void quiz :: display_score(char name[20], int played, int correct)
{ clrscr() ;
  lines line ;
  line.box(1,1,39,25,218) ;
  line.box(2,2,38,24,219) ;
  textbackground(WHITE) ;
  textcolor(BLACK+BLINK) ;
  gotoxy(5,4) ;
  cprintf("                    ") ;
  gotoxy(9,4) ;
  cprintf("S C O R E B O A R D") ;
  textbackground(BLACK) ;
  textcolor(LIGHTGRAY) ;
  gotoxy(5,7) ;
  cout <<"Player's Name : " <<name ;
  gotoxy(5,9) ;
  cout <<"questions Attempted : " <<played ;
  gotoxy(5,11) ;
  cout <<"Correct answer : " <<correct ;
  gotoxy(5,13) ;
  cout <<"Wrong answer           : " <<played-correct ;
  int score ;
  score = correct * 10 ;
  gotoxy(5,16) ;
  cout <<"Score : " <<score ;
  int tplayed ;
  tplayed = played * 10 ;
  float percentage ;
  percentage = ((score*100)/tplayed) ;

                                                                     31 | P a g e
gotoxy(5,18) ;
  cout <<"Percentage : " <<percentage ;
getch() ; }
//**********************************************************
//        CLASS NAME : quiz
//        FUNCTION NAME : play
//        DETAILS       : IT CREATES SCREEN FOR PLAYING QUIZ
//                TO THE PLAYER FOR THE GIVEN FILE NAME
//                AND KEEP SCORE.
//**********************************************************
void quiz :: play(char filename[13])
{ clrscr() ;
  int valid ;
  lines line ;
  char name[20] ;
  gotoxy(3,3) ;
  cout <<"Enter your name : " ;
  do
  {       line.box(1,1,39,25,219) ;
          valid = 1 ;
          gotoxy(30,24) ;
          cout <<"<0>=EXIT" ;
          gotoxy(21,3) ;
          gets(name) ;
          strupr(name) ;
          if (name[0] == '0')
                    return ;
          if (strlen(name) > 18)
          {        valid = 0 ;
                    sound(500) ;
                    delay(100) ;
                    nosound() ;
                    gotoxy(30,24) ;
                    cout <<"     ";
                    gotoxy(3,23) ;
                    cout <<"LENGTH SHOULD NOT GREATER THAN 18" ;
                    gotoxy(3,24) ;
                    cout <<"Press any key to continue..." ;
                    getch() ;
                    gotoxy(3,23) ;
                    cout <<"                   ";
                    gotoxy(3,24) ;

                                                                   32 | P a g e
cout <<"                     ";
                 gotoxy(21,3) ;
           cout <<"             " ;}
} while ( !valid ) ;
char t_sol, ch ;
int correct=0, played=0 ;
fstream file ;
file.open(filename,ios::in) ;
file.seekg(0,ios::beg) ;
while (file.read((char *) this, sizeof(quiz)))
{       clrscr() ;
       line.box(1,1,39,25,219) ;
       gotoxy(25,3) ;
       cout <<"SCORE:" <<correct*10 ;
       valid = 1 ;
       gotoxy(28,24) ;
       cout <<"<ESC>=Exit" ;
       gotoxy(3,4) ;
       cout <<"question # " <<ques_no ;
       gotoxy(3,6) ;
       cout <<"question : " <<ques ;
       gotoxy(3,10) ;
       cout <<"answer 1 : " <<ans1 ;
       gotoxy(3,11) ;
       cout <<"answer 2 : " <<ans2 ;
       gotoxy(3,12) ;
       cout <<"answer 3 : " <<ans3 ;
       gotoxy(3,14) ;
       cout <<"Enter correct solution : " ;
       int i=0, j=0, time=10 ;
       do { valid = 1 ;
                 gotoxy(3,21) ;
                 cout <<"Time : " <<time ;
                 gotoxy(28,12) ;
                 do { delay(1) ;
                         i++ ;
                         j++ ;
                         if (j == 600)
                         {       j=0;
                                     time-- ;
                                    gotoxy(11,21) ;
                                    cout <<" " ;

                                                      33 | P a g e
gotoxy(10,21) ;
                             cout <<time ;
                        gotoxy(28,14) ;}
          } while (!kbhit() && i<6000) ;
          if (i >= 6000)
          {         played++ ;
                    sound(500) ;
                    delay(100) ;
                    nosound() ;
                    gotoxy(13,16) ;
                    cout <<"Sorry Time up!" ;
                    gotoxy(1,1) ;
                    getch() ;
                    if (played)
                             display_score(name,played,correct) ;
                    return ;}
          gotoxy(3,21) ;
          cout <<"           ";
          gotoxy(28,12) ;
          t_sol = getche() ;
          if (t_sol == 27)
          {                   if (played)
                             display_score(name,played,correct) ;
                    return ; }
          if (t_sol != '1' && t_sol != '2' && t_sol != '3')
          {         valid = 0 ;
                    sound(500) ;
                    delay(100) ;
                    nosound() ;
                    gotoxy(28,12) ;
                    cout <<" " ; }
} while (!valid) ;
played++ ;
if (t_sol != sol)
{          sound(500) ;
          delay(100) ;
          nosound() ;
          gotoxy(14,16) ;
          cout <<"wrong answer" ;
          gotoxy(13,17) ;
          cout <<"Correct answer : " <<sol ;
          gotoxy(1,1) ;

                                                                    34 | P a g e
ch = getch() ;
             gotoxy(14,15) ;
              cout <<"       ";
             gotoxy(13,16) ;
             cout <<"           ";
             gotoxy(3,24) ;
             cout <<"                ";}
      else
      {            correct++ ;
                   sound(500) ;
                   delay(100) ;
                   nosound() ;
                   gotoxy(16,16) ;
                   cout <<"GOOD ! CORRECT ANSWER" ;
                   gotoxy(25,3) ;
                   cout <<"SCORE:" <<correct*10 ;
                   gotoxy(1,1) ;
                   ch = getch() ; }
          if (ch == 27)
          {     display_score(name,played,correct) ;
                   return ;          } }
  gotoxy(3,22) ;
  cout <<"No more questions available" ;
  getch() ;
  if (!played)
          return ;
  display_score(name,played,correct) ; }
//**********************************************************
//        FUNCTION NAME : main
//        DETAILS       : IT CALLS THE START FUNCTION AND
//              MENU FUNCTION.
//**********************************************************
void main(void)
{ menu m ;
  m.start() ;
  m.main_menu() ;
}
//**********************************************************
//             END OF PROJECT
//**********************************************************



                                                               35 | P a g e
OUTPUT




         36 | P a g e
37 | P a g e
38 | P a g e
39 | P a g e

Weitere ähnliche Inhalte

Was ist angesagt?

Overview of c language
Overview of c languageOverview of c language
Overview of c language
shalini392
 
First game using c language
First game using c languageFirst game using c language
First game using c language
Saurabh Khetan
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
Aarti P
 

Was ist angesagt? (20)

Student database management system PROJECT
Student database management system PROJECTStudent database management system PROJECT
Student database management system PROJECT
 
Tic tac toe game code
Tic tac toe game codeTic tac toe game code
Tic tac toe game code
 
School Management (c++)
School Management (c++) School Management (c++)
School Management (c++)
 
Online quiz system
Online quiz systemOnline quiz system
Online quiz system
 
Android technical quiz app
Android technical quiz appAndroid technical quiz app
Android technical quiz app
 
Online Quiz System Project PPT
Online Quiz System Project PPTOnline Quiz System Project PPT
Online Quiz System Project PPT
 
Modul Pratikum Algoritma dan Pemrograman dalam Bahasa Visual C++ 2010
Modul Pratikum Algoritma dan Pemrograman dalam Bahasa Visual C++ 2010Modul Pratikum Algoritma dan Pemrograman dalam Bahasa Visual C++ 2010
Modul Pratikum Algoritma dan Pemrograman dalam Bahasa Visual C++ 2010
 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
 
ATM System management
ATM System managementATM System management
ATM System management
 
Bangla News Portal System
Bangla News Portal SystemBangla News Portal System
Bangla News Portal System
 
Android async task
Android async taskAndroid async task
Android async task
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 
Tipe data dan variabel
Tipe data dan variabelTipe data dan variabel
Tipe data dan variabel
 
jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events jQuery -Chapter 2 - Selectors and Events
jQuery -Chapter 2 - Selectors and Events
 
Lefmost rightmost TOC.pptx
Lefmost rightmost TOC.pptxLefmost rightmost TOC.pptx
Lefmost rightmost TOC.pptx
 
Library Managment System - C++ Program
Library Managment System - C++ ProgramLibrary Managment System - C++ Program
Library Managment System - C++ Program
 
First game using c language
First game using c languageFirst game using c language
First game using c language
 
Visual basic 6.0
Visual basic 6.0Visual basic 6.0
Visual basic 6.0
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 

Ähnlich wie Quiz using C++

Here is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfHere is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdf
doshirajesh75
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
Week 2 - Advanced C++list1.txt312220131197.docx
Week 2 - Advanced C++list1.txt312220131197.docxWeek 2 - Advanced C++list1.txt312220131197.docx
Week 2 - Advanced C++list1.txt312220131197.docx
melbruce90096
 
Write the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docxWrite the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docx
delicecogupdyke
 
write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
annetnash8266
 
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdfg++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
arakalamkah11
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
Abed Bukhari
 

Ähnlich wie Quiz using C++ (20)

M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
 
Project fast food automaton
Project fast food automatonProject fast food automaton
Project fast food automaton
 
Durgesh
DurgeshDurgesh
Durgesh
 
Project hotel on hotel management fo
Project  hotel on hotel management foProject  hotel on hotel management fo
Project hotel on hotel management fo
 
Here is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdfHere is the code- I can't get it to work- I need a function that finds.pdf
Here is the code- I can't get it to work- I need a function that finds.pdf
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
Java
JavaJava
Java
 
java-introduction.pdf
java-introduction.pdfjava-introduction.pdf
java-introduction.pdf
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Week 2 - Advanced C++list1.txt312220131197.docx
Week 2 - Advanced C++list1.txt312220131197.docxWeek 2 - Advanced C++list1.txt312220131197.docx
Week 2 - Advanced C++list1.txt312220131197.docx
 
Write the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docxWrite the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docx
 
c++ project on restaurant billing
c++ project on restaurant billing c++ project on restaurant billing
c++ project on restaurant billing
 
About Go
About GoAbout Go
About Go
 
write the TODO part of the program.docx
write the TODO part of the program.docxwrite the TODO part of the program.docx
write the TODO part of the program.docx
 
Computer Investgatort Project (HOTEL MANAGEMENT SYSTEM)
Computer Investgatort Project (HOTEL MANAGEMENT SYSTEM)Computer Investgatort Project (HOTEL MANAGEMENT SYSTEM)
Computer Investgatort Project (HOTEL MANAGEMENT SYSTEM)
 
DS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL IntroductionDS & Algo 1 - C++ and STL Introduction
DS & Algo 1 - C++ and STL Introduction
 
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdfg++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
g++ -o simpleVector.exe simpleVector.cpp #include stdio.h #i.pdf
 
Treatment, Architecture and Threads
Treatment, Architecture and ThreadsTreatment, Architecture and Threads
Treatment, Architecture and Threads
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 

Mehr von Sushil Mishra

Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sql
Sushil Mishra
 
microprocessor 8086 lab manual !!
microprocessor 8086 lab manual !!microprocessor 8086 lab manual !!
microprocessor 8086 lab manual !!
Sushil Mishra
 

Mehr von Sushil Mishra (14)

Heart beat monitor using AT89S52 microcontroller
Heart beat monitor using AT89S52 microcontrollerHeart beat monitor using AT89S52 microcontroller
Heart beat monitor using AT89S52 microcontroller
 
Opt sim manual
Opt sim manualOpt sim manual
Opt sim manual
 
Consumer electronics lab manual
Consumer electronics lab manualConsumer electronics lab manual
Consumer electronics lab manual
 
Summer training at Doordarshan presentation
Summer training at Doordarshan presentationSummer training at Doordarshan presentation
Summer training at Doordarshan presentation
 
List of microcontroller 8051 projects
List of microcontroller 8051 projectsList of microcontroller 8051 projects
List of microcontroller 8051 projects
 
Sequence Diagram of Hotel Management System
Sequence Diagram of Hotel Management SystemSequence Diagram of Hotel Management System
Sequence Diagram of Hotel Management System
 
Trigger and cursor program using sql
Trigger and cursor program using sqlTrigger and cursor program using sql
Trigger and cursor program using sql
 
c-programming-using-pointers
c-programming-using-pointersc-programming-using-pointers
c-programming-using-pointers
 
microprocessor 8086 lab manual !!
microprocessor 8086 lab manual !!microprocessor 8086 lab manual !!
microprocessor 8086 lab manual !!
 
Tachometer using AT89S52 microcontroller with motor control
Tachometer using AT89S52 microcontroller with motor controlTachometer using AT89S52 microcontroller with motor control
Tachometer using AT89S52 microcontroller with motor control
 
Report on industrial training at DDK, Mandi House, Delhi -01
Report on industrial training at DDK, Mandi House, Delhi -01Report on industrial training at DDK, Mandi House, Delhi -01
Report on industrial training at DDK, Mandi House, Delhi -01
 
Mythological calender using C++
Mythological calender using C++Mythological calender using C++
Mythological calender using C++
 
Laser, its working & hazards
Laser, its working & hazardsLaser, its working & hazards
Laser, its working & hazards
 
Designing a notch filter using orcad 15.3
Designing a notch filter using orcad 15.3Designing a notch filter using orcad 15.3
Designing a notch filter using orcad 15.3
 

Kürzlich hochgeladen

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 

Kürzlich hochgeladen (20)

Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

Quiz using C++

  • 1. Made By :- Sushil Kumar Mishra (05311502809) Of ECE-I 1|Page
  • 2. INTRODUCTION The Online Quiz is basically for the school and college goers, where a user can give an online test for a subject(s). According to the number of marks his/her evaluation has to be done. Where the students at large, this Online Quiz scrutinize the universities/Institutions problems at once and produce a quick response in a limited time. It can be further extended to any organization or company who want to conduct the examination using online. The project keeps four different data files such as : 􀂈 Computer.dat 􀂈 Maths.dat 􀂈 Science.data 􀂈 General.dat All the above files have the common fields, but the records are appended according to the examination option. ques_no : Question number ques : Name of the question ans1 : First answer of the question ans2 : Second answer of the question ans3 : Third answer of the question sol : Correct answer of the question The Online Quiz system displays the result immediately after a quiz is completed. The Online Quiz system keeps track of the following options for maintaining its database and quiz. QUIZ OPTIONS PLAY ADD QUESTIONS EDIT QUIT PLAY : This option opens a sub-menu as : SUB – MENU COMPUTER MATHEMATICS SCIENCE GENERAL (Uparrow DownArrow)=Move <ENTER> = Select <ESC>Exit From the above menus when you select any one option, you will be used to enter your name. After entering your name, it will display the question one-by-one and you have to give the answer in a specified time limit. If the time limit is over, it will display the next question and zero will be added to your score, otherwise, your score will be incremented by one. In the end, you will see a score board as shown in Fig. 1.9. Similarly, you can attend all the sub-menu options, as required by you. ADD QUESTIONS : In this option, you can add different questions to your previous sub-menu options. For example, you select COMPUTER, you will see a screen for adding a question with its question number and question details. Here, the question number generates automatically. After entering three answers and its right solution, you will be asked for updating the database for next quiz. EDIT : In this option, you can delete, modify your previously entered questions as required. Here, all the process will transact through the question number. Class Description - lines. It controls function related to draw horizontal and vertical line and boxes. - menu. It control the overall functioning of Online Quiz project. It displays all menus and submenus. - quiz. It controls overall function related to quiz, like adding, deleting or modifying questions in the database. 2|Page
  • 3. SOURCE CODE //********************************************************** // PROJECT COMPUTER QUIZ //********************************************************** //********************************************************** // INCLUDED HEADER FILES //********************************************************** #include <iostream.h> #include <conio.h> #include <dos.h> #include <string.h> #include <fstream.h> #include <process.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> //********************************************************** // CLASS NAME : lines // DETAILS : IT CONTROLS FUNCTIONS RELATED TO DRAW // LINES, BOXES, ETC. //********************************************************** class lines {public : void line_hor (int, int, int, char) ; void line_ver (int, int, int, char) ; void box (int,int,int,int,char) ; }; //*************************************************************** // CLASS NAME : menu // DETAILS : IT CONTROLS OVER ALL FUNCTIONING OF PROJECT //*************************************************************** class menu {public : void main_menu(void) ; char *sub_menu(void) ; void start(void) ; private : void edit_menu(void) ; }; 3|Page
  • 4. //********************************************************** // CLASS NAME : quiz // DETAILS : IT CONTROLS OVER ALL THE FUNCTIONS // RELATED TO QUIZ //********************************************************** class quiz {public : void play(char filename[13]) ; void add(char filename[13]) ; void deletion(char filename[13]) ; void modify(char filename[13]) ; private : void delete_record(char filename[13], int) ; void modify_record(char filename[13], int) ; void display_score(char name[20], int, int) ; int recordno(char filename[13], int) ; int record_count(char filename[13]) ; int found_record(char filename[13], int) ; void display_record(char filename[13], int) ; int ques_no ; char ques[60] ; char ans1[50] ; char ans2[50] ; char ans3[50] ; char sol ; }; //********************************************************** // CLASS NAME : lines // FUNCTION NAME : line_hor // DETAILS : IT ACCEPTS THE ROWS AND COLUMNS AND // DRAW THE HORIZONTAL LINE //********************************************************** void lines :: line_hor(int column1, int column2, int row, char c) { for ( column1; column1<=column2; column1++ ) { gotoxy(column1,row) ; cout <<c ; } } //********************************************************** // CLASS NAME : lines // FUNCTION NAME : line_ver 4|Page
  • 5. // DETAILS : IT ACCEPTS THE ROWS AND COLUMNS AND // DRAW THE VERTICAL LINE //********************************************************** void lines :: line_ver(int row1, int row2, int column, char c) { for ( row1; row1<=row2; row1++ ) { gotoxy(column,row1) ; cout <<c ; }} //********************************************************** // CLASS NAME : lines // FUNCTION NAME : box // DETAILS : IT ACCEPTS THE ROWS AND COLUMNS AND // DRAW THE BOX //********************************************************** void lines :: box(int column1, int row1, int column2, int row2, char c) { char ch=218 ; char c1, c2, c3, c4 ; char l1=196, l2=179 ; if (c == ch) { c1 = 218 ; c2 = 191 ; c3 = 192 ; c4 = 217 ; l1 = 196 ; l2 = 179 ; } else { c1 = c ; c2 = c ; c3 = c ; c4 = c ; l1 = c ; l2 = c ; } gotoxy(column1,row1) ; cout <<c1 ; gotoxy(column2,row1) ; cout <<c2 ; gotoxy(column1,row2) ; cout <<c3 ; gotoxy(column2,row2) ; cout <<c4 ; column1++ ; 5|Page
  • 6. column2-- ; line_hor(column1,column2,row1,l1) ; line_hor(column1,column2,row2,l1) ; column1-- ; column2++ ; row1++ ; row2-- ; line_ver(row1,row2,column1,l2) ; line_ver(row1,row2,column2,l2) ; } //********************************************************** // CLASS NAME : menu // FUNCTION NAME : start // DETAILS : IT CREATES THE OPENING SCREEN //********************************************************** void menu :: start(void) { lines line ; textmode(C80) ; clrscr() ; textbackground(LIGHTCYAN); textcolor(BLACK) ; clrscr() ; gotoxy(8,12) ; cout <<"C O M P U T E R" ; gotoxy(25,12) ; cout <<"Q U I Z" ; line.box(4,10,36,14,21) ; gotoxy(5,21); cout<<"MADE BY :"; gotoxy(5,22); cout<<"SUSHIL MISHRA,SACHIN MISHRA(ECE-1)"; line.box(2,19,40,24,219); gotoxy(4,10); getch() ; textbackground(BLACK) ; textcolor(LIGHTGRAY) ; clrscr() ; } //********************************************************** // CLASS NAME : menu // FUNCTION NAME : main_menu // DETAILS : IT CREATES THE MAIN MENU TO CONTROL // ALL THE FUNCTIONS //********************************************************** 6|Page
  • 7. void menu :: main_menu(void) { lines line ; textmode(C80) ; clrscr ; int valid ; int n = 4 ; int x = 14 ; char ch1, ch2 ; char chr1=219, chr=175 ; do { line.box (1,1,39,25,219) ; line.line_hor(9,31,6,196) ; line.box (8,3,32,20,218) ; char c1=24, c2=25 ; gotoxy(3,24) ; cout <<c1 ; cout <<c2 ; cout <<"=Move <ENTER>=Select <ESC>=Exit" ; gotoxy(13,5) ; cout <<chr1 ; textbackground(WHITE) ; textcolor(BLACK) ; gotoxy(14,5) ; cprintf("Q U I Z ") ; textbackground(BLACK) ; textcolor(LIGHTGRAY) ; gotoxy(14,8) ; cout <<"OPTIONS" ; gotoxy(14,9) ; cout <<"-------" ; gotoxy(14,11) ; cout <<"PLAY" ; gotoxy(14,12) ; cout <<"ADD QUESTIONS" ; gotoxy(14,13) ; cout <<"EDIT" ; gotoxy(14,14) ; cout <<"QUIT" ; gotoxy(10,x) ; cout <<chr ; gotoxy(13,5) ; do 7|Page
  • 8. { do { do { ch1 = getch() ; if ( ch1 == 27 ) { textmode(C80) ; clrscr() ; exit(0) ; } } while (( ch1 != 0 ) && ( ch1 != 13 )) ; if ( ch1 != 13 ) { do { ch2 = getch() ; if ( ch2 == 27 ) { textmode(C80) ; clrscr() ; exit(0) ; } } while (( ch2 != 72 ) && ( ch2 != 80 ) && ( ch2 != 13 )) ; } } while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ; if (( ch1 == 0 ) && ( ch2 == 80 )) { gotoxy(10,x) ; cout <<" " ; if (n == 4) {n=1; x=x-3;} else { n=n+1; x=x+1;} gotoxy(10,x) ; cout <<chr ; gotoxy(13,5) ; sound(200) ; delay(30) ; nosound() ; } if (( ch1 == 0 ) && ( ch2 == 72 )) { gotoxy(10,x) ; cout <<" " ; if ( n == 1 ) {n=4; x = x + 3 ;} else {n=n-1; 8|Page
  • 9. x=x-1; }gotoxy(10,x) ; cout <<chr ; gotoxy(13,5) ; sound(200) ; delay(30) ; nosound() ; } } while (( ch1 != 13 ) && ( ch2 != 13 )) ; if (n == 1) { char filename[13] ; strcpy(filename,sub_menu()) ; if (strcmp(filename,"null")) { quiz q ; q.play(filename) ; clrscr() ; } } if (n == 2) { char filename[13] ; strcpy(filename,sub_menu()) ; if (strcmp(filename,"null")) { textmode(C80) ; clrscr() ; quiz q ; q.add(filename) ; textmode(C40) ; clrscr() ;} } if (n == 3) edit_menu() ; } while ( n != 4 ) ; textmode(C80) ; clrscr() ; } //********************************************************** // CLASS NAME : menu // FUNCTION NAME : edit_menu // DETAILS : IT CREATES THE EDIT MAIN MENU //********************************************************** void menu :: edit_menu(void) { lines line ; int valid ; static int n = 3 ; static int x = 19 ; char ch1, ch2 ; char chr1=219, chr=175 ; 9|Page
  • 10. do { line.box(19,14,31,20,218) ; gotoxy(21,15) ; cout <<chr1 ; textbackground(WHITE) ; textcolor(BLACK) ; gotoxy(22,15) ; cprintf("E D I T ") ; textbackground(BLACK) ; textcolor(LIGHTGRAY) ; gotoxy(23,17) ; cout <<"DELETE" ; gotoxy(23,18) ; cout <<"MODIFY" ; gotoxy(23,19) ; cout <<"RETURN" ; gotoxy(20,x) ; cout <<chr ; gotoxy(21,15) ; do { do { do { ch1 = getch() ; if ( ch1 == 27 ) { gotoxy(1,15) ; clreol() ; gotoxy(1,17) ; clreol() ; gotoxy(1,18) ; clreol() ; gotoxy(1,19) ; clreol() ; gotoxy(1,20) ; clreol() ; gotoxy(19,14) ; clreol() ; return ; } } while (( ch1 != 0 ) && ( ch1 != 13 )) ; if ( ch1 != 13 ) { do { ch2 = getch() ; if ( ch2 == 27 ) { gotoxy(1,15) ; clreol() ; gotoxy(1,17) ; clreol() ; gotoxy(1,18) ; clreol() ; gotoxy(1,19) ; clreol() ; gotoxy(1,20) ; clreol() ; gotoxy(19,14) ; clreol() ; 10 | P a g e
  • 11. return ; } } while (( ch2 != 72 ) && ( ch2 != 80 ) && ( ch2 != 13 )) ; }} while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ; if (( ch1 == 0 ) && ( ch2 == 80 )) { gotoxy(20,x) ; cout <<" " ; if (n == 3) { n=1; x=x-2; } else { n=n+1; x=x+1; } gotoxy(20,x) ; cout <<chr ; gotoxy(21,15) ; sound(200) ; delay(30) ; nosound() ; } if (( ch1 == 0 ) && ( ch2 == 72 )) { gotoxy(20,x) ; cout <<" " ; if ( n == 1 ) { n=3; x=x+2;} else { n=n-1; x=x-1;} gotoxy(20,x) ; cout <<chr ; gotoxy(21,15) ; sound(200) ; delay(30) ; nosound() ; } } while (( ch1 != 13 ) && ( ch2 != 13 )) ; if (n == 1) { char filename[13] ; strcpy(filename,sub_menu()) ; if (strcmp(filename,"null")) { textmode(C80) ; clrscr() ; quiz q ; q.deletion(filename) ; 11 | P a g e
  • 12. textmode(C40) ; clrscr() ; return ; } clrscr() ; return ;} else if (n == 2) { char filename[13] ; strcpy(filename,sub_menu()) ; if (strcmp(filename,"null")) { textmode(C80) ; clrscr() ; quiz q ; q.modify(filename) ; textmode(C40) ; clrscr() ; return ; } clrscr() ; return ; } } while ( n != 3 ) ; gotoxy(1,15) ; clreol() ; gotoxy(1,17) ; clreol() ; gotoxy(1,18) ; clreol() ; gotoxy(1,19) ; clreol() ; gotoxy(1,20) ; clreol() ; gotoxy(19,14) ; clreol() ;} //********************************************************** // CLASS NAME : menu // FUNCTION NAME : sub_menu // DETAILS : IT CREATES THE SUB MAIN MENU AND // RETURN FILE NAME //********************************************************** char *menu :: sub_menu(void) { lines line ; clrscr() ; int valid ; static int n = 1 ; static int x = 10 ; char ch1, ch2 ; char chr1=219, chr=175 ; line.box(1,1,39,25,219) ; line.line_hor(2,38,23,196) ; char c1=24, c2=25 ; 12 | P a g e
  • 13. gotoxy(3,24) ; cout <<c1 ; cout <<c2 ; cout <<"=Move <ENTER>=Select <ESC>=Exit" ; gotoxy(13,6) ; cout <<chr1 ; textbackground(WHITE) ; textcolor(BLACK) ; gotoxy(14,6) ; cprintf("S U B - M E N U ") ; textbackground(BLACK) ; textcolor(LIGHTGRAY) ; line.box(11,5,31,7,218) ; gotoxy(14,10) ; cout <<"COMPUTERS" ; gotoxy(14,12) ; cout <<"MATHEMATICS" ; gotoxy(14,14) ; cout <<"SCIENCE" ; gotoxy(14,16) ; cout <<"GENERAL" ; gotoxy(14,18) ; cout <<"RETURN" ; gotoxy(12,x) ; cout <<chr ; gotoxy(13,6) ; do { do { do { ch1 = getch() ; if ( ch1 == 27 ) { clrscr() ; return("null") ; } } while (( ch1 != 0 ) && ( ch1 != 13 )) ; if ( ch1 != 13 ) { do { ch2 = getch() ; if ( ch2 == 27 ) { clrscr() ; return("null") ; } } while (( ch2 != 72 ) && ( ch2 != 80 ) && ( ch2 != 13 )) ; } 13 | P a g e
  • 14. } while ((( ch1 != 0 ) || (( ch2 != 72 ) && ( ch2 != 80 ))) && (( ch1 != 13 ) && ( ch2 != 13 ))) ; if (( ch1 == 0 ) && ( ch2 == 80 )) { gotoxy(12,x) ; cout <<" " ; if (n == 5) { n=1; x=x-8;} else { n=n+1; x = x + 2 ;} gotoxy(12,x) ; cout <<chr ; gotoxy(13,6) ; sound(200) ; delay(30) ; nosound() ; } if (( ch1 == 0 ) && ( ch2 == 72 )) { gotoxy(12,x) ; cout <<" " ; if ( n == 1 ) { n=5; x = x + 8 ;} else { n=n-1; x = x - 2 ;} gotoxy(12,x) ; cout <<chr ; gotoxy(13,6) ; sound(200) ; delay(30) ; nosound() ; } } while (( ch1 != 13 ) && ( ch2 != 13 )) ; clrscr() ; if (n == 1) return("computer.dat") ; else if (n == 2) return("maths.dat") ; else if (n == 3) return("science.dat") ; else 14 | P a g e
  • 15. if (n == 4) return("general.dat") ; return("null") ;} //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : record_count // DETAILS : IT RETURNS THE NO. OF RECORD IN THE // GIVEN FILE //********************************************************** int quiz :: record_count(char filename[13]) { fstream file ; file.open(filename, ios::in) ; file.seekg(0,ios::beg) ; int t=0 ; while (file.read((char *) this, sizeof(quiz))) t++ ; file.close() ; return t ;} //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : add // DETAILS : IT ADDS THE RECORDS IN THE GIVEN FILE //********************************************************** void quiz :: add(char filename[13]) { lines line ; int valid ; int t_ques_no ; t_ques_no = record_count(filename) ; t_ques_no++ ; if (t_ques_no == 1) { ques_no = t_ques_no ; strcpy(ques,"abc") ; strcpy(ans1,"-") ; strcpy(ans2,"-") ; strcpy(ans3,"-") ; sol = '0' ; fstream file ; file.open(filename, ios::out | ios::app ) ; file.write((char *) this, sizeof(quiz)) ; file.close() ; delete_record(filename,t_ques_no) ; } 15 | P a g e
  • 16. char ch ; do{ clrscr() ; line.box(1,1,79,23,218) ; gotoxy(3,5) ; cout <<"question # " <<t_ques_no ; gotoxy(3,8) ; cout <<"question : " ; gotoxy(3,10) ; cout <<"answer 1 : " ; gotoxy(3,12) ; cout <<"answer 2 : " ; gotoxy(3,14) ; cout <<"answer 3 : " ; gotoxy(3,16) ; cout <<"solution : " ; do { line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(1,25) ; clreol() ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER QUESTION" ; gotoxy(14,8) ; gets(ques) ; strupr(ques) ; if (ques[0] == '0') return ; if (strlen(ques) > 159 || strlen(ques) == 0) { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; cout <<"LENGTH SHOULD NOT BE BLANK OR GREATER THAN 159" ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(1,24) ; clreol() ; gotoxy(1,25) ; clreol() ; gotoxy(14,8) ; clreol() ; } 16 | P a g e
  • 17. } while ( !valid ) ; do { line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(1,25) ; clreol() ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER ANSWER FOR THE QUESTION" ; gotoxy(14,10) ; gets(ans1) ; strupr(ans1) ; if (ans1[0] == '0') return ; if (strlen(ans1) > 49) { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; cout <<"LENGTH SHOULD NOT GREATER THAN 49" ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(1,24) ; clreol() ; gotoxy(1,25) ; clreol() ; gotoxy(14,10) ; clreol() ; } } while ( !valid ) ; do { line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(1,25) ; clreol() ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER ANSWER FOR THE QUESTION" ; gotoxy(14,12) ; gets(ans2) ; strupr(ans2) ; if (ans2[0] == '0') return ; if (strlen(ans2) > 49) 17 | P a g e
  • 18. { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; cout <<"LENGTH SHOULD NOT GREATER THAN 49" ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(1,24) ; clreol() ; gotoxy(1,25) ; clreol() ; gotoxy(14,12) ; clreol() ;} } while ( !valid ) ; do{ line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(1,25) ; clreol() ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER ANSWER FOR THE QUESTION" ; gotoxy(14,14) ; gets(ans3) ; strupr(ans3) ; if (ans3[0] == '0') return ; if (strlen(ans3) > 49) { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; cout <<"LENGTH SHOULD NOT GREATER THAN 49" ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(1,24) ; clreol() ; gotoxy(1,25) ; clreol() ; gotoxy(14,14) ; clreol() ; } } while ( !valid ) ; do{ line.box(1,1,79,23,218) ; 18 | P a g e
  • 19. valid = 1 ; gotoxy(1,25) ; clreol() ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER CORRECT SOLUTION FOR THE QUESTION (1/2/3)" ; gotoxy(14,16) ; sol = getche() ; if (sol == '0') return ; if (sol != '1' && sol != '2' && sol != '3') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(14,16) ; clreol() ;} } while ( !valid ) ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; clreol() ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,19) ; cout <<"Do you want to save the record (y/n) : " ; do{ line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(42,19) ; ch = getche() ; ch = toupper(ch) ; if (ch == '0') return ; if (ch != 'Y' && ch != 'N') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(42,19) ; clreol() ; } } while ( !valid ) ; if (ch == 'Y') { ques_no = t_ques_no ; fstream file ; file.open(filename, ios::app ) ; file.write((char *) this, sizeof(quiz)) ; 19 | P a g e
  • 20. file.close() ; t_ques_no++ ; } gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,21) ; cout <<"Do you want to add more questions (y/n) : " ; do { line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(45,21) ; ch = getche() ; ch = toupper(ch) ; if (ch == '0') return ; if (ch != 'Y' && ch != 'N') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(45,21) ; clreol() ;}} while ( !valid ) ; } while (ch == 'Y') ;} //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : found_record // DETAILS : IT SEARCH THE GIVEN RECORDS IN THE // GIVEN FILE AND RETURN 0 IF NOT FOUND //********************************************************** int quiz :: found_record(char filename[13], int t_ques_no) { fstream file ; file.open(filename, ios::in) ; file.seekg(0,ios::beg) ; int found=0 ; while (file.read((char *) this, sizeof(quiz))) {if (t_ques_no == ques_no) { found++ ; break ;} } file.close() ; return found ;} //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : display_record // DETAILS : IT DISPLAY THE RECORD FOR THE GIVEN // QUESTION NO. FROM THE GIVEN FILE 20 | P a g e
  • 21. //********************************************************** void quiz :: display_record(char filename[13], int t_ques_no) { fstream file ; file.open(filename, ios::in) ; file.seekg(0,ios::beg) ; while (file.read((char *) this, sizeof(quiz))) { if (t_ques_no == ques_no) { gotoxy(3,3) ; cout <<"question # " <<t_ques_no ; gotoxy(3,7) ; cout <<"question : " <<ques ; gotoxy(3,8) ; cout <<"answer 1 : " <<ans1 ; gotoxy(3,9) ; cout <<"answer 2 : " <<ans2 ; gotoxy(3,10) ; cout <<"answer 3 : " <<ans3 ; break ;}} file.close() ;} //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : delete_record // DETAILS : IT DELETE THE RECORD FOR THE GIVEN // QUESTION NO. FROM THE GIVEN FILE //********************************************************** void quiz :: delete_record(char filename[13], int t_ques_no) { fstream file ; file.open(filename, ios::in) ; fstream temp ; temp.open("temp.dat", ios::out) ; file.seekg(0,ios::beg) ; while (!file.eof()) { file.read((char *) this, sizeof(quiz)) ; if ( file.eof() ) break ; if (ques_no != t_ques_no) temp.write((char *) this, sizeof(quiz)) ; } file.close() ; temp.close() ; file.open(filename, ios::out) ; temp.open("temp.dat", ios::in) ; temp.seekg(0,ios::beg) ; 21 | P a g e
  • 22. t_ques_no = 1 ; while (!temp.eof()) { temp.read((char *) this, sizeof(quiz)) ; ques_no = t_ques_no ; if (temp.eof()) break ; file.write((char *) this, sizeof(quiz)) ; t_ques_no++ ; } file.close() ; temp.close() ;} //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : deletion // DETAILS : IT GIVE THE QUESTION NO. TO DELETE // RECORD FROM THE GIVEN FILE //********************************************************** void quiz :: deletion(char filename[13]) { lines line ; clrscr() ; int valid ; int t_ques_no=0, t; char t1_ques_no[5] ; char ch ; line.box(1,1,79,23,218) ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,3) ; cout <<"Enter question no. to be deleted : " ; do { gotoxy(38,3) ; gets(t1_ques_no) ; } while (strlen(t1_ques_no) == 0) ; t = atoi(t1_ques_no) ; t_ques_no = t ; if (t1_ques_no[0] == '0') return ; if (!found_record(filename,t_ques_no)) { sound(500) ; delay(100) ; nosound() ; gotoxy(3,15) ; cout <<"question not found" ; 22 | P a g e
  • 23. line.line_hor(1,79,24,196) ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; return ; } clrscr() ; line.box(1,1,79,23,218) ; display_record(filename,t_ques_no) ; gotoxy(3,12) ; cout <<"Do you want to delete this Record (y/n) : " ; do {valid = 1 ; gotoxy(45,12) ; ch = getche() ; ch = toupper(ch) ; if (ch != 'Y' && ch != 'N') {valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(45,10) ; clreol() ;} } while (!valid ) ; if (ch == 'N') return ; gotoxy(1,25) ; cout <<"Wait..." ; delete_record(filename,t_ques_no) ; clrscr() ; sound(500) ; delay(100) ; nosound() ; gotoxy(3,14) ; cout <<"Record Deleted" ; line.line_hor(1,79,24,196) ; gotoxy(1,25) ; cout <<"Press any key to continue...." ; getch() ;} //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : modify_record // DETAILS : IT MODIFY THE RECORD FOR THE GIVEN // QUESTION NO. FROM THE GIVEN FILE //********************************************************** void quiz :: modify_record(char filename[13], int t_ques_no) 23 | P a g e
  • 24. { lines line ; int valid, modified=0 ; char ch ; line.line_hor(2,78,12,196) ; line.box(1,1,79,23,218) ; gotoxy(3,14) ; cout <<"QUESTION # " <<t_ques_no ; gotoxy(3,16) ; cout <<"QUESTION : " ; gotoxy(3,17) ; cout <<"ANSWER 1 : " ; gotoxy(3,18) ; cout <<"ANSWER 2 : " ; gotoxy(3,19) ; cout <<"ANSWER 3 : " ; gotoxy(3,20) ; cout <<"SOLUTION : " ; gotoxy(1,25) ; clreol() ; line.line_hor(1,79,23,196) ; gotoxy(14,16) ; cout <<"Change (y/n) " ; do { line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(28,16) ; ch = getche() ; ch = toupper(ch) ; if (ch != 'Y' && ch != 'N') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(28,16) ; clreol() ; } } while (!valid) ; valid = 0 ; while (!valid && ch == 'Y') { line.box(1,1,79,23,218) ; modified = 1 ; valid = 1 ; gotoxy(14,16) ; clreol() ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; 24 | P a g e
  • 25. cout <<"ENTER QUESTION" ; gotoxy(14,16) ; gets(ques) ; strupr(ques) ; if (ques[0] == '0') return ; if (strlen(ques) >159 || strlen(ques) == 0) { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; cout <<"LENGTH SHOULD NOT BLANK OR GREATER THAN 159" ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(1,24) ; clreol() ; gotoxy(1,25) ; clreol() ; gotoxy(14,16) ; clreol() ;} } gotoxy(1,25) ; clreol() ; gotoxy(14,17) ; cout <<"Change (y/n) " ; do{line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(28,17) ; ch = getche() ; ch = toupper(ch) ; if (ch != 'Y' && ch != 'N') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(28,17) ; clreol() ; } } while (!valid) ; valid = 0 ; while (!valid && ch == 'Y') { line.box(1,1,79,23,218) ; modified = 1 ; valid = 1 ; gotoxy(13,17) ; clreol() ; gotoxy(72,25) ; 25 | P a g e
  • 26. cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER ANSWER FOR THE QUESTION" ; gotoxy(14,17) ; gets(ans1) ; strupr(ans1) ; if (ans1[0] == '0') return ; if (strlen(ans1) > 49) { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; cout <<"LENGTH SHOULD NOT GREATER THAN 49" ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(1,24) ; clreol() ; gotoxy(1,25) ; clreol() ; gotoxy(14,17) ; clreol() ;} } gotoxy(1,25) ; clreol() ; gotoxy(14,18) ; cout <<"Change (y/n) " ; do{line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(28,18) ; ch = getche() ; ch = toupper(ch) ; if (ch != 'Y' && ch != 'N') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(28,18) ; clreol() ;} } while (!valid) ; valid = 0 ; while (!valid && ch == 'Y') { line.box(1,1,79,23,218) ; modified = 1 ; valid = 1 ; gotoxy(14,18) ; clreol() ; 26 | P a g e
  • 27. gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER ANSWER FOR THE QUESTION" ; gotoxy(14,18) ; gets(ans2) ; strupr(ans2) ; if (ans2[0] == '0') return ; if (strlen(ans2) > 49) { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; cout <<"LENGTH SHOULD NOT GREATER THAN 49" ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(1,24) ; clreol() ; gotoxy(1,25) ; clreol() ; gotoxy(14,18) ; clreol() ;} } gotoxy(1,25) ; clreol() ; gotoxy(14,19) ; cout <<"Change (y/n) " ; do { line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(28,19) ; ch = getche() ; ch = toupper(ch) ; if (ch != 'Y' && ch != 'N') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(28,19) ; clreol() ;} } while (!valid) ; valid = 0 ; while (!valid && ch == 'Y') { line.box(1,1,79,23,218) ; modified = 1 ; 27 | P a g e
  • 28. valid = 1 ; gotoxy(14,19) ; clreol() ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER ANSWER FOR THE QUESTION" ; gotoxy(14,19) ; gets(ans3) ; strupr(ans3) ; if (ans3[0] == '0') return ; if (strlen(ans3) > 49) { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; cout <<"LENGTH SHOULD NOT GREATER THAN 49" ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(1,24) ; clreol() ; gotoxy(1,25) ; clreol() ; gotoxy(14,19) ; clreol() ;} } if (!modified) return ; do{ line.box(1,1,79,23,218) ; gotoxy(1,25) ; clreol() ; valid = 1 ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,25) ; cout <<"ENTER CORRECT SOLUTION FOR THE QUESTION (1/2/3)" ; gotoxy(14,20) ; sol = getche() ; if (sol == '0') return ; if (sol != '1' && sol != '2' && sol != '3') { valid = 0 ; sound(500) ; delay(100) ; 28 | P a g e
  • 29. nosound() ; gotoxy(14,20) ; clreol() ;} } while (!valid) ; gotoxy(1,25) ; clreol() ; gotoxy(1,24) ; clreol() ; gotoxy(1,22) ; cout <<"Do you want to save the record (y/n) : " ; do { line.box(1,1,79,23,218) ; valid = 1 ; gotoxy(41,22) ; ch = getche() ; ch = toupper(ch) ; if (ch != 'Y' && ch != 'N') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(41,22) ; clreol() ; } } while ( !valid ) ; if (ch == 'N') return ; fstream file ; file.open(filename, ios::out | ios::ate) ; int recno ; recno = t_ques_no ; int location ; location = (recno-1) * sizeof(quiz) ; file.seekp(location) ; file.write((char *) this, sizeof(quiz)) ; file.close() ; clrscr() ; sound(500) ; delay(100) ; nosound() ; gotoxy(1,14) ; cout <<"Record Modified" ; line.line_hor(1,79,24,196) ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; } //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : modify // DETAILS : IT GIVE THE QUESTION NO. TO MODIFY 29 | P a g e
  • 30. // RECORD FROM THE GIVEN FILE //********************************************************** void quiz :: modify(char filename[13]) { lines line ; clrscr() ; int valid ; int t_ques_no=0, t; char t1_ques_no[5] ; char ch ; line.box(1,1,79,23,218) ; gotoxy(72,25) ; cout <<"<0>=EXIT" ; gotoxy(3,3) ; cout <<"Enter question no. to be modify : " ; do { gotoxy(38,3) ; gets(t1_ques_no) ; } while (strlen(t1_ques_no) == 0) ; t = atoi(t1_ques_no) ; t_ques_no = t ; if (t1_ques_no[0] == '0') return ; if (!found_record(filename,t_ques_no)) { sound(500) ; delay(100) ; nosound() ; gotoxy(3,15) ; cout <<"question not found" ; line.line_hor(2,78,24,196) ; gotoxy(1,25) ; cout <<"Press any key to continue..." ; getch() ; return ; } clrscr() ; display_record(filename,t_ques_no) ; gotoxy(3,12) ; cout <<"Do you want to modify this Record (y/n) : " ; do { valid = 1 ; gotoxy(45,12) ; ch = getche() ; ch = toupper(ch) ; if (ch != 'Y' && ch != 'N') { valid = 0 ; sound(500) ; 30 | P a g e
  • 31. delay(100) ; nosound() ; gotoxy(45,10) ; clreol() ;} } while (!valid ) ; if (ch == 'N') return ; modify_record(filename,t_ques_no) ; } //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : display_score // DETAILS : IT DISPLAY THE SCORE FOR THE GIVEN // PLAYER'S NAME //********************************************************** void quiz :: display_score(char name[20], int played, int correct) { clrscr() ; lines line ; line.box(1,1,39,25,218) ; line.box(2,2,38,24,219) ; textbackground(WHITE) ; textcolor(BLACK+BLINK) ; gotoxy(5,4) ; cprintf(" ") ; gotoxy(9,4) ; cprintf("S C O R E B O A R D") ; textbackground(BLACK) ; textcolor(LIGHTGRAY) ; gotoxy(5,7) ; cout <<"Player's Name : " <<name ; gotoxy(5,9) ; cout <<"questions Attempted : " <<played ; gotoxy(5,11) ; cout <<"Correct answer : " <<correct ; gotoxy(5,13) ; cout <<"Wrong answer : " <<played-correct ; int score ; score = correct * 10 ; gotoxy(5,16) ; cout <<"Score : " <<score ; int tplayed ; tplayed = played * 10 ; float percentage ; percentage = ((score*100)/tplayed) ; 31 | P a g e
  • 32. gotoxy(5,18) ; cout <<"Percentage : " <<percentage ; getch() ; } //********************************************************** // CLASS NAME : quiz // FUNCTION NAME : play // DETAILS : IT CREATES SCREEN FOR PLAYING QUIZ // TO THE PLAYER FOR THE GIVEN FILE NAME // AND KEEP SCORE. //********************************************************** void quiz :: play(char filename[13]) { clrscr() ; int valid ; lines line ; char name[20] ; gotoxy(3,3) ; cout <<"Enter your name : " ; do { line.box(1,1,39,25,219) ; valid = 1 ; gotoxy(30,24) ; cout <<"<0>=EXIT" ; gotoxy(21,3) ; gets(name) ; strupr(name) ; if (name[0] == '0') return ; if (strlen(name) > 18) { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(30,24) ; cout <<" "; gotoxy(3,23) ; cout <<"LENGTH SHOULD NOT GREATER THAN 18" ; gotoxy(3,24) ; cout <<"Press any key to continue..." ; getch() ; gotoxy(3,23) ; cout <<" "; gotoxy(3,24) ; 32 | P a g e
  • 33. cout <<" "; gotoxy(21,3) ; cout <<" " ;} } while ( !valid ) ; char t_sol, ch ; int correct=0, played=0 ; fstream file ; file.open(filename,ios::in) ; file.seekg(0,ios::beg) ; while (file.read((char *) this, sizeof(quiz))) { clrscr() ; line.box(1,1,39,25,219) ; gotoxy(25,3) ; cout <<"SCORE:" <<correct*10 ; valid = 1 ; gotoxy(28,24) ; cout <<"<ESC>=Exit" ; gotoxy(3,4) ; cout <<"question # " <<ques_no ; gotoxy(3,6) ; cout <<"question : " <<ques ; gotoxy(3,10) ; cout <<"answer 1 : " <<ans1 ; gotoxy(3,11) ; cout <<"answer 2 : " <<ans2 ; gotoxy(3,12) ; cout <<"answer 3 : " <<ans3 ; gotoxy(3,14) ; cout <<"Enter correct solution : " ; int i=0, j=0, time=10 ; do { valid = 1 ; gotoxy(3,21) ; cout <<"Time : " <<time ; gotoxy(28,12) ; do { delay(1) ; i++ ; j++ ; if (j == 600) { j=0; time-- ; gotoxy(11,21) ; cout <<" " ; 33 | P a g e
  • 34. gotoxy(10,21) ; cout <<time ; gotoxy(28,14) ;} } while (!kbhit() && i<6000) ; if (i >= 6000) { played++ ; sound(500) ; delay(100) ; nosound() ; gotoxy(13,16) ; cout <<"Sorry Time up!" ; gotoxy(1,1) ; getch() ; if (played) display_score(name,played,correct) ; return ;} gotoxy(3,21) ; cout <<" "; gotoxy(28,12) ; t_sol = getche() ; if (t_sol == 27) { if (played) display_score(name,played,correct) ; return ; } if (t_sol != '1' && t_sol != '2' && t_sol != '3') { valid = 0 ; sound(500) ; delay(100) ; nosound() ; gotoxy(28,12) ; cout <<" " ; } } while (!valid) ; played++ ; if (t_sol != sol) { sound(500) ; delay(100) ; nosound() ; gotoxy(14,16) ; cout <<"wrong answer" ; gotoxy(13,17) ; cout <<"Correct answer : " <<sol ; gotoxy(1,1) ; 34 | P a g e
  • 35. ch = getch() ; gotoxy(14,15) ; cout <<" "; gotoxy(13,16) ; cout <<" "; gotoxy(3,24) ; cout <<" ";} else { correct++ ; sound(500) ; delay(100) ; nosound() ; gotoxy(16,16) ; cout <<"GOOD ! CORRECT ANSWER" ; gotoxy(25,3) ; cout <<"SCORE:" <<correct*10 ; gotoxy(1,1) ; ch = getch() ; } if (ch == 27) { display_score(name,played,correct) ; return ; } } gotoxy(3,22) ; cout <<"No more questions available" ; getch() ; if (!played) return ; display_score(name,played,correct) ; } //********************************************************** // FUNCTION NAME : main // DETAILS : IT CALLS THE START FUNCTION AND // MENU FUNCTION. //********************************************************** void main(void) { menu m ; m.start() ; m.main_menu() ; } //********************************************************** // END OF PROJECT //********************************************************** 35 | P a g e
  • 36. OUTPUT 36 | P a g e
  • 37. 37 | P a g e
  • 38. 38 | P a g e
  • 39. 39 | P a g e