Question: In C++ You are writing some simple code to simulate rolling a die. The possible outcomes are the values 1 to 6. a) 6 points
In C++
You are writing some simple code to simulate rolling a die. The possible outcomes are the values 1 to 6. a) 6 points The Die class has these public behaviors: - construct a die object. Takes no parameters. - roll: rolls the die and returns the outcome. Outcomes 1 to 6 have an equal chance of occurring. - getRollCount: takes a value in the range 1 to 6 and returns how many times the die outcome was equal to that value. - getTotalRolls: returns how many times the die was rolled. Please give the interface and implementation of the Die class. b) 7 points You would like to simulate a loaded die. A loaded die has all the behaviors of a fair die but there is a difference. A loaded die has one preferred value which is not totally fair. All the values in the range 1 to 6 can occur by chance, but the preferred value is guaranteed to be the outcome whenever the previous roll's outcome was "one less".
E.g.: if the preferred value is 2, the die outcome will always be a 2 after a 1 roll. If the preferred value is 5, there will always be a 5 after a 4. If the preferred value is 1, there will always be a 1 after a 6. Here is a possible sequence of outcomes for a loaded die with a preference for 6: 3, 1, 1, 5, 6, 4, 5, 6, 2, 6, 3. The 6 outcomes after the 5 outcomes were guaranteed. The preferred value is specified in the constructor of the class. Please give the interface and implementation of the LoadedDie class. You should not have unnecessarily duplicate code. c) 4 points Please implement a function named rollDice which takes a vector of loaded dice and a positive integer count and rolls each die count times. The function returns nothing. Call your function from the main.
d) 3 points Please implement a function named rollDie which takes a pointer to a die, rolls it, and returns its outcome. The function should work as expected for both fair and loaded dice.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
