// DisplayRollDice.cc // Modify a copy of RollDice.cc to answer Exercise 8 then // use parts of this incomplete program to answer Exercise 9. // Standard library headers #include #include #include "glue.h" using namespace std; //User-defined function prototypes int RollDie(); void plot_the_graph(int w, int h); int main() { int outcome, N=0; // Initialise random number generator with value of system time. srandom(time(NULL)); // Get user input in correct range. while(N<1 || N>1000) { cout << "Input the number of experiments (1-1000): " ; cin >> N; } // Perform N experiments. // Call RollDie() N times for(int i=0; i< N; i++) { outcome = RollDie(); } // Create the graphics window glueWindow(); // Set the redraw function and Go! graphicsfunction (plot_the_graph); glueGo(); } // Function to simulate rolling a single 6-sided die. // Each call will randomly return a different integer between 1 and 6. int RollDie() { int randomNumber, die; randomNumber = random(); die = 1 + randomNumber % 6; return die; } // This will be called whenever the window needs redrawing void plot_the_graph(int w, int h) { // assume that 61 pieces of data exist in an array // of floating point numbers called fraction float xlo=0.0, xhi = 60, ylo = 0.0, yhi=0.25; //Draw x and y axes with nxticks and nyticks between max and min values int nxticks = 7, nyticks = 6; color(BLACK); xaxis(50, 400, nxticks, 50, 5, "Outcome", xlo, xhi); yaxis(50, 400, nyticks, 50, 5, "Frequency", ylo, yhi); // Plot data as discrete distribution for(int i=0; i<61; i++) { // The cout command below is to assist with debugging // Comment it out if you wish cout << "Drawing a line from (" << i <<",0) to (" << i <<"," <