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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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:

 

1. What do you use to measure an angle?
A. Protractor
B. Ruler
C. T-Square
D. Compass
Your answer (enter the letter): A
2. The Great Sphinx has the head of a human and the body of a what?
A. Eagle
B. Lion
C. Alligator
D. Camel
Your answer (enter the letter): B
3. What is the flat rubber disc used in a game of ice hockey?
A. Dart
B. Tile
C. Puck
D. Birdie
Your answer (enter the letter): D
4. What is the slowest wind speed a hurricane can have according to the Saffir-Simpson scale?
A. 74 mph
B. 96 mph
C. 110 mph
D. 50 mph
Your answer (enter the letter): B
Transcribed Image Text:1. What do you use to measure an angle? A. Protractor B. Ruler C. T-Square D. Compass Your answer (enter the letter): A 2. The Great Sphinx has the head of a human and the body of a what? A. Eagle B. Lion C. Alligator D. Camel Your answer (enter the letter): B 3. What is the flat rubber disc used in a game of ice hockey? A. Dart B. Tile C. Puck D. Birdie Your answer (enter the letter): D 4. What is the slowest wind speed a hurricane can have according to the Saffir-Simpson scale? A. 74 mph B. 96 mph C. 110 mph D. 50 mph Your answer (enter the letter): B
5. Which two planets have the most similar sized diameters?
A. Venus and Earth
B. Uranus and Neptune
C. Jupiter and Saturn
D. Mars and Mercury
Your answer (enter the letter): a
Answers:
A B C A A
Your score out of 5: 3
Transcribed Image Text:5. Which two planets have the most similar sized diameters? A. Venus and Earth B. Uranus and Neptune C. Jupiter and Saturn D. Mars and Mercury Your answer (enter the letter): a Answers: A B C A A Your score out of 5: 3
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 7 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education