Starting from:

$25

CS1570 - HW4 - Solved

This file is 9 pages long, but don’t worry, 5 of those pages are sample output

 

Link:

https://docs.google.com/document/d/1Ca2OSGi0Ze93PMGFKU1vs-d5jKgv9zqM0 G1uApt8AFk/edit?usp=sharing



Documentation Header Reminder

Before you start your assignment, you will need to add documentation similar to what we demonstrated in the first few lectures.

Function Prototype Documentation Reminder

In the function prototype section of your C++ program, remember to add documentation to each function similar to what was demonstrated in lectures.

Separate File Compilation

For this assignment (and onward), you will submit multiple C++ compilable files containing a program written in C++. Name your file a meaningful name and give it a proper extension (.h, .hpp, .cpp). Also, make sure that you compile and run your program using the GNU (g++) compiler before submitting to make sure that it will work.

Background:

After twelve long years of sending in video interviews and applications, you’ve finally been accepted to compete on your favorite game show, “Are You

Smarter than a Comp Sci?”. Here is how the game works in brief:

1.      You are asked ten multiple choice trivia questions back to back. Each question will have four options.

2.      You start with $100.

3.      Every time you answer a question correctly, multiply your winnings by two. Every time you get a question wrong, you lose $100.

4.      If you answer three questions incorrectly, you immediately lose, and you walk away with $0.

5.      You are given three lifelines. These will allow you to call a friend, who has an 80% chance of answering the question correctly, and a 20% chance of picking a random answer.

Specifications

All of the following functions must be implemented. You may add more or use different parameters if you like, unless specifically stated otherwise. Variable names may be different in your code. Return types and parameter types are up to your own discretion.

greeting()

-          This function outputs a greeting message to the user.

printQuestion(questionNumber)

-          This function outputs a single multiple choice question, as well as the 4 options for answers. Remember, the questions should be asked in order, from

1 to 10.

isCorrect(questionNumber, userAnswer)

-          This function returns whether or not the user answered the question correctly, based on the question number, and what the user input as their answer. If no user answer is passed as a parameter, use a default parameter to set the user answer equal to 3.

lifeLine(questionNumber)

-          This function has an 80% chance of outputting the correct answer to the current question to the user, and a 20% chance of outputting a randomly selected answer from the other 3 options. This function may only be called 3 times. To ensure this, you must use a static variable inside of this function.

answerRandomly()

-          This function generates a random value between 1 and 4.

leave()

-          This function allows the user to leave with their current winnings, and ends the game. No more questions will be displayed to the user.

exitMessage(winLoseOrLeave, winnings)

-          This function prints an exit message to the user, along with their winnings. This function should be called after the user wins the game, loses the game, or decides to leave the game prematurely.

-          //The “winLoseOrLeave” parameter should hold the information that contains whether the user won, lost, or left.

updateMoney(currentMoney, isCorrect)

-          This function needs to be a templated function. It will multiply the current pool of money by 2 if the user answered the question correctly, and subtract it by 100 if the user answered the question incorrectly. This function must be set up so that currentMoney can be ANY numeric data type.

Overall Program Flow
1.      Greet the User

2.      Ask the user the first question

3.      Get input from the user (1, 2, 3, 4, random, lifeline, or leave).

4.      If the user chose 1, 2, 3, or 4, output whether they were right or not. If they chose the random or the lifeline option, output the randomly generated answer to the question, and take their input again. If they chose a lifeline but they have no lifelines left, print a message to the user stating this fact instead of generating an answer. If the user picks leave, print an exit message to the user.

5.      If the user did not leave or get 3 losses, repeat with the next question.

6.      Continue this cycle until the user loses, leaves, or all 10 questions have been asked.

7.      Print an exit message to the user, stating whether they won, lost, or left, and output their winnings.

Notes
●     You can use the sample questions in the file provided, but the answers to the questions must be the same (i.e. the answer to question 1 must be 3 regardless of what the question is, the answer to question 2 must be 2 regardless of what the question is, etc.)

●     Link:

https://docs.google.com/document/d/1pBsBBXetGy1beBNg7hjB10CRYLLk-a N1J9P0UWyA5wk/edit?usp=sharing

Sample Output 1
Welcome to Are you Smarter than a Comp Sci! Ready to play?

Question 1 Which of these is not a numeric data type?

1 - integer 2 - double

3   - boolean

4   - float

3

Correct!

Question 2 Which of the following is a reserved c++ keyword?

1   - buddy

2   - friend

3   - pal4 - homeslice

lifeline

Your friend said the answer is 2. What is your answer?

random

You thought of the number 1. What is your answer? random

You thought of the number 2. What is your answer?

3

Incorrect! You have 2 lives remaining.

Question 3 What does the & symbol mean in C++?

1   - address of

2   - and

3   - not4 - value of lifeline

Your friend said the answer is 1. What is your answer?

lifeline

Your friend said the answer is 2. What is your answer?

1

Correct!

Question 4 You do not need to document your functions in CS1570

1   - true

2   - false

3   - sometimes

4   - I don’t know

1

Incorrect! You have 1 life remaining.

Question 5 What is “OOP”?

1 - Only Once Programming

2 - Object Oriented Programming3 - What I say when I stub my toe 4 - Ope, oh peanuts.

lifeline

You are out of lifelines! What is your answer?

2

Correct!

Question 6 How many significant digits can a float have?

1   - 9

2   - 8

3   - 7

4   - 6

4

Correct!

Question 7 If C is 3, then C++ is:

1   - An object oriented programming language

2   - 4

3   - Amazing

4   - All of the above

4

Correct!

Question 8 What is the maximum value of a signed integer in C++?

1   - 81

2   - 2147483647

3   - 11

4   - -12

2

Correct!

Question 9 What does == do in C++?

1   - Sets the left variable equal to the right value

2   - Checks the validity of a data type in C++

3   - Checks if 2 values are equal to each other

4   - All of the above

3

Correct!

Question 10 Can you lose money in this game show?

1   - Yes

2   - No

3   - Don’t pick this one

4   - Don’t pick this one either

1

Correct!

Congratulations! You won $6400! Thanks for playing!

Sample Output 2

Welcome to Are you Smarter than a Comp Sci! Ready to play?

Question 1 Which of these is not a numeric data type?

1 - integer 2 - double

3   - boolean

4   - float

1

Incorrect! You have 2 lives remaining.

Question 2 Which of the following is a reserved c++ keyword?

1   - buddy

2   - friend

3   - pal

4   - homeslice

1

Incorrect! You have 1 life remaining.

Question 3 What does the & symbol mean in C++?

1   - address of

2   - and

3   - not4 - value of leave

You walked out with -$100.

Sample Output 3
Welcome to Are you Smarter than a Comp Sci! Ready to play?

Question 1 Which of these is not a numeric data type?

1 - integer 2 - double

3   - boolean

4   - float

1

Incorrect! You have 2 lives remaining.

Question 2 Which of the following is a reserved c++ keyword?

1   - buddy

2   - friend

3   - pal

4   - homeslice

1

Incorrect! You have 1 life remaining.

Are you Smarter than a Comp Sci?

Question 3 What does the & symbol mean in C++?

1   - address of

2   - and

3   - not

4   - value of

2

Incorrect! You have 0 lives remaining.

You lost, and walked away with $0.

More products