Write a class named Coin . 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. 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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 5PE: Using classes, design an online address book to keep track of the names, addresses, phone numbers,...
icon
Related questions
Question

Write a class named Coin . 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.
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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage