Question: Overview For this assignment, implement and use the methods for a class called Die. Die class The Die class is used to represent a 6-sided

Overview

For this assignment, implement and use the methods for a class called Die.

Die class

The Die class is used to represent a 6-sided die.

Data Members

The class contains two data members.

An integer that holds the value of the side of the die that is up

An integer symbolic constant that holds the maximum number of sides on the die. Use a value of 6.

C++ 11 allows for symbolic constants to be initialized in the class definition. However, it's not something that is supported by all compilers because class definitions are treated as patterns for what the class should contain, and therefore, they don't take up any memory. To create a symbolic constant that will work for all compilers:

In the class definition, define the symbolic constant with the keyword "static" before the definition. So:

static const int NUM_SIDES;

Before main, initialize the symbolic constant with its value. So:

const int Die::NUM_SIDES = 6;

Note the dropping of the keyword "static" and the inclusion of the "Die::" in front of the constant name. This lets the compiler know that the constant belongs to the Die class.

Constructor

This class has one constructor, a default constructor (ie. one that takes no arguments). It should simply call the roll method that is described below to initialize the value of the side of the die that is up.

Methods

void roll()

This method simulates the rolling of the die. It takes no arguments and returns nothing.

The die will be "rolled" by using the rand() function to generate a random value for the side of the die that is up. The value should be between 1 and 6. Use the symbolic constant data member to help to limit the values. The result should be assigned to the integer data member.

int getValue()

This accessor method returns the current side of the die that is facing up. It takes no arguments and returns an integer.

Part 1: Testing the Die class

Before using the Die class as part of a larger project, it should be tested to make sure that the constructor and all of the methods work. A short program has been written that will test each one of the methods individually. You will NOT submit this program for grading.

The test program is shown below. scroll to the very bottom

The output that is produced by the test program:

The current side is 1

Roll 1:

You rolled a 2

Roll 2:

You rolled a 4

Roll 3:

You rolled a 6

Roll 4:

You rolled a 1

Roll 5:

You rolled a 3

Roll 6:

You rolled a 6

Roll 7:

You rolled a 4

Roll 8:

You rolled a 5

Roll 9:

You rolled a 1

Roll 10:

You rolled a 3

If the output, using your Die class, matches the above output, move on to part 2 of this assignment. Otherwise, fix the constructor/methods until the output does match.

Part 2: Using the Die class

This is the part of the assignment that will be submitted for grading.

For this part of the program, create a game that uses the Die class.

The concept of the game is fairly simple. The game uses two standard six-sided dice. A player places their wager on whether the sum total of numbers showing on the two dice will be even or odd. The dice are rolled and the winner is declared.

Implementing the game

Set the seed value that is used by the random number generator by using the srand() function. Pass the value time(NULL) to the srand function.

Create a 2 die objects that will be rolled by the dealer.

Ask the player for the number of times they would like to cast. Then ask the player to declare even or odd.

Write a loop that will execute the number of times the player wants to cast. Inside of the loop:

Roll the die objects.

Check if the sum of the die is even or add and the dealers or player's score according to what was rolled.

Once all of their casts have been used, display the final scores, and declare the winner (player or dealer).

Programming Requirements

Make sure to add #include statements for the cstdlib, ctime, and cstring libraries.

Each method must have a documentation box like a function.

Hand in a copy of the source code from part 2 of the assignment using Blackboard.

Output

A couple runs of the program might resemble the following but keep in mind that the random number generator is being used so your output will probably not match this output completely.

Run 1:

How many times do you want to play? 5

Even or odd (0 or 1)? 1

Roll 1:

Die 1: 3

Die 2: 4

You win!

Roll 2:

Die 1: 2

Die 2: 6

Dealer wins!

Roll 3:

Die 1: 1

Die 2: 4

You win!

Roll 4:

Die 1: 5

Die 2: 1

Dealer wins!

Roll 5:

Die 1: 3

Die 2: 5

Dealer wins!

Your final score is 2 points.

Dealers final score is 3 points.

Dealer Wins!

Run 2:

How many times do you want to play? 4

Even or odd (0 or 1)? 0

Roll 1:

Die 1: 3

Die 2: 4

Dealer wins!

Roll 2:

Die 1: 2

Die 2: 6

You win!

Roll 3:

Die 1: 1

Die 2: 4

Dealer wins!

Roll 4:

Die 1: 5

Die 2: 1

You win!

Your final score is 2 points.

Dealers final score is 2 points.

Its a tie!

Test program :

/*************************************************************** CSCI 240 Program 9 Spring 2016 Test the Die class ***************************************************************/ #include  #include  #include  #include  using namespace std; //********** Put the Die class definition after this line ********** int main() { //seed the random number generator //Note: this must be done before creating any Die class objects srand(5); //Create a Die class object and display the side that is currently up Die die1; cout << "The current side is " << die1.getValue(); //Roll the die 10 times to test the roll and getValue methods for( int cnt = 1; cnt <= 10; cnt++ ) { die1.roll(); cout << endl << endl << "Roll " << cnt << ":" << endl << "You rolled a " << die1.getValue() << endl; } return 0; } //********** Code the Die class constructor and methods after this line ********** 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!