1 answer

Stimulating a dice roll in C++ (using dynamic arrays)

Question:

Write a program that stimulates the mathematical experiment of rolling a pair of dice any number of times. Let user input this data. The program also lets user pick achoice of output for either partial or all of the following information:
1. all random outcomes observed
2. frequency and relative frequency corresponding to the random values defined by the sum of the dots on the dice for each roll
3. text version of histogram
4. graphic version of histogram by a Scalable Vector File
The main source of code that I am having trouble with is displaying the output of the dice rolls. Please show me how to do this. Help with the entire problem would bepreferred. Use void functions, do not put everything in the main function.

Answers

#include <iostream>
using std::cout;
using std::ios;

#include <iomanip>
using std::setw;
using std::setprecision;
using std::fixed;
using std::showpoint;

#include <cstdlib>
using std::rand;
using std::srand;

#include <ctime>
using std::time;

int main()
{
const long ROLLS = 36000;
const int SIZE = 13;

// array expected contains counts for the expected
// number of times each sum occurs in 36 rolls of the dice
/* Write a declaration of array exprected here. Assign an
initializer list containing the expected values here. Use
SIZE for the number of elements */
int x; // first die
int y; // second die
/* Write declaration for the array sum here. Initialize all
elements to zero. Use SIZE for the number of elements */

srand( time( 0 ) );

// roll dice 36,000 times
/* Write a for statement that iterates ROLL times.

Randomly
generate values for x (i.e., die1) and (i,e, die2)
and increment the appropriate counter in array sum that
corresponds to the sum of x and y */

cout << setw( 10 ) << "Sum" << setw( 10 ) << "Total" << setw( 10 )
<< "Expected" << setw( 10 ) << "Actualn" << fixed << showpoint;


// display results of rolling dice
for ( int j = 2; j < SIZE; j++ )
cout << setw( 10 ) << j << setw( 10 ) << sum[ j ]
<< setprecision( 3 ) << setw( 9 )
<< 100.0 * expected[ j ] / 36 << "%" << setprecision( 3 )
<< setw( 9 ) << 100.0 * sum[ j ] / 36000 << "%n"


return 0; // indicates successful completion
} // end main.

Similar Solved Questions

