Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task: Write a program called DiceStats which computes and displays statistics on the frequency of sums obtained when rolling a pair of dice, as described

Task: Write a program called DiceStats which computes and displays statistics on the frequency of sums obtained when rolling a pair of dice, as described below.

Steps: Your program must contain the following elements:

A subroutine called printHashes which takes an integer as a parameter and prints that many # symbols on a line, ending with a new line.

A subroutine called printHistogram which takes an array of integers and two additional integers (called low and high) as parameters, and, for each slot between low (inclusive) and high (exclusive), prints out the number of the slot followed by a number of hashes determined by the value stored in the array at that slot. For example, if the array contains the seven values 1 8 0 3 2 10 7, low is 1, and high is 5, then printHistogram should produce:

1: ######## 2: 3: ### 4: ## 

A function called generateStats which takes the number of sides on a die and the number of times to roll as parameters, rolls a pair of dice with the specified number of sides the specified number of times, and returns an array where slot i of the array contains the number of times the sum i was rolled.

A main program which rolls a pair of 6-sided dice 400 times and prints out a histogram showing how often each sum was rolled.

Make use of the various subroutines and functions where you can - printHistogram should use printHashes to print the hashes for each slot of the array and the main program should use all three subroutines/functions.

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 Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions