Write a die class with a constructor that accepts the


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 die's 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.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write a die class with a constructor that accepts the
Reference No:- TGS02900749

Expected delivery within 24 Hours