Question: #16 Coin Toss Simulator Your class code should be in a .h and .cpp file. You should also have a separate .cpp file with a

#16

Coin Toss Simulator

Your class code should be in a .h and .cpp file.

You should also have a separate .cpp file with a main in it.

Coin Toss Simulator. C++ Write a class named Coin. The Coin class should have the following member variables: A string named sideUp. The sideUp member variable will holder 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 and sets the sideUp member variable accordingly. A member function named getSideUp that returns the value of the sideUp member variable. Write a program that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up. Then, use a loop to toss the coin 20 times. Each time the coin is tossed, display the side that is facing up. The program should keep count of the number of times heads is facing up and the number of times tails is facing up, and display those values after the loop finishes.

Make sure to use Constants (or enums!) where appropriate (heads or tails may be a good example)

The name of your class should be Coin and the .cpp file with the main should be CoinTest.cpp

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!