Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

============================================================================= -- The Coin.h file (class specification file) should contain the class declaration, the declaration of the member variables, and prototypesfor the constructorand the member

=============================================================================

-- The Coin.h file (class specification file) should contain the class declaration, the declaration of the member variables, and prototypesfor the constructorand the member functions.Nothing should be implemented in this file. -- The Coin.cpp file (class implementation file) should contain the implementationof the constructor andthemember functions. -- The 3.cpp file (application program) should contain the game logicfor the coin toss game.

========================================================== The Coin class should have the following member variable: ==========================================================

~ A stringnamedsideUp. ThesideUpmember variable will hold either heads or tails indicating the side of the coin that is facing up.

~ The Coinclass should have the following member functions:

~ A default constructor that randomly determines the side of the coin that is facing up (heads or tails) and initializes thesideUpmember variable accordingly. ~ A voidmember function namedtossthat simulates the tossing of the coin. When thetossmember function is called, it randomly determines the side of the coin that is facing up (heads or tails) and sets thesideUpmember variable accordingly.

~ A member function namedgetSideUpthat returns the value of thesideUpmember variable.

UML Diagramfor the Coin class: Coin ======================================================== -sideUp: string // Stores either heads or tails ======================================================== <> +Coin() +toss() +getSideUp(): string ========================================================

~The game works as follows (as you will see in the sample runs below):

The player (you) and the computerbothbegin with a starting balance of $0.00. For each round of the game, both the player and the computer toss a quarter, a nickel, and a dime. For each type of coin, if the coin lands on heads, the amount of the coin is added to the players balance. If the coin lands on tails, however, nothing is added to the players balance for that coin.

~ For example: The player gets heads for the quarter, heads for the dime, and tails for the nickel. $0.25 + $0.10 = $0.35 is added to the players balance for that round. The computer gets tails for the quarter, tails for the dime, and heads for the nickel. $0.05 is added to the computers balance for that round. The maximum amount that can be added to a players balance in a single round is $0.25 + $0.10 + $0.05 = $0.40 (heads for all three coins). Theminimum amountthat can be added to a players balance in a single round is $0.00 (tails for all three coins).

The game ends when at least oneplayer has a balance of $1.00 or more. The following are conditions for win/loss/tie:

-If both players have the same balance at the end, they tie (note that this means both players not only have the same score, but their shared score is $1.00 or more) -If one player has a balance of less than $1.00 when the game ends, the other player who has a balance of $1.00 or more wins. For example, if the player has $0.90 and the computer has $1.05, the computer with $1.05 wins(remember its not possible for both players to have less than $1.00 when the game ends) -If both players have a balance of $1.00 or more, the player with the lower score wins. For example if the player ends the game with $1.10, and the computer ends the game with $1.30, the playerwith $1.10wins.

As you will see from the sample runs, there is NOuser input for this game. Again, the game automatically ends when one or both players have a balance of $1.00 or more.The output of your program should follow the same formatshown in the sample runs below. In particular, at the beginning of the program, the starting balance for both the player and the computer should be displayed. Then after the three coins have been tossed for both the player and the computer, the balance for both the player and the computer should be displayed. At the end of the program, the ending balance for both the player and the computer should be displayed. Finally, the outcome of the game (player won, computer won, or tie) should be displayed.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions

Question

29ofH2 16g of O2 109 of CH4 20 of of N2

Answered: 1 week ago