#include <iostream> #include <stdlib.h> #include <string> #include <conio.h> #include <fstream> using namespace std; class contest { private: double index; float x; char name[50]; char s[100],ans; public: contest() { x=0; } void init(); void define(); void display(); void clrscr(); }; void contest :: define() { ifstream in; char a; int i=0; in.open("questions.txt"); //opening file while(in.eof()==0) { in.getline(s, 150); //number of lines to read cout<<endl<<s; if(i==5) //if number of lines is equal to five skip next line { in.get(a); //inputting answer cout<<"\nans:"; cin>>ans;// input answer i=-1; //display question by questions if(ans==a)// if answer inputted is equal to value of a { x=x+5;//add plus 5 cout<<" *Correct.\n"; } else { cout<<" #Wrong.\n"; } } i++; } in.close();//close file } void contest :: init() //input students name and index number { cout<<"Sur Name:"; cin>>name; cout<<"Index Number:"; cin>>index; } void contest :: display() { cout<<"\n **Result:\n"; //display student's name and result cout<<"\t"<<name<<" you got total "<<x<<" marks, out of 50.\n"; } int main() { //clrscr(); contest r; cout<<" \t\t\t QUIZ \t Total Marks:50\n\n"; r.init(); cout<<" "<<endl; cout<<"\t 5 Marks Per Questions"; L: cout<<"\n\n\tSELECT YOUR CHOICE:\n" <<"\n\t*To start Quiz Press 1" <<"\n\t*To quit Press 0 :"; int c; cin>>c; switch(c) { case 1: r.define(); r.display(); break; case 0: exit(1); default: cout<<"invalid choice!"; goto L; } getch(); }
append
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)