In: Computer Science
Complete the following...
Submit:
//diceType.h (header file)
#ifndef H_diceType
#define H_diceType
class diceType
{
public:
diceType();
// Default constructor
// Sets numSides to 6 with a random numRolled from 1 - 6
diceType(int);
// Constructor to set the number of sides of the dice
int roll();
// Function to roll a dice.
// Randomly generates a number between 1 and numSides
// and stores the number in the instance variable numRolled
// and returns the number.
int getNum() const;
// Function to return the number on the top face of the dice.
// Returns the value of the instance variable numRolled.
private:
int numSides;
int numRolled;
};
#endif // H_diceType
============================================
//diceTypeImp.cpp (implementatio file)
//Implementation File for the class diceType
#include
#include
#include
#include "diceType.h"
using namespace std;
diceType::diceType()
{
srand(time(nullptr));
numSides = 6;
numRolled = (rand() % 6) + 1;
}
diceType::diceType(int sides)
{
srand(time(0));
numSides = sides;
numRolled = (rand() % numSides) + 1;
}
int diceType::roll()
{
numRolled = (rand() % numSides) + 1;
return numRolled;
}
int diceType::getNum() const
{
return numRolled;
}
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
diceType.h
#ifndef DICETYPE_H_
#define DICETYPE_H_
#include
#include
#include
#include
template
class diceType
{
public:
diceType();
// Default constructor
// Sets numSides to 6 with a random numRolled from 1 -
6
diceType(int);
// Constructor to set the number of sides of the
dice
Type roll();
// Function to roll a dice.
// Randomly generates a number between 1 and
numSides
// and stores the number in the instance variable
numRolled
// and returns the number.
Type getNum() const;
// Function to return the number on the top face of
the dice.
// Returns the value of the instance variable
numRolled.
Type getType(int);
Type getType(char);
private:
int numSides;
Type numRolled;
};
#endif /* DICETYPE_H_ */
diceTypeImp.cpp
#include "diceType.h"
using namespace std;
template
diceType
{
srand(time(nullptr));
numSides = 6;
numRolled = (rand() % 6) + 1;
}
template
Type diceType
return i;
}
template
Type diceType
return 'A'+i-1;
}
template
diceType
{
srand(time(0));
numSides = sides;
numRolled = (rand() % numSides) + 1;
numRolled=getType(numRolled);
}
template
Type diceType
{
numRolled = (rand() % numSides) + 1;
numRolled=getType(numRolled);
return numRolled;
}
template
Type diceType
{
return numRolled;
}
main.cpp
#include
#include
#include "diceType.h"
#include "diceTypeImp.cpp"
using namespace std;
int main () { }
diceType
cout<<"Rolling int dice..."<
cout<
diceType
cout<<"Rolling char dice..."<
cout<
return 0;
}