1 answer
Saved Help Save The Foundational 15 (LO1-1, LO1-2, LO1-3, LO1-4, LO1-5, LO1-6) [The following information applies...
Saved Help Save The Foundational 15 (LO1-1, LO1-2, LO1-3, LO1-4, LO1-5, LO1-6) [The following information applies to the questions displayed below.] Martinez Company's relevant range of production is 7,500 units to 12,500 units. When it produces and sells 10,000 units, its average costs per unit...
1 answer
Discuss medications to treat congestive heart failure (CHF). What medications are used to treat CHF? What...
Discuss medications to treat congestive heart failure (CHF). What medications are used to treat CHF? What specifically should patients be taught about CHF medications to prevent adverse side effects?...
1 answer
Question 10 2.3 pts Which part of photosynthesis is responsible for the production of O2? e...
Question 10 2.3 pts Which part of photosynthesis is responsible for the production of O2? e Light reactions Citric acid cycle Calvin cycle Carbon fixation Chemiosmosis...
1 answer
1. Net present value (NPV) Evaluating cash flows with the NPV method The net present value...
1. Net present value (NPV) Evaluating cash flows with the NPV method The net present value (NPV) rule is considered one of the most common and preferred criteria that generally lead to good investment decisions. Consider this case: Suppose Fuzzy Button Clothing Company is evaluating a proposed capit...
1 answer
Mercer Asbestos Removal Company removes potentially toxic asbestos Insulation and related products from bulldings. There has...
Mercer Asbestos Removal Company removes potentially toxic asbestos Insulation and related products from bulldings. There has been a long-simmering dispute between the company's estimator and the work supervisors. The on-site supervisors claim that the estimators do not adequately distinguish bet...
1 answer
Find if the following problems are algorithmically decidable and prove that your answers are correct. Given...
Find if the following problems are algorithmically decidable and prove that your answers are correct. Given three context-free languages N, L and M, find if the language (L⋂N)⋃(N⋂M) is empty Please help....
2 answers
The battery for a certain cell phone is rated at 3.70V. According to the supplier, the...
The battery for a certain cell phone is rated at 3.70V. According to the supplier, the battery can produce 3.50x104J of energy enough to operate the cell phone for 5.25hrs before needing a recharge. What’s the average value of the current (in units of A) the cell phone draws when turned on?...
1 answer
7. A 0.730 m length of conducting wire has its ends connected so as to form...
7. A 0.730 m length of conducting wire has its ends connected so as to form a conducting loop. An electrical current of 0.145 A is somehow flowing through the wire. The loop is place in an external magnetic field of 0.0482 T. What is the magnitude of the maximum possible torque that acts on this cur...
1 answer
B) A 1MW, 3300 V, 50 Hz, wye-connected, 3-ф, twenty four-pole, synchronous motor has a synchronous...
b) A 1MW, 3300 V, 50 Hz, wye-connected, 3-ф, twenty four-pole, synchronous motor has a synchronous reactance of 3.24 2 per phase. Assume armature resistance is negligible. This machine is connected to an infinite bus-bars at 3300 V. Its field excitation is adjusted to provide P.F-1 at rated lo...
1 answer
This is an Image from a plant tissue. What is the microscopic technique used? and why?(2...
This is an Image from a plant tissue. What is the microscopic technique used? and why?(2 Marks) Describe and Interpret what you see in the micrograph. (8 Marks) YeastPaste Os04_GC5_019 Cal: 0.001607 pm/pix 09:45:38 6/9/2016 400 nm HV=80.OkV Direct Mag. 50000X X -442 Y: -94.7 UBC Biolmaging Facility ...
1 answer
Risk and return analysis
Given below is hypothetical data on two stocks on the LUSE and the market data (All Lusaka Share Index). The market data already includes dividends paid during the year. Stock 1                   &nbs...
2 answers
C++ write a function to evaluate the length of a lost. Do not assume the list...
C++ write a function to evaluate the length of a lost. Do not assume the list is the same length as above....
1 answer
1.) A firm manufactures bottles with the following technology: q =f (L) = 100√L, where q...
1.) A firm manufactures bottles with the following technology: q =f (L) = 100√L, where q denotes bottles and L, the number of workers. (a) How many workers are needed to produce q = 500 bottles? If the firm doubles that amount of workers, will they be able to double the amount of output? (...
1 answer
Ection in statement of financial position Question 2 Test Bank: Q1 J19 Below are the non...
ection in statement of financial position Question 2 Test Bank: Q1 J19 Below are the non current assets purchased by Teguh Bersatu Sdn Bhd in the current year (1 July 2014 until 30 June 2015) and all payments are made by cheque. Assets Date of purchase 1 July 2014 1 October 2014 1 January 2015 Cost ...
1 answer
45. Predict/Calculate Figure 19-42 shows a system consisting of three charges, q1 +5.00 uC, 92 +5.00...
45. Predict/Calculate Figure 19-42 shows a system consisting of three charges, q1 +5.00 uC, 92 +5.00 uC, and gs5.00 uC, at the vertices of an equilateral triangle of side d 2.95 cm. (a) Find the magnitude of the electric field at a point halfway between the charges qi and q2. (b) Is the magnitude of...
1 answer
A 747 jetliner lands and begins to slow to a stop as it moves along the...
A 747 jetliner lands and begins to slow to a stop as it moves along the runway. If its mass is 3.58×105 kg, its speed is 68.0 m/s, and the net braking force is 4.30×105N, what is its speed 7.00 s later? How far has it traveled in this time?...