Question: This assignment will exercise the use of OOP classes, accessor function, mutator functions, and arrays of objects. Write a program quiz generator program to help
This assignment will exercise the use of OOP classes, accessor function, mutator functions, and arrays of objects.
Write a program quiz generator program to help students study for quizzes and exams. The program must call a function that reads a set of multiple choice questions from a file, storing the questions in an array of object of the class Question. The class maintains the question text, an array of possible answers, and the correct answer.
After loading the questions, the program should loop through the array prompting the student with the question and checking the students answer. The program should indicate correct to the student, if the answer is correct, otherwise indicate incorrect and display the correct answer (see sample) below.
After all questions have been answered, the program should display the student score in points, and correct score percentage.
The question file format is as follows:
(1) question text?
first possible answer
second possible answer
third possible answer
fourth possible answer
fifth possible answer
x correct answer number.
(2) question text?
first possible answer
second possible answer
third possible answer
fourth possible answer
fifth possible answer
x correct answer number.
(n) question text?
first possible answer
second possible answer
third possible answer
fourth possible answer
fifth possible answer
x correct answer number.
Name your program lastNamePass4.cpp. Your program should meet the following requirements
main()
- Declare variables and Question array. Use a constant for the number_of_questions.
- Call initQuestions() function to load array with questions.
- Use a loop to prompt student with question and read answer.
- Call displayQuestion to display question.
- use cin >> ans to read student answer.
- If the answer is correct, display correct
- Else display incorrect and then display the correct answer.
- Increment array index and repeat loop until all questions
- After all questions have been issues, display student results.
initQuestions()
- Define a function (initQuestions()) that implements the following logic:
- Opens questions.txt and checks for a valid open issues error and exits if not successful.
- Uses a while loop to read the question text, five answers, and the correct answer number. Use setter methods to store the questions in a Question object array. Be certain to protect against data overrunning the array.
displayQuestion()
- Define a function (displayQuestion())) that displays the question text and possible answers. (See sample run for format).
Question Class
- Define a class called Question in its own header file Question.h. Be certain to create an include guard.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
