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

Fill in the missing code BELOW where it says \"student provides missing code\" T

ID: 3885151 • Letter: F

Question

Fill in the missing code BELOW where it says "student provides missing code"

The program output will look this after complete. Please upload screenshot with how it looks compiled along with the source code.

Problem

Allow the user to specify the number-of-sides of a die, S, the number-of-dice, D, and the number-of-trials, T. Because there is no requirement to validate user input, you may safely assume

(1 £ S £ 11), (1 £ D £ 11), and (T ³ 1)

By definition, a trial consists of repeatedly throwing the D Ssided dice until all the dice thrown show exactly the same face. For example, for S = 6 and D = 2, 1 trial might require the 8 throws (1,6) (2,3) (1,4) (5,6) (2,5) (4,6) (3,4) and finally (2,2).

After all trials have been run, display 1 line which shows the minimum number-of-throws used for a trial, the maximum number-of-throws used for a trial, and the average of the number-of-throws used for all trials using the format shown below. Note#1 The average is the real number which is computed as the quotient of the sum of number-of-throws for all trials (numerator) and the number-of-trials (denominator).

111111111122222222223333333333444444444455555555

123456789012345678901234567890123456789012345678901234567

Minimum XXXXXXXXXX, maximum XXXXXXXXXX, average XXXXXXXX.X

Note #2 Your Monte Carlo simulation is attempting to show the average number-of-throws required for D S-sided dice is SD/S = SD-1, the number predicted by the theory of the geometric distribution which is implicit in the dice-throwing experiment.

#include

#include

#include

#include

using namespace std;

//--------------------------------------------------

void SetRandomSeed(void)

//--------------------------------------------------

{

   srand( (unsigned int) time(NULL) );

}

//--------------------------------------------------

double RandomReal(void)

//--------------------------------------------------

{

   double r;

   int i;

   i = rand();

// i is in [ 0,RAND_MAX ]

   if ( i == 0 )

      r = 0.0;

   else

      r = (double) (i-1)/RAND_MAX;

// r is in [ 0.0,1.0 )

   return( r );

}

//--------------------------------------------------

int RandomInteger(int LB,int UB)

//--------------------------------------------------

{

   double RandomReal(void);

   return( (int) (RandomReal()*(UB-LB+1)) + LB );

}

//--------------------------------------------------

bool RandomBoolean(double bias)

//--------------------------------------------------

{

   double RandomReal();

   return( RandomReal() <= bias );

}

//--------------------------------------------------

char RandomCharacter(char characters[],int size)

//--------------------------------------------------

{

   int RandomInteger(int LB,int UB);

   return( characters[RandomInteger(0,(size-1))] );

}

//--------------------------------------------------

int main()

//--------------------------------------------------

{

   void RunOneTrial(int S,int D,int &throws);

   int S,D;

   int T,minimum,maximum,throws,sum;

   cout << "S? "; cin >> S;

   cout << "D? "; cin >> D;

   cout << "T? "; cin >> T;

   SetRandomSeed();

   Student provides missing code to ²run² T trials to determine and subsequently display

      the minimum, maximum, and average = sum/T of number-of-throws required for the T trials.

   system("PAUSE");

   return( 0 );

}

//--------------------------------------------------

void RunOneTrial(int S,int D,int &throws)

//--------------------------------------------------

{

   bool AllDieTheSame(int die[],int D);

   int *die = new int [ D ];

   Student provides missing code to ²run² one trial, counting the number-of-throws

      of the D S-sided dice required before all die faces are the same.

   delete [] die;

}

//--------------------------------------------------

bool AllDieTheSame(int die[],int D)

//--------------------------------------------------

{

   Student provides missing code to implement the quantification

      AllDieTheSame = "i (die[i] = die[i+1]), i Î [ 0,D-2 ]

   ...or equivalently

    AllDieTheSame = (die[0] = die[1]) && (die[1] = die[2]) && ... && (die[D-2] = die[D-1])

}

Sample Program Dialog S? 6 D? 5 T? 10000 Minimum L, maximum 11784, average 1290.2 S? 10 D? 2 T? 10000 Minimum (6) 5-1 = 1296 1, maximum 96, average 9.9 (10)2-1 = 10

Explanation / Answer

class Die
{

// Note: If we changed the class definition to "public class Die"
// then we would put this class definition in a separate file Die.java

// Represents one die (singular of dice) with faces showing values
// between 1 and 6.

private final int MAX = 6; // maximum face value

private int faceValue; // current value showing on the die

//-----------------------------------------------------------------
// Constructor: Sets the initial face value.
//-----------------------------------------------------------------
public Die()
{
faceValue = 1;
}

// Alternate Constructor

public Die(int value)
{
faceValue = value;
}

//-----------------------------------------------------------------
// Rolls the die and returns the result.
//-----------------------------------------------------------------
public int roll()
{
faceValue = (int)(Math.random() * MAX) + 1;

return faceValue;
}

//-----------------------------------------------------------------
// Face value mutator.
//-----------------------------------------------------------------
public void setFaceValue (int value)
{
faceValue = value;
}

//-----------------------------------------------------------------
// Face value accessor.
//-----------------------------------------------------------------
public int getFaceValue()
{
return faceValue;
}

// Returns a string representation of this die.
public String toString()
{
String result = Integer.toString(faceValue);
return result;
}

}

public class Dice
{

//-----------------------------------------------------------------
// Creates two Die objects and rolls them several times.
//-----------------------------------------------------------------
public static void main (String[] args)
{
Die die1, die2, die3;
int sum;

die1 = new Die();
die2 = new Die();

die1.roll();
die2.roll();
System.out.println ("Die One: " + die1 + ", Die Two: " + die2);

// The previous two method calls are sloppy programming practice,
// as the method returns an int which is not "received"
// Better to do this:

int x = die1.roll();

// Or

System.out.println("Die 1 " + die1.roll());

die2.setFaceValue(4);
System.out.println ("Die One: " + die1 + ", Die Two: " + die2);

sum = die1.getFaceValue() + die2.getFaceValue();
System.out.println ("Sum: " + sum);

sum = die1.roll() + die2.roll();
System.out.println ("Die One: " + die1 + ", Die Two: " + die2);
System.out.println ("New sum: " + sum);

die3 = new Die(4);
System.out.println("Die Three : " + die3.getFaceValue());
  
die3 = die2;
System.out.println("Die Three : " + die3.getFaceValue());

// What happens if we change faceValue to public
// and then do die3.faceValue = 2; System.out.println("Die Two : " + die2.getFaceValue());


}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote