Answered step by step
Verified Expert Solution
Question
1 Approved Answer
******************************Complete this program in C++********************************* This assignment requires you to write a program to generate a multiple-choice exam. The file, questions.txt, contains a set of
******************************Complete this program in C++*********************************
This assignment requires you to write a program to generate a multiple-choice exam. The file, questions.txt, contains a set of multiple-choice questions. Each question has exactly four responses. The following shows the layout of each item of data that is stored for a question: Data Item ID Text Responses Description Question ID (a string without spaces on a line by itself) The actual question on a line by itself (a string that could contain spaces) Four responses, each on a line by itself, followed by the correct response on a line by itself, followed by 1 or 0 where 1 indicates that the responses should be shuffled and O indicates otherwise. The amount of points gained if the question is correctly answered. Points For example, here is the data for one of the questions in questions.txt Data Popeye Which of the following gives Popeye his strength? Broccoli Spinach Fried chicken All of them. Spinach 1 1 Description ID of question Question text Choice 1 Choice 2 Choice 3 Choice 4 Correct answer 1: shuffle responses; O: don't shuffle If correctly answered, 1 mark is awarded Program Requirements Your program must provide the following functionality: (a) Read all the questions from the file, questions.txt, and store them in an array. This array is referred to as the Question Bank. The file contains no more than 100 questions. (b) Create an array of exam questions by randomly selecting M questions (specified by the user) from the Question Bank. The array of exam questions is referred to as the Exam. When a question is selected from the Question Bank, the four responses must be shuffled, if necessary. (c) Allow a user to take the exam by presenting the questions from the exam, one by one. Three actions are possible when a question is displayed to the user: (1) the user answers the question correctly (ii) the user answers the question incorrectly the user skips the question A record must be kept of the user's performance on each question. (d) At the end of the examination, a summary of the user's performance is given. The summary displays how many responses were correct or incorrect and how many questions were skipped. The total marks obtained by the user is also displayed. 1 You should use the structs in Table 1 in your code: Description Contains the four responses for a question, the correct answer, and a variable indicating whether the responses should be shuffled after they are selected for an examination. Struct struct Responses string text(4); string answer; bool shuffle; }; struct Question { string ID; string text; Responses responses; int points; }; struct Summary { string questionID; bool correct; bool skipped; string answer, string givenAnswer, int points; }; Contains the ID of a question, the text of the question, a struct of Responses, and the amount of points that are gained by answering the question correctly. Contains the ID of a question attempted by the user, whether it was skipped or correctly answered by the user, and the amount of points obtained. If it was not skipped, stores the correct answer and the answer given by the user. Table 1: Structs to be used in Assignment 1 You may use additional fields in the structs or additional structs, if required. Organization of Your Program To simplify the development of the code for Assignment 1, a template, Assignment1.cpp, has been provided containing the structs described in the previous section as well as empty function bodies for the following functions. You do not have to use these functions in your code if you don't want to. int readQuestions (Question questionBank(1) This function reads all the questions from questions.txt into the Question Bank. It returns the amount of questions in the Question Bank. bool containsQuestion (Question exam[], int numExamQuestions, string questionID) Returns true if the exam already contains the question with the given questionID and false, otherwise. bool containsResponse (Responses responses, int numResponses, string response) Returns true if the set of responses already contains the given response, and false otherwise. 1 Question shuffleResponses (Question question) This function takes the question passed as a parameter, shuffles the responses if the responses can be shuffled, and returns the modified question. void prepareExam (Question questionBank [], int numQuestions, Question exam[], int numExamQuestions) Creates the exam containing numExamQuestions where the questions are taken from the Question Bank which contains numQuestions. void display ExamQuestion (Question question) While the exam is in progress, displays a question for the user to answer. void generateExam Question exam[], int numExamQuestions, Summary summary()) After the exam is generated, presents the questions on the exam to the user, one by one. Takes a note of how the user responded to each question, for the summary at the end. void displaySummary (Summary summary[], int numExamQuestions) Displays a summary of the user's performance on each question of the exam, after the exam is completed int main() Calls readQuestions, prepareExam, generateExam, and displaySummary. Selecting a Question from the Question Bank at Random Suppose there are N questions in the Question Bank and the exam must have M questions where MStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started