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::vectorsumResultList; //sum of dice throw Die *dice; //point to dice objects public: int ReportSum(int X); DiceCup(int numberOfDice); ~DiceCup(void); void Throw(); };

//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::iterator itr = sumResultList.begin(); itr != sumResultList.end(); itr++) { if (*itr == X) count++; } return count; }

//die.cpp

#include "Die.h" #include #include Die::Die(void) //constructor { val = 1; //initial value 1 }

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 #include "DiceCup.h"//DiceCup.h

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

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!