Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Enhance this Galton board simulation by printing a bar chart of the bottommost counters. Draw the bars vertically, below the last row of numbers. See

Enhance this Galton board simulation by printing a bar chart of the bottommost counters. Draw the bars vertically, below the last row of numbers. See the comments in the C++ source file for where to put your modified code.

// Enhanced version of galton.cpp with snazzy vertical bar graphs.

#include

#include

#include

#include

using namespace std;

int main()

{

srand(time(0));

int* counts[10];

// Allocate the rows

for (int i = 0; i

{

counts[i] = new int[i + 1];

for (int j = 0; j

{

counts[i][j] = 0;

}

}

const int RUNS = 1000;

// Simulate 1,000 balls

for (int run = 0; run

{

// Add a ball to the top

counts[0][0]++;

// Have the ball run to the bottom

int j = 0;

for (int i = 1; i

{

int r = rand() % 2;

// If r is even, move down, otherwise to the right

if (r == 1)

{

j++;

}

counts[i][j]++;

}

}

// Print all counts

for (int i = 0; i

{

for (int j = 0; j

{

cout

}

cout

}

// You will need to create the code here for the bar chart

// Step1: Compute the maximum count so that we can make

// the bar charts proportional to this number

// Step 2: Create an array of bar chart heights based on

// this computed max value

// Step 3: Print the bars across the bottom

// Deallocate the rows

for (int i = 0; i

{

delete[] counts[i];

}

return 0;

}

image text in transcribed
.. P7.1 Enhance the Galton board simulation by printing a bar chart of the bottommost counters. Draw the bars vertically, below the last row of numbers. 1 18 64 149 239 265 186 61 15 2 * * * * * * * * * * * * * * * * * *

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Shamkant B. Navathe

7th Edition Global Edition

1292097612, 978-1292097619

More Books

Students also viewed these Databases questions

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago