Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribedYour 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

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

Real Time Database Systems Architecture And Techniques

Authors: Kam-Yiu Lam ,Tei-Wei Kuo

1st Edition

1475784023, 978-1475784022

More Books

Students also viewed these Databases questions