I'm trying to solve this exercise:
The Dice class manages the launch of 2 dice.
- A) The constructor receives two optional parameters with the initial value for the given 1 and the given 2 respectively. If the dice do not receive an initial value, it will be assigned to 1. Error control: if any initial value is not correct, the assigned value will be equal to 1.
- B) Observer get (). It will have 2 parameters. The identifier of the die (1 or 2) and a reference to an integer that will store the corresponding die value. Error control: if there is an error with the identifier of the die, get () must return false, otherwise get () returns true.
I have doubts in the bool-type observer, since I do not understand how I can return true or false in addition to the object.
This is the class:
class Dados{
private:
int dado1_, dado2_;
public:
Dados(int valor1=1, int valor2=1){
if (valor1>=1 && valor1<=6)
{
dado1_=valor1;
}
else dado1_=1;
if (valor2>=1 && valor2<=6)
{
dado2_=valor2;
}
else dado2_=1;
}
I tried to make the observer like that, but I do not return dice1_ or dado2_:
bool get(int dado,int valor)
{
if (dado>=1 && dado<=2)
{
return true;
}
else
{
return false;
}
}
Thank you!