Question: 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
This is a comprehensive task involving objectoriented programming to create classes that simulate rolling dice including a normal sixsided die and a l... View full answer
Get step-by-step solutions from verified subject matter experts
