Problem

The following lists a Dice class that simulates rolling a die with a different number of s...

The following lists a Dice class that simulates rolling a die with a different number of sides. The default is a standard die with six sides. The rollTwoDice function simulates rolling two dice objects and returns the sum of their values. The srand function requires including cstdlib.

Write a main function that creates two Dice objects with a number of sides of your choosing. Invoke the rollTwoDice function in a loop that iterates ten times and verify that the functions are working as expected.

Next create your own class, LoadedDice, that is derived from Dice. Add a default constructor and a constructor that takes the number of sides as input. Override the rollDice function in LoadedDice so that with a 50% chance the function returns the largest number possible (i.e., numSides), otherwise it returns what Dice’s rollDice function returns.

Test your class by replacing the Dice objects in main with LoadedDice objects. You should not need to change anything else. There should be many more dice rolls with the highest possible value. Polymorphism results in LoadedDice’s rollDice function to be invoked instead of Dice’s rollDice function inside rollTwoDice.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 15