Question: Write a C++ program that will output multiple choice trivia questions. Part I: Design and implement a class called Question. The Question class contains the

Write a C++ program that will output multiple choice trivia questions.

Part I: 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 supplied 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.

display: Output the stem and answers (but not the key), each on a separate line. Output 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 after each letter!

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 on the class Tracs Website: QuestionTester.cpp to test your class. You may modify this file to do more testing if you like.

Part II:

Design and implement a driver QuizDriver.cpp. This driver should create an array of 5 Question objects (initialized using the data provided in the file questions.txt on the class Tracs website). Then it should output the five questions (using the display member function). It should number the questions 1 to 5, with a dot and space after each number. It should also output a blank line after each question. Then it should output the key to the quiz (labeled Answers), all on one line with spaces between the keys.

Sample output:

1. What name is given to half of a Byte (4 bits)?

A. Nibble

B. Ort

C. Scrap

D. Snippet

2. Which country is home to the Kangaroo?

A. China

B. India

C. Mexico

D. Australia

3. What do you use to measure an angle?

A. Compass

B. Protractor

C. Ruler

D. T-Square

NOTES: This program must be done in a Linux or Unix environment, using a command line compiler like g++. Do not use codeblocks, eclipse, or Xcode to compile.

Your program must compile and run, otherwise you will receive a score of 0. Note: your Question.h and Question.cpp files must compile with the provided QuestionTester.cpp file, without changing it!

Your program should NOT read the questions in from a file. You should copy the code from questions.txt into your driver. This is provided for your convenience.

Put a header comment at the top of each source file (not the makefile)!

The class declaration does not need comments (except for the header file). The function definitions in the *.cpp files DO need function header comments!!

Turn in four files: Question.h, Question.cpp, QuizDriver.cpp, makefile. See below for instructions on how to combine them into one zip file. Logistics: Since there are multiple files for this assignment, you need to combine them into one file before submitting them. You should use the zip utility from the Linux/Unix command line: [...]$zip assign4_xxxxx.zip Question.h Question.cpp QuizDriver.cpp makefile

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!