Test 1: Check correct assignment of dice values and selection (0/2) failed
#include <string>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <iomanip>
using namespace std;
//#################################################################################################
class Dice{
private:
int value;
public:
//Randomly assigns a value between from 1 to 6 to the dice.
void roll(){
value = rand() % 6 + 1;
}
int reveal() {return value;}
void setValue(int value) {this->value = value;}
};
//#################################################################################################
const int HAND_SIZE = 5;
class Hand {
public:
Dice dices[HAND_SIZE];
//Display the value of the five dice
void show(){
for(int i = 0; i < HAND_SIZE; i++){
cout << dices[i].reveal() << " ";
}
cout << endl;
}
void play(){
for(int i = 0; i < HAND_SIZE; i++){
dices[i].roll();
}
}
Dice* getDice(int diceNum){
if(diceNum >= 0 && diceNum < HAND_SIZE){
return &dices[diceNum];
}
return nullptr;
}
//selection is the string of dice numbers that the player wants to keep.
//For example, "125" means that player wants to keep the first, second, and fifth dice, and roll the rest.
void setSelection(string selection){
bool keep[HAND_SIZE] = {false};
for(char c : selection){
int index = c - '1';
if(index >= 0 && index < HAND_SIZE){
keep[index] = true;
}
}
for(int i = 0; i < HAND_SIZE; i++){
if(!keep[i]){
dices[i].roll();
}
}
}
Hand(){
for(int i = 0; i < HAND_SIZE; i++){
dices[i].roll();
}
}
private:
};
![Test 1: Check correct assignment of dice values and selection (0/2)
failed](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fd0dac0b6-5a17-4cd9-bac9-9e2e50ac9cbc%2F84c83af8-cfa8-4b00-8e46-836b1a46e0a5%2Fr0pkvgo_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)