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.
Your 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started