Problem 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 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. swapAnswers(a, b) Swaps two answers given two numbers a and b. Note that a and b are not indexes. a and b can be any integers. Use % to convert a and b into a value between 0 and 3, then swap the answers at these two positions. 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 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 . 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. For each question it should shuffle the answers by swapping first with second and third with fourth answers. Then it should 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 questio questions.txt  What do you use to measure an angle? Compass Protractor Ruler T-Square B The Great Sphinx has the head of a human and the body of a what? Camel Eagle Lion Alligator C What is the flat rubber disc used in a game of ice hockey? Birdie Dart Tile Puck D What is the slowest wind speed a hurricane can have according to the Saffir-Simpson scale? 50 mph 74 mph 96 mph 110 mph B Which two planets have the most similar sized diameters? Mars and Mercury Venus and Earth Uranus and Neptune Jupiter and Saturn B

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

Problem

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

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.
  • swapAnswers(a, b) Swaps two answers given two numbers a and b. Note that a and b are not indexes. a and b can be any integers. Use % to convert a and b into a value between 0 and 3, then swap the answers at these two positions. 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 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 . 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. For each question it should shuffle the answers by swapping first with second and third with fourth answers. Then it should 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 questio

questions.txt 

What do you use to measure an angle?
Compass
Protractor
Ruler
T-Square
B
The Great Sphinx has the head of a human and the body of a what?
Camel
Eagle
Lion
Alligator
C
What is the flat rubber disc used in a game of ice hockey?
Birdie
Dart
Tile
Puck
D
What is the slowest wind speed a hurricane can have according to the Saffir-Simpson scale?
50 mph
74 mph
96 mph
110 mph
B
Which two planets have the most similar sized diameters?
Mars and Mercury
Venus and Earth
Uranus and Neptune
Jupiter and Saturn
B

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
User Defined DataType
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