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. Design 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 all the answers down 1 position and puts the last answer in the first position. So, after this function call, the first answer will be the former last answer, the second answer will be the former first answer, the third answer will be the former second one and the fourth(last) answer will be the former third one. 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 ltter for the question at index i). Put a period and space after each letter. Return the string. The member variables should be private and the member functions should do no input or output. Design and implement a driver with a main function that uses the Question class. This driver should create an array of 5 Question objects. The main function should read from input a filename (called "questions.txt" in which the questions are stored. When the main function starts, it should try to open the file using the filenmae it read from the input. If the file exists, it should be assumed that the file contains the 5 trivia questions with answer choices and the key for each question. If the file does not exist, exit with an error message. 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. It should accept the uppercase or lowercase version of they key as being correct.
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.
Design 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 all the answers down 1 position and puts the last answer in the first position. So, after this function call, the first answer will be the former last answer, the second answer will be the former first answer, the third answer will be the former second one and the fourth(last) answer will be the former third one. 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 ltter for the question at index i). Put a period and space after each letter. Return the string.
The member variables should be private and the member functions should do no input or output.
Design and implement a driver with a main function that uses the Question class. This driver should create an array of 5 Question objects. The main function should read from input a filename (called "questions.txt" in which the questions are stored. When the main function starts, it should try to open the file using the filenmae it read from the input. If the file exists, it should be assumed that the file contains the 5 trivia questions with answer choices and the key for each question. If the file does not exist, exit with an error message.
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. It should accept the uppercase or lowercase version of they key as being correct.
Sample execution:



Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 7 images









