Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

How have social technologies changed e-commerce?

Answered: 1 week ago

Question

Define Trade Mark.

Answered: 1 week ago

Question

What is cost plus pricing ?

Answered: 1 week ago

Question

1. What are the types of wastes that reach water bodies ?

Answered: 1 week ago

Question

=+Trainers from headquarters? Local trainers? Independent trainers?

Answered: 1 week ago