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

question 19 and then 20( 20 is one im trying to figure out) suppose you roll a s

ID: 3663275 • Letter: Q

Question

question 19 and then 20( 20 is one im trying to figure out)

suppose you roll a set of n dice. then the smallest sum is n and the largest is 6n. example if n=10 then the small sum will be 6 and the largest 60. Let m be the desired sum of the numbers rolled. then n<= m <= 6n. write a program that uses the class die of example 10-9 to roll 10 die(will type it below the instruction). use an array of size 10 to implement 10 dice. the program prompts the user to enter the desired sum and the number of the times the dice are to be rolled. the program outputs the number of times the desired sum was rolled and the probability of the rolling the desired sum .

question20

programing excersie 19 promted the user to imput the number of tmes the dice were to be rolled and the desired sum and the program output the number of times the desired sum occued. modify progamming exersie 19(the instructions from above),: suppose you roll 4 dice 1000 times. store the sum of the n umbers rolled in each roll into an array and then use this array to pring a bar graph(sounds like me want to put the numbers into excell and consturct a graph) test run your program use 4,5,6 dice and the number of rolls 2500, 3000, and 5000. what type of curve does the shape of your bar graph resemble?

class die

{

public:

die();

void roll();

int getNum() const;

private

int num;

};

die :: die()

{

num = 1;

srand(time(0));

}

void die::roll()

{

num = rand()% 6+1

}

int die:: getNum() const

{

return num;

}

if it helps the isbn is 9781285852751

Explanation / Answer

die.h

#define DIE_H
#ifndef DIE_H
#include<time.h>
#include<iostream>

using namespace std ;

class Die

{

private:

int nums;
int* vals;
int sum;
void DieRoll();

public:

Die()
   {
   srand( static_cast<int>( time( NULL ) ) );
   nums = 0 ;
   vals = NULL ;
   sum = 0 ;
   }

void DieRoll( int n );
int getNums()const{
   return nums ;
       }
void printsLastVal();
void printsVals();
~Die(){
   delete [] vals ;
   }

};

#endif


die.cpp

#include<iostream>
#include<time.h>
#include"die.h"

using namespace std ;

void Die::DieRoll()
{

nums = 1+rand()%6 ;
}

void Die::printsLastVals()
{
cout << nums << endl ;
}

void Die::DieRoll( int n )
{
sum = n ;
vals = new int[sum] ;
for( int i = 0 ; i < sum ; i++ )
{
DieRoll();
vals[i] = nums ;
}

}
void Die::printsVals()
{
for( int i = 0 ; i < sum ; i++ )
{
cout << vals[i] << endl ;
}
}


main.cpp


#include"die.h"
#include<iostream>

using namespace std ;

int main()
{
Die r ;
r.DieRoll(2500) ;
r.printsVals(3000) ;
r.DieRoll(40) ;
r.printsVals() ;
r.DieRoll(5000) ;
r.printsVals() ;
r.printsLastVals() ;
}