Question: Coin.h (class specification file) Coin.cpp (class implementation file) 200_assign3.cpp (application program) Your solution should use all three files listed above. The Coin.h file (class specification

Coin.h (class specification file) Coin.cpp (class implementation file) 200_assign3.cpp (application program)

Your solution should use all three files listed above.

The Coin.h file (class specification file) should contain the class declaration, the declaration of the member variables, and prototypes for the constructor and the member functions. Nothing should be implemented in this file.

The Coin.cpp file (class implementation file) should contain the implementation of the constructor and the member functions.

The 200_assign3.cpp file (application program) should contain the game logic for the coin toss game.

The Coin class should have the following member variable:

A string named sideUp. The sideUp member variable will hold either heads or tails indicating the side of the coin that is facing up.

The Coin class 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 the sideUp member variable accordingly.

A void member function named toss that simulates the tossing of the coin. When the toss member function is called, it randomly determines the side of the coin that is facing up (heads or tails) and sets the sideUp member variable accordingly.

A member function named getSideUp that returns the value of the sideUp member variable.

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

Game Logic (200_assign3.cpp):

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

The player (you) and the computer both begin 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). The minimum amount that 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 one player 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 player with $1.10 wins.

As you will see from the sample runs, there is NO user 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 format shown 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.

NOTE: The first thing that you should do in your application program (200_assign3.cpp) is create three different Coin objects: one for the quarter, one for the dime, and one for the nickel. Remember that both the player and the computer toss the same coins, so only a total of three Coin objects are needed.

Sample Run 1:

Coin.h (class specification file) Coin.cpp (class implementation file) 200_assign3.cpp (application program) Your

Sample Run 2:

solution should use all three files listed above. The Coin.h file (class

Sample Run 3:

specification file) should contain the class declaration, the declaration of the member

Sample Run 4:

variables, and prototypes for the constructor and the member functions. Nothing should

Sample Run 5:

be implemented in this file. The Coin.cpp file (class implementation file) should

Your starting balance: $e.e0 The computer's starting balance: $e.e0 Your balance after round 1: $0.40 The computer's balance after round 1: $0.15 Your balance after round 2: $0.40 The computer's balance after round 2: $0.20 Your balance after round 3: $0.45 The computer's balance after round 3: $e.35 Your balance after round 4: $0.55 The computer's balance after round 4: $0.7e Your balance after round 5: $e.70 The computer's balance after round 5: $0.70 Your balance after round 6: $0.85 The computer's balance after round 6: $e.80 Your balance after round 7: $1.1e The computer's balance after round 7: $1.10 Your ending balance: $1.10 The computer's ending balance: $1.10 Tie! Nobody wins. Press any key to continue

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!