Dice()No arguments – The number of sides shoulddefault to 6. The face values arr
ID: 3619402 • Letter: D
Question
Dice()No arguments– The number of sides shoulddefault to 6. The face values array should be allocated with values1-6, and the current index should default to 0.
Dice(int sideCt) Number ofSides – Thenumber of sides should be set to the parameter value. The facevalues array should be allocated with values 1-Number Of Sides. Thecurrent index should default to 0.
Dice (int sideCt, int initIndex) Number ofSides and Starting Index – The number of sides should be set tothe parameter value. The face values array should be allocated withvalues 1-Number of Sides.The current index should be set to theStarting Index.
Dice (int *arrayValues, int sideCt) Arrayof Face Values and Number of Sides – The number of sides should be set tothe parameter value. A new face values array should be allocatedand the values of the Array of Face Values should be copied in. Thecurrent index should default to 0.
introll(); -- Rolls thedice and returns the showing value
intgetCurrentValue() const; -- Returns the current faceValue of thedice
intgetValue(int faceIndex) const; -- Return the value at the givenindex
void setValue(int faceIndex, intvalue); -- Sets thevalue ate the given index
int* getSides() const;-- Returns a deep-copy of thefaceValues array. Caller has the owningpointer
void setSides(int newValues[], int length,int startIndex=0); -- Makes a deep-copy of the newValues andstores the values as the faceValues
void setSides(int sides, intstartIndex=0); --Allocates a new array of faceValues of lengthsides.
intgetNumOfSides() const; -- Returns the number of sides of thisdice
intadd(const Dice &other) const; -- Sums the faceValue with other's faceValueand returns the result
Explanation / Answer
please rate - thanks you don't initialize anything in private. the initializations are done in the constructors message me if this isn't what you're looking for Should look similar to: #ifndef DICE_H#define DICE_H
class Dice
{
private:
int currentValue;
int numOfSides;
int *faceValue; //points to the dynamically allocated array
public:
Dice ()
{ currentValue=0;
numOfSides=6;
faceValue=new int[6];
faceValue[0]=1;
faceValue[1]=2;
faceValue[2]=3;
faceValue[3]=4;
faceValue[4]=5;
faceValue[5]=6;
}
Dice (int *arrayValues, int sideCt, int initIndex);
int roll();
int getCurrentValue() const;
int getValue(int) const;
void setValue(int, int);
int* getSides() const; //Dont know if this is done write.
void setSides(int [], int, int);
void setSides(int, int);
int getNumOfSides() const;
int add(const Dice &) const; //Dont know if this is done right
int add(int) const;
};
#endif
Should look similar to:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.