Question: C++ program 1. (10 points) Coin Toss Simulator Write a class named Coin . The Coin class should have the following private member variables: sideUp

C++ program

1. (10 points) Coin Toss Simulator

Write a class named Coin. The Coin class should have the following private member variables:

sideUp a string holding either Heads or Tails indicating the side of the coin facing up.

sideUpLetter a char holding either H or T mirroring sideUp.

playerName a string holding the name of the player tossing the coin.

The Coin class should have the following public member functions:

Default constructor that randomly determines the side of the coin facing up (Heads or Tails), initializing sideUp, sideUpLetter and playerName variables accordingly.

A void member function named toss that simulates the tossing of a coin. When the toss function is called, it randomly determines the side of the coin that is facing up (Heads or Tails) and sets the sideUp and sideUpLetter variables accordingly.

string and char member functions named getSideUp and getsideUpLetter, respectively, that return the value of the appropriate member variables.

string getName member function to return the name of the player.

Test your Coin class by writing a program that demonstrates its operation as follows:

Your program should ask for three players names (specifically you will use your first name and 2 friends) from the console to be used with 3 instances of the class (such as Player1, Player2 and Player3) created by the test program. It also displays which side is up initially.

Then the program runs 2 separate loops with all 3 players in each loop. In both loops, the coin is tossed, the side facing up display updates and the program keeps a count of the number of times heads faces up and tails faces up. At the end of execution, these will be displayed with each players name.

The difference between the loops is that the first is executed 20 times: each players resulting flips are arranged in a column. The first row contains the three names; the second the result of the first flip for each player (e.g., Heads or Tails); the ensuing 19 rows, similarly; and the last row a H/T count summary.

The second loop is executed 100 times: each players resulting flips are arranged in a several rows. The row for each player begins with their name, a colon and space (e.g., :_); followed by the result of the 100 flips (e.g., H or T); and finally a H/T count summary.

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!