Question: Given the c++ code listed below how can i modify it to get it to print a list of how many times the total is
Given the c++ code listed below how can i modify it to get it to print a list of how many times the total is for 3 to 18 if i roll the 3 dice 200 times
for ex: the total 3 occurred 16 times
the total 4 occurred 20 times
the total 5 occurred 9 times
and so on through the total 18
//Die.h
class Die { short val; //for storing current throw value. public: Die(void); ~Die(void); int RollDie(); };
//dicecup.h
#pragma once #include "Die.h" //////DieCup.h #include
using namespace std; class DiceCup { int numberOfDiceInCup; //no. of dices , set in the c'trct std::vector
//dicecup.cpp
#include "DiceCup.h"
using namespace std;
DiceCup::DiceCup(int numberOfDice) { numberOfDiceInCup = numberOfDice; dice = new Die[numberOfDice]; //create objs arrays }
DiceCup::~DiceCup(void) { delete[] dice;//delete objs arrays } void DiceCup::Throw() //A single throw { int sum = 0; for (int i = 0; i < numberOfDiceInCup; i++) { sum += dice[i].RollDie(); //call roll die function for each die and get result. } sumResultList.push_back(sum); } int DiceCup::ReportSum(int X) //Report the sum { int count = 0; for (std::vector
//die.cpp
#include "Die.h" #include
Die::~Die(void) { } int Die::RollDie() { for(int i = 0;i<200;i++) val = rand() % 6 + 1; //random number to get val b/w 1 to 6 return val; }
//main .cpp
#include
int main() { DiceCup diceCup(3); //three dices for (int i = 0; i<200; i++) //Test case { diceCup.Throw(); cout << "values:" << i + 1; }
int sum = 0; std::cout << " Enter the sum to be reported: "; std::cin >> sum; std::cout << " Sum " << sum << " came " << diceCup.ReportSum(sum) << " times."; return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
