#include #include #include using namespace std; void OpenFile(/* out */ ifstream & instr); void Get_Number_Of_Questions(/* inout */ ifstream & ifstr, int & NQ); void Ask_Questions(ifstream & instr, int NQ ,int & CA); void Print_Score(int NumberOfQuestions,int CorrectAnswers); int main () { ifstream infile; int NumberOfQuestions; int CorrectAnswers; OpenFile(infile); Get_Number_Of_Questions(infile,NumberOfQuestions); Ask_Questions(infile,NumberOfQuestions,CorrectAnswers); Print_Score(NumberOfQuestions,CorrectAnswers); return 0; } void OpenFile(ifstream & instr){ string InFileName; cout << "Enter the name of a quiz file " ; cin >> InFileName; instr.open(InFileName.c_str()); return; } void Get_Number_Of_Questions(ifstream & ifstr, int & NQ) { ifstr >> NQ; return; } void Grade_Question(int CorrectAnswer,int Response,int & CA){ if (CorrectAnswer == Response) { CA ++; } return; } void Read_Question_Stats(ifstream & instr, int & Number, int & Right) { instr >> Number; instr >> Right; instr.ignore(80,'\n'); return; } void Ask_Question(ifstream & infile) { string Question; getline(infile, Question); cout << Question << endl ; return; } void Give_Answers(ifstream & infile, int NumberOfAnswers){ int i; string Answer; i = 1; while (i <= NumberOfAnswers) { getline(infile, Answer); cout << "\t\t" << i << "..." << Answer<< endl; i++; } } void Get_Response(int NumberOfAnswers, int & Response){ Response = 0; while ((Response <1) || (Response >NumberOfAnswers)) { cout << "Your Answer (1.." << NumberOfAnswers << "): "; cin >> Response; } return; } void Ask_Questions(ifstream & instr, int NQ ,int & CA){ int Question = 0; int NumberOfAnswers, CorrectAnswer, Response; CA = 0; while (Question < NQ) { Read_Question_Stats(instr, NumberOfAnswers, CorrectAnswer); Ask_Question(instr ); Give_Answers(instr, NumberOfAnswers); Get_Response(NumberOfAnswers, Response); Grade_Question(CorrectAnswer, Response,CA); Question ++; } return; } void Print_Score(int NumberOfQuestions,int CorrectAnswers){ cout << "You got " << CorrectAnswers << " out of " << NumberOfQuestions << " Correct " << endl; return; }