Question
C++ Hello, I've created the dice class and dice.cpp file for the following set of instructions, I only need help implemented the diceandanger.cpp and diceanddanger_test.cpp
C++
Hello, I've created the dice class and dice.cpp file for the following set of instructions, I only need help implemented the diceandanger.cpp and diceanddanger_test.cpp file....please feel free to make any changes....
With this program, you will begin the practice of breaking source code into distinct modules that are responsible for limited scopes of behavior and data. You will create the framework of a game that uses dice to generate random decisions. This game is called DiceAndDanger.cpp.
Create a class (header and implmentation files) named Dice that can be used to create objects that simulate the behavior of one or more Die. This class should be able to simulate a die with an arbitrary number of sides; for example, it should be able to simulate a three sided die or a 21 sided die.
This class must have at least two public methods:
void roll() - which will simulate rolling a die by returning a random number between 1 and N where N represents the number of sides on the die.
int read() - which will return the value showing on the "top" of the die. This value represents the number of "pips" on the face of the die considered to be the top. If you store the values of the faces of your die in an array, the top should be the first element.
int read(int n) - return the value associated with the nth side of the die.
Your class must have a default constructor that will create a die with 6 sides. It should also have a parameterized constructor which will take an argument that indicates the number of sides that the new die object should contain.
DiceAndDanger.cpp should contain two methods:
rollCharacter(int* attributeArray) which will use 6 rolls of an 18-sided die to determine each of the following character attributes: Strength, Constitution, Dexterity, Intelligence, Wisdom, Charisma.
printCharacter(int *attributeArray) which will print each of the characters attributes and the value rolled: Strength:17,Constitution:12,Dexterity:8,Intelligence:16,Wisdom:11,Charisma:4
After the first set of character attributes is generated, the program should ask:
"Roll another characer? (y/n): "
If yes, the program should re-roll the character. If no the program should exit.
#ifndef DICE_H_INCLUDED
#define DICE_H_INCLUDED
class Die
{
private:
int sides; // Number of sides
int value; // The die's value
public:
Die(); // Default Constructor
Dice(int s); //parameterized constructor
void roll(); // Rolls the die
int getSides(); // Returns the number of sides
int getValue(); // Returns the die's value
int getValue(int n) // Returns the die's value of nth side
};
#endif // DICE_H_INCLUDED
// Implememtation file for the Die class
#include
#include
#include "Dice.h"
using namespace std;
//*******************************************************
// The constructor accepts an argument for the number *
// of sides for the die, and performs a roll. *
//*******************************************************
Die::Die(int numSides)
{
// Get the system time.
unsigned seed = time(0);
// Seed the random number generator.
srand(seed);
// Set the number of sides.
sides = numSides;
// Perform an initial roll.
roll();
}
//*******************************************************
// The roll member function simulates the rolling of *
// the die. *
//*******************************************************
void Die::roll()
{
// Constant for the minimum die value
const int MIN_VALUE = 1; // Minimum die value
// Get a random value for the die.
value = (rand() % (sides - MIN_VALUE + 1)) + MIN_VALUE;
}
//*******************************************************
// The getSides member function returns the number of *
// for this die. *
//*******************************************************
int Die::getSides()
{
return sides;
}
//*******************************************************
// The getValue member function returns the die's value.*
//*******************************************************
int Die::getValue()
{
return value;
}
I need help with the methods mentioned above....and finally my main () function which should be the diceanddanger_test.cpp file, thank you in advance
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started