This is what the class implementations should be for both classes Die class: Imp
ID: 3901790 • Letter: T
Question
This is what the class implementations should be for both classes
Die class: Implements the logic for a die that when rolled produces a random value between 1 and numSides. Implementation instructions: ? Default constructor should make a 6 sided die. ? Any newly constructed die should have a random value between 1 and numSides. ? roll() should pick a new random value ? setValue(int) will be force a particular value for testing purposes
ThreeDicePoker class: Implements the logic for a game where a player rolls three dice, then can chose to reroll 0-3 three of the dice. They they get points according to this logic: ? Three of a kind (all the same value) – 1000 pts ? 3 in a row (like 1,2,3 or 3,4,5) – 400 pts ? Two of a kind (two that match and one that does not) – 40 x the matched value i.e. 3, 3, 5 would score 40 x 3 or 120pts ? Otherwise – 10 x the highest die i.e. 2, 3, 5 would score 10 x 5 or 50pts. Implemenetaion instructions: ? getDieValue and rollDie take a die number 0, 1 or 2 and either return the current value or roll the die ? rollAll() rolls all three dice ? getScore returns the score that would be awarded for the current three values on the dice ? setDie(int dieNumber, int value) will be used for testing the scoring
Explanation / Answer
#include "die1.h"
Die::Die(){
numSides = 6;
value = 1;
}
Die::Die(int a){
numSides = a;
value = 1;
}
Die::roll(){
srand(time(NULL));
value = rand() % numSides + 1;
}
Die::getValue(){
return value;
}
Die::setValue(int a){
value = a;
return value;
}
ThreeDicePoker::ThreeDicePoker(){
dice[0].setValue(1);
dice[1].setValue(1);
dice[2].setValue(1);
}
int ThreeDicePoker::getDieValue(int dieNumber){
return dice[dieNumber].getValue();
}
void ThreeDicePoker::rollDie(int dieNumber){
dice[dieNumber].roll();
}
void ThreeDicePoker::rollAll(){
dice[0] = dice[0].roll();
dice[1] = dice[1].roll();
dice[2] = dice[2].roll();
}
void ThreeDicePoker::setDie(int dieNumber, int value){
dice[dieNumber].setValue(value);
}
int getScore(){
int a = dice[0].getValue();
int b = dice[1].getValue();
int c = dice[2].getValue();
if (a == b && b == c) {
return 1000;
}
else if (a < b < c || a < c < b || b < a < c || b < c < a || c < a < b || c < b < a){
return 400;
}
else if (a == b || b == c || a == c){
int d = 0;
if (a == b)
d = a;
if (b == c)
d = b;
if (a == c)
d = a;
return 40 * d;
}
else {
int max = 0;
if (a > b && a > c)
max = a;
if (b > a && b > c)
max = b;
if (c > a && c > b)
max = c;
return 10 * max;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.