Question: In c++ Program : Simulating Dice with Objects Dice traditionally have six sides, representing the values 1 to 6. Some games, however, use specialized dice

In c++

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

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!