Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Dice class that simulates rolling a die with a different number of sides. The default is a standard die with six sides. You

Create a Dice class that simulates rolling a die with a different number of sides. The default is a standard die with six sides. You should have a default constructor that sets the number of sides to 6. You should have another constructor that creates a new instance of Dice with the number of sides in the argument. You should have one member function, Roll(), that rolls one die.

There are some firm physical constraints. For example, you cannot have a die with 0 or negative sides. Are there any other constraints you must validate?

Write a main function that creates two Dice objects with a number of sides of your choosing. Roll both dice and add the results. Roll the dice 10 times. Do the results make sense? Now create a class, LoadedDice that is derived from Dice. Override the Roll() function. For any result other than the number of sides there is a 5% chance a one will be added to the results. For example on a 6-sided die a roll of 1, 2, 3, 4, or 5 has a 5% chance of being 1 higher. A 6 is always a 6. You should still be able to create a LoadedDice object that has the default 6 sides, or the number specified when you call the constructor. Do you need to change or add anything else?

Test your class by adding code to roll dice with LoadedDice objects. You should not need to change anything else.

Test your program. How can you test it to ensure the distribution of results is higher for the loadedDice objects? Each class should be in its own file. Separate header files are not required for this lab but feel free to use them!

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions

Question

Which celebrity would you choose as a mentor?

Answered: 1 week ago