Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Attached Files: Die.cpp (94 B) Die.h (942 B) main.cpp (755 B) sampleScreenShot.p

ID: 3907293 • Letter: A

Question

Attached Files: Die.cpp (94 B) Die.h (942 B) main.cpp (755 B) sampleScreenShot.png (117.234 KB) Lab Assignment 1You may work alone or with a single partner. If working with a partner, make one submission with both partners names in the submission. For this assignment, you may not change the Die.h or main.cpp files. You need to complete the Die.cpp implementation file. The Die class creates a single die object with the following features: Private members: int sides bool cheatmode; is this a cheating die? int favor int id int num_rolls; I/how many times has this die ever been rolled? int total; static int count how many die have ever been created? static int make id0treturn count++/static function to create a new id number of sides of this die //what number to favor, if a cheater //static id number of this die /what is the total number ever rolled? Public members: default constructor Die(int sides) loverloaded constructor for setting the number of sides int get id0 returns the id number of this die int rollo: lperform a roll int get average: Wreturn the die average void cheatfint favor); enable cheat mode and set the favor number friend bool cheating(Die& I/function that detects cheating die The less obvious features are the id value, and the cheating function. The id value is created by using the static count variable. The cheating function must be a friend in order to read the private member cheat mode. You should be able to implement the class by looking at the provided header and main files. In addition to submitting your completed implementation file, also submit a screenshot of your program output. The screenshot should show the output of a successful run. The score will be based on the implemented functions, screenshot, and code style.

Explanation / Answer

Please use the below Die.cpp along with Die.h and main.cpp files given by instructor.
Please do rate the answer if it was helpful. Thank you


Die.cpp
============
#include <cstdlib>
#include <ctime>
#include "Die.h"

using namespace std;
Die::Die(){
id = get_id();
sides = 6;
cheat_mode = false;
favor = 0;
num_rolls = 0;
total = 0;

count++;
if(count == 1){
srand(time(0));
}
}
Die::Die(int sides1){
id = get_id();
sides = sides1;
cheat_mode = false;
favor = 0;
num_rolls = 0;
total = 0;
count++;
}

int Die::roll(){

int r = 1 + rand() % sides;
if(cheat_mode && rand() % 2 == 0) //if its a cheating die, it will return favored number 50% of the times
r = favor;
total += r;
num_rolls++;
return r;
}
int Die::get_average(){
return total / num_rolls;
}
void Die::cheat(int favor1){
cheat_mode = true;
favor = favor1;
}
bool cheating(Die &d){
return d.cheat_mode;
}