Question
Program : Simulating Dice with Objects Dice traditionally have six sides, representing the values 1 to 6. Some games, however, use specialized dice that have
Program :
Simulating Dice with Objects
Dice traditionally have six sides, representing the values 1 to 6. Some games, however, use specialized dice that have a different number of sides. For example, the fantasy role-playing game Dungeons and Dragons uses dice with four, six, eight, ten, twelve, and twenty sides. Suppose you are writing a program that needs to roll simulated dice with various numbers of sides. A simple approach would be to write a Die class with a constructor that accepts the number of sides as an argument. The class would also have appropriate methods for rolling the die and getting the dies value. Write a program that defines a class die. There are 2 member variables of type int. sides an int variable that will hold the number of sides for the die. (for this pgrm assume the die has either 6 or 12 sides).
value an int variable that will hold the dies value once it has been rolled. Constructor -The constructor should get the system time and use that number to seed the random number generator. The constructor accepts an arguments for the number of sides of the die and performs an initial roll(). Roll The roll member function simulates the rolling of the die. The random number generator should be executed returning a random number within the range for this particular die. getsides member function returns the sides member variable. getvalue member function returns the value member variable.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started