Question: In C++ Dice class int numberSides int rollDice() Returns a random number between 1 and numberSides Virtual? Constructor(s) int rollTwoDice(const Dice& dice1, const Dice& dice2)

In C++

Dice class

int numberSides

int rollDice()

Returns a random number between 1 and numberSides

Virtual?

Constructor(s)

int rollTwoDice(const Dice& dice1, const Dice& dice2) { return die1.rollDice() + die2.rollDice(); } 

LoadedDice class, derived from Dice class

Default constructor

Constructor that takes one int as argument

Argument is the numberSides

Override rollDice() function

50% chance return numberSides

50% chance same as Dice's rollDice() function

int main() { srand(1); Dice dice1(6), dice2(12); LoadedDice loadedDie1(6), loadedDie2(24); cout << "die1 + die2 = " << rollTwoDice(die1, die2) << endl; cout << "die1 + loadedDie1 = " << rollTwoDice(die1, loadedDie1) << endl; cout << "loadedDie1 + die2 = " << rollTwoDice(loadedDie1, die2) << endl; cout << "loadedDie1 + loadedDie2 = " << rollTwoDice(loadedDie1, loadedDie2) << endl; } 

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!