Write a code

User Generated

JvyylJbaxn555

Programming

Harvard University

Description

Rolling the Dice

Description:

This assignment will replace physically rolling dice. Most dice games use between 2 and 9 dice. Dice have dots on each of the six sides that correspond to the numbers 1,2,3,4,5, and 6. You will be given a main routine designed to roll and maintain dice for these type of games. Your job is to write the Dice Object Oriented class to work with the main routine. You will be given the following files... DO NOT CHANGE THEM:

1. The main routine: main.cppDownload main.cpp

2. The header file for the Dice class: dice.hDownload dice.h

Dice class interface requirements:

  • Minimum number of dice is 2, maximum number of dice is 9 , the default number of dice or throws is 4. These constants are declared in the dice.h file and you must use them. They are accessible inside your main routine.
  • Dice(): Default constructor. Set the initial seed to the random number generator to the system time and sets number of dice or throws to 2. Set the sum to zero and clear out the dice_array.
  • Dice(const int t): One parameter constructor. Set the initial seed to the random number generator to the system time and sets number of dice to the value passed in if it is valid otherwise set it to the default value. Set the sum to zero and clear out the dice_array.
  • Roll(): Calls a random number generator to roll the number of dice specified by the private data item throws, stores the values in the array dice_values, calculates the sum and stores it.
  • PrintDice(): Prints out the dice that were rolled in order. Goes through the dice_array for each value. See the sample output.
  • Setnumberofdice(const int t): Set the number of dice or throws. Checks for min and max and rolls the dice before leaving.
  • GetSum(): Returns the current sum.
  • Getnumberofdice(); Returns the number of throws or number of dice.
  • ClearDice(); Set sum to zero, set all values in dice_values to zero

Programming Specifications:

  1. This is going to be your introduction to Object Oriented Programming and multiple file solutions. Attached to this program are two files. dice.h and main.cpp. THEY ARE NOT TO BE CHANGED .
  2. You will write the dice.cpp file that makes it all work.
//
// Created by David Gaitros on 4/9/23.
//

#ifndef DICE_H
#define DICE_H
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <iomanip>
using namespace std;


const int MINIMUMDICE=4;
const int MAXIMUMDICE=9;
const int DEFAULTDICE=4;

class Dice {
public:
Dice();
Dice(const int t);
void Roll();
void PrintDice();
void Setnumberofdice(const int t);
int Getnumberofdice();
int GetSum();

private:
void ClearDice();
int numberofdice;
int dice_values[MAXIMUMTHROWS];
int sum;
};
#endif

Design Considerations:

  1. Provide an initial seed to your random number generator by pasting the current time to srand. . Be sure to include the <cstlib> , <ctime>, and <iomanip> and <iostream> libraries. Seeding the random number generator is done by executing this series of statements just once at the start of the program.
    • srand(time(0)) ;
  2. Each subsequent call to rand() will cause a new seed to be generated automatically.
  3. The random number generator returns a large integer number which must have the modulo operator used to reduce the possible number of returned values for the range you wish. For instance, if you wanted the upper range of your numbers to be 6 you would use the following statements:

Randomnumber = (rand() % 6)+1;

General Requirements:

  1. No global variables, other than constants and type definitions!. Private data inside the class are the exception.
  2. Use the const qualifier on member functions and for constants wherever it is appropriate.
  3. The main routine (main.cpp) and the Dice class header file (dice.h) must not be altered.
  4. Your output must match the example exactly.
  5. Your must follow the specifications for the public and private routines exactly.
  6. You may add any other non-class routines to the dice.cpp function that you feel you need. Again, you may not alter the dice.h or the main routine file.

Submission:

Submit only the dice.cpp file. The file name must be in all lower case. The dice.cpp should contain as a minimum the following include statements:

#include <iostream>

#include <ctime>

#include <cstdlib>

#include "dice.h"

using namespace std;

Grading Criteria:

  1. (25 Points) The program compiles and executes without exception and produces output. The grading of the output cannot be accomplished unless the program executes. 25 points will be deducted if the grader must make minor modifications to your program in order for it to work on the CLION compiler.
  2. (25 Points) The program produces the correct output.
  3. (25 Points) The program specifications are followed.
  4. (10 Points)The program is documented (commented) using the block style comments
  5. (5 Points)Use constants when values are not to be changed
  6. (5 Points)Use proper indentation
  7. (5 Points)Use good naming standards

Sample Run:

Generic RAndom Dice Egame Routine (GRADER)
Enter one of the options below:
-------------------------------------
| T - Throw Dice |
| R - Reset/Set number of Dice |
| P - Print the last throw again |
| S - Show Summary Data |
| E - Exit Game |
-------------------------------------

Option: t
-------
|0 0|
| 0 | 5
|0 0|
-------

-------
|0 0|
|0 0| 6
|0 0|
-------

-------
|0 0|
| | 4
|0 0|
-------

-------
|0 0|
|0 0| 6
|0 0|
-------


Generic RAndom Dice Egame Routine (GRADER)
Enter one of the options below:
-------------------------------------
| T - Throw Dice |
| R - Reset/Set number of Dice |
| P - Print the last throw again |
| S - Show Summary Data |
| E - Exit Game |
-------------------------------------

Option: s
Sum is: 21
Number of Dice is 4


Generic RAndom Dice Egame Routine (GRADER)
Enter one of the options below:
-------------------------------------
| T - Throw Dice |
| R - Reset/Set number of Dice |
| P - Print the last throw again |
| S - Show Summary Data |
| E - Exit Game |
-------------------------------------

Option: r
Enter a number between 2 and 9: 6
Generic RAndom Dice Egame Routine (GRADER)
Enter one of the options below:
-------------------------------------
| T - Throw Dice |
| R - Reset/Set number of Dice |
| P - Print the last throw again |
| S - Show Summary Data |
| E - Exit Game |
-------------------------------------

Option: p
-------
|0 0|
|0 0| 6
|0 0|
-------

-------
|0 0|
| | 4
|0 0|
-------

-------
|0 |
| | 2
| 0|
-------

-------
|0 |
| 0 | 3
| 0|
-------

-------
|0 0|
|0 0| 6
|0 0|
-------

-------
|0 0|
| | 4
|0 0|
-------


Generic RAndom Dice Egame Routine (GRADER)
Enter one of the options below:
-------------------------------------
| T - Throw Dice |
| R - Reset/Set number of Dice |
| P - Print the last throw again |
| S - Show Summary Data |
| E - Exit Game |
-------------------------------------

Option: s
Sum is: 25
Number of Dice is 6


Generic RAndom Dice Egame Routine (GRADER)
Enter one of the options below:
-------------------------------------
| T - Throw Dice |
| R - Reset/Set number of Dice |
| P - Print the last throw again |
| S - Show Summary Data |
| E - Exit Game |
-------------------------------------

Option: e
Good Bye and thanks for playing

Process finished with exit code 0

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Attached.

#include
#include
#include
#include "dice.h"

using namespace std;


/**
* Default constructor. Set the initial seed to the random number generator to
* the system time and sets number of dice or throws to 2. Set the sum to zero
* and clear out the di...

Related Tags