Question: Polymorphic Dice This program will allow us to simulate dice rolls on the computer. Normally, we would want to make one function that takes as

Polymorphic Dice

This program will allow us to simulate dice rolls on the computer. Normally, we would want to make one function that takes as input the number of sides, but instead we will use dice as an example of polymorphism. All dice have one thing in common: they can be rolled, so we will have an abstract base type to allow us to make many different dice.

Polymorphic Dice This program will allow us to simulate dice rolls onYour program must: Use the Dice class below to create a series of subclasses representing dice with 4, 6, 8, 12, and 20 sides Ask the user for what dice they would like to roll, using dice notation o This means they request dice with an input of xdy, where x is the number of dice to roll, and y is the number of sides the die has o Reject invalid inputs Add the requested dice to a data structure of your choice that stores pointers to the Dice type Once the user is done adding dice, use the power of polymorphism to roll all the Dice in the structure to get the result without having to know what kind they are! Implement a rigged die of your choice Dice Class class Dice { public: virtual int Roll() = 0; };

Dice Class

class Dice {

public: virtual int Roll() = 0;

};

Example Input and Output Welcome to the Dice Rolling Program! what dice would you 1ike to ro11? 2d4 what dice would you like to ro11? 1d6 Any other dice (y)? n Result: 8 Press any key to continue .. . _

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!