Write a C++ program that will display multiple-choice trivia questions, accept the user’s answers, and provide a full key and a score at the end.

Question class Designs and implement a class called Question. The Question class contains the following information: a stem (the text of the trivia question), an array of 4 multiple choice answers (the text of each possible answer) the letter of the correct answer (A, B, C, or D), called the key. This class will be used to represent trivia questions in a trivia game. The following operations should be available for Question objects (use the provided names). . . .

Construct a Question with no values (use empty strings for stem and answers and ‘X’ for the key).

Construct a Question given its 3 components ().

setStem: Set the stem question. getStem : Return the stem question.

setAnswers: Set the 4 answers given an array. The answers will NOT include the letter (A, B, C, or D).

getAnswer(i) : Return the single answer at index i.

setKey: Set the key letter. getKey: Return the key letter.

cycle(): It moves the first answer to the last position and moves all the other answers up to 1 position. So, after this function call, the first answer will be the last answer, the second answer will be the first, the third answer will be the second and the fourth(last) answer will be the third. (Tip: The easiest way to do this is: create a swap function that swaps two variables (or call the one in the algorithm library). Then, swap the first two answers, swap the next two answers, swap the last two answers). Don’t forget to update the key appropriately.

ask: Compose the stem and answers (but not the key), each on a separate line, as a string. Insert the letter A. before the first answer, B. before the second answer, and so on (you can use char(‘A’+i) to compute the letter for the question at index i). Put a period and space after each letter! Return the string.

Save the class declaration in Question.h and save the member function definitions in Question.cpp (do not inline the member function definitions). Use the driver, QuestionTester.cpp, in the downloadable files below to test your class. You may modify this file to do more testing if you like. Don’t change the names, parameters, or return values of these methods. Otherwise, you won’t be able to pass all tests. QuizDriver Design and implement a driver QuizDriver.cpp with the main function that uses the Question class. This driver should create an array of 5 Question objects. It should then read the data provided in the file questions.txt, using it to create Question objects and storing them in the array. Then call cycle once for each question. Then output each question (using the ask member function), numbering the questions 1 to 5. It should ask the user to enter the letter of their chosen answer. At the end of the quiz it should output the key to the quiz (labeled “Answers”), all on one line with spaces between the keys, and then output the number of correctly answered questions (see “Sample execution” section for more details). It should accept the uppercase or lowercase version of the key as being correct.

"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp