Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Students also viewed these Databases questions

Question

5. Arranging for the training facility and room.

Answered: 1 week ago

Question

1. Discuss the five types of learner outcomes.

Answered: 1 week ago