标签:iss bsp signed use bst setup ace actions down
CS132 – PROGRAMMING ASSIGNMENT #3
OVERVIEW
This activity is designed to have you work with strings as a data type, as well as having you create a
class and read from a data file.
INSTRUCTIONS
In this program you will be creating a program to play a trivia game. You will be provided with a data file that
contains over 200 questions, and you will need to create a game that allows the user to pick a number of trivia
questions and then determine if they are correct or now.
Each question will be stored internally as an object, and it will take control of the ability to determine if the chosen
answer is correct or not. It will also have a constructor to parse the input string and break it into its component
parts (Questions/correct answer/incorrect answers).
Your main program will take care of reading the file, creating the storage for all the questions, and asking the user
how many questions.
THE MAIN PROGRAM.
Your main program should do the following:
It should open up the data file ("TriviaData.txt") and take care of the strings in the file.
o The first line of the file is a single integer that tells how many questions are coming.
o Each remaining line is a single question with the answers following it.
Your program will then create a storage device to keep track of all the possible questions in either an
array or a vector. Note that this needs to be an array/vector of TrivaQuestion. NOT an array/vector of
strings, making this array is part of the grade for this assignment.
Once the data file is read and the questions are created it will ask the user how many questions they want
to try.
It should then ask the user random questions from the list depending on how many questions they
wanted.
o Note that the main program only starts the question, the question class will take care of itself.
The main program should record the number of answers they got right and determine the final score.
THE TRIVAQUESTION CLASS
For this assignment, you will create question class that handles all the actions for an individual question.
The methods that you will need are the following
TRIVAQUESTION()
You will want a default constructor that doesn’t do anything, but does allow the object to be created.
TRIVAQUESTION(STRING)
You will also want a constructor that allows for the user to create the object with the data string so that it can be
initialized if you so desire. This constructor will do the same thing as setup() below, but without having to be
called.
SETUP(STRING)
This method is an alternative to the string constructor. After creating the trivaQuestion you can pass a string
to it, to set up the question and the possible answer. Details on how to read the string are below.
ASKQUESTION()
This is the method that will print out the question, the possible answer, and wait for the user to type in what they
think the answer will be. If they type in the correct answer, it will return a value of 1, or if they get it wrong, it will
return a value of zero after telling the user what the correct answer was.
This method is entirely self-contained. It should ask the question and wait for the result. The main program will
not deal with the question at all.
Note that the possible answers should be in a random order. So that if I run the program multiple times, the same
answer is not always #1.
VALUES
Your program may have need of various other attributes/fields. But most of the time I would assume that you
would have 5 fields
The question string
The correct answer string
The 3 incorrect answer strings.
THE DATA
Each line of the data file except for the first is a single line that looks like the following
Which of the following did not feature in the cartoon ‘Wacky Races‘? :: "The Dragon Wagon" :: "The
Bouldermobile" :: "The Crimson Haybailer" :: "The Compact Pussycat"
You will note that the first part is the question and it ends with :: Following that is the correct answer. (The
correct answer is always the first possible answer). That is followed by another :: and then the three wrong
answers are also given with :: between them.
question = Which of the following did not feature in the cartoon ‘Wacky Races‘?
correct = "The Dragon Wagon"
incorrect1 = "The Bouldermobile"
incorrect2 = "The Crimson Haybailer"
incorrect3 = "The Compact Pussycat"
In your Trivia Question class, you will need to take this single string and break it down into the 5 component parts
by using string functions like find, substr, erase, and others.
Because the correct answer is always #1, it is important to rearrange the possible answers when you output them.
SAMPLE OUTPUT
Your final program should look something like this:
How many questions would you like to try?
> 2
For what reason would a spotted hyena "laugh"?
1. "Nervousness"
2. "Aggression"
3. "Exhaustion"
4. "Excitement"
Your answer please >> 1
Nice Job!!
Which Russian oblast forms a border with Poland?
1. "Nizhny Novgorod"
2. "Samara"
3. "Kaliningrad"
4. "Omsk"
Your answer please >> 4
Not quite right. The answer was : “Kaliningrad”
Your score was 1 correct for 50%.
SUBMISSION
You will be expected to turn in 3 files
main.cpp
TriviaQuestion.h
TriviaQuestion.cpp
Before submitting your assignment, include a comment at the beginning of your program with some basic
information and a description of the program in your own words. For example:
// Suzy Student, CS132, Autumn 2049, Section XX
// Programming Assignment #2, 06/07/49
//
// This program‘s behavior is ...
Make sure to comment appropriately and document all your major points.
PROGRAM NOTES
Read from the file first. Even if all you do is print it to the screen, get that working first.
Create the class and get it working in general before trying to parse the string.
The program is slightly easier if you can use and figure out vectors, but it works with arrays as well
Ask help before the due date.
A sample EXE file is provided so you can see what it is supposed to do.
To read the number from the file, followed by the lines, you will need to use a mix of >>, .ignore, and getline.
因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
微信:codinghelp
标签:iss bsp signed use bst setup ace actions down
原文地址:https://www.cnblogs.com/rrrrrhelper/p/10327719.html