Question: Write a C++ program to simulate a uniform (meaning every number is equally likely to appear as the next) integer random number. Your program will

Write a C++ program to simulate a uniform (meaning every number is equally likely to appear as the next) integer random number. Your program will be a console application which will simulate a 6-sided die. You will throw your simulated die N times. The number N should be obtained by prompting the user with the question How many rolls?

Also, since you will be using rand() provide a prompt requesting that the user provide a seed number. The prompt can be as simple as "Please enter a seed number:"

Then use the seed provided by the user to seed the random number generator. This will also help you test your program.

We will use 6000 times as an example.

Show the frequency distribution of your numbers when 6,000 tosses are made and the random number is instantiated to generate numbers between 1 and 6 (inclusive). In other words, show how many times the numbers 1,2,3,.and 6 have appeared.

The output displayed on the screen should look something like this:

1 ----- 900

2 ----- 950

Up to

6 ---- 1011

Meaning that the number one appeared 900 times (your mileage may vary), and so on.

The output should also have a section displaying a histogram.

The histogram should look something like this:

1 xxxxxxxxxxxxxx

2 xxxxxxxxxxxxxx

.

.

.

6 xxxxxxxxxxxxxx

Where the x represent some number of occurrence of a particular face. Since you are likely to get 100s of occurrences of a face you will not be able to use one x for one occurrence. Therefore you will have to scale your display so that x represents some number of occurrences and so that the largest number of occurrences will fit on a standard console line of 80 characters.

You might want to find the number with the maximum occurrence and represent that maximum occurrence with 60 xs. This means that should the die side appearing the most comes out 1200 times out of 6000, you would want to represent its count with 60 xs. This means that each x, in that particular run would represent 20 occurrences of a side. Thus 1200 occurrences are represented by 20 Xs If, on the other hand, the largest number of occurrences of a particular side had been 1800, then you would need each X to represent 30 occurrences so that 1800 occurrences would be represented by 60 Xs.

Basically, you want to normalize your graph in such a way that the largest number of occurrences is represented by 60 Xs.

Make sure that your xs line up and start on the same column.

Then display the histogram obtained when you roll 2 dice and add up the numbers that come up (2 12). As in the first part, you will roll the dice N times.

Create 2 outputs as above. 1 output to display the counts for each sum and one output to display the xs for each sum

Guidelines.

Use plenty of comments to help others understand your code. Program without comments will incur a 10% penalty.

Note that using Arrays or the vector<> types to hold the histogram counts will make your work much, much easier. Those topics are covered in module 5.

Your code must compile. If your code doesnt compile you will automatically receive a grade of 0.

Your executable must run. If not you will automatically receive a grade of 0.

If your code doesnt display the histogram and counts appropriately you will suffer a penalty of at least 50% depending on the cause of the error.

FYI: Please do not use advanced function. this a beginner class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!