Create a new file (in Dev C++) and save it as lab12_XYZ.cpp (replace XYZ with your initials). Create ANOTHER new file (in Dev C++) and save it as lab12_XYZ.h (replace XYZ with your initials). Use the H (header) file to declare constants and define functions. Make sure to #include "lab12_XYZ.h", and place H file in same location as your main program. Consider rolling two six-sided dice. While the result of each throw is independent of all rolls that have come before, we can still calculate the odds of rolling any given number between 2 and 12. This program will calculate those odds by generating a large number (100,000) of random values (i.e. "rolling the dice") and storing the results in an array. When all values have been rolled, we will display the results (counts and odds to 2 decimal places) to the user.   x   x   2   3   4   5   6   7   8   9   10  11  12     //value for sum of 2 dice rolls+---+---+---+---+---+---+---+---+---+---+---+---+---+|   |   |   |   |   |   |   |   |   |   |   |   |   |    //counters for number of times value is rolled+---+---+---+---+---+---+---+---+---+---+---+---+---+   0   1   2   3   4   5   6   7   8   9   10  11  12     //array index We need some constants int constants - NUM_ROLLS, NUM_SIDES, NUM_DICE, PRECISION, COLW1, COLW2, COLW3, etc. string constants - HELLO, GOODBYE, etc. We need some functions: void displayMessage(string);  //HELLO, GOODBYE, etc. (constants declared in your lab12_XYZ.h file...) int rollDice();  //returns a number between 2 and 12 (by rolling two dice and summing the result) void displayResults(int[]);  //displays results in the array In Lab 5, sample code was provided for generating a random number. Seed the random number generator in main(), then use rand() in the rollDice() function. #include <cstdlib>#include <ctime>unsigned seed = time(0);srand(seed);  //seed the RNGint num = (rand() % NUM_SIDES) + 1;   For this assignment: Header comments must be present in both CPP and H files Hello and goodbye messages must be shown Array(s) must be used for implementation DO NOT make arrays global variables Results should be formatted neatly (2 decimal places for odds, decimals lined up, etc.) Use comments and good style practices HINT: Make sure to initialize counter array before starting loop HINT: To calculate odds percentage: odds = count * 100 / NUM_ROLLS; SAMPLE OUTPUT:Welcome! This program will calculate the odds of rolling 2 - 12 with two 6-sided dice.Number of  2s rolled:         2776  ( 2.78%) Number of  3s rolled:         5518  ( 5.52%) Number of  4s rolled:         8234  ( 8.23%) Number of  5s rolled:        11273  (11.27%) Number of  6s rolled:        13884  (13.88%) Number of  7s rolled:        16594  (16.59%) Number of  8s rolled:        13848  (13.85%) Number of  9s rolled:        11102  (11.10%) Number of 10s rolled:         8394  ( 8.39%) Number of 11s rolled:         5580  ( 5.58%) Number of 12s rolled:         2797  ( 2.80%)Exiting program. Goodbye!   Lanauge is C++ Please make it as simple as possible.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section8.1: I/o File Stream Objects And Functions
Problem 3E
icon
Related questions
Question

Create a new file (in Dev C++) and save it as lab12_XYZ.cpp (replace XYZ with your initials).

Create ANOTHER new file (in Dev C++) and save it as lab12_XYZ.h (replace XYZ with your initials).

Use the H (header) file to declare constants and define functions. Make sure to #include "lab12_XYZ.h", and place H file in same location as your main program.

Consider rolling two six-sided dice. While the result of each throw is independent of all rolls that have come before, we can still calculate the odds of rolling any given number between 2 and 12. This program will calculate those odds by generating a large number (100,000) of random values (i.e. "rolling the dice") and storing the results in an array. When all values have been rolled, we will display the results (counts and odds to 2 decimal places) to the user.

  x   x   2   3   4   5   6   7   8   9   10  11  12     //value for sum of 2 dice rolls+---+---+---+---+---+---+---+---+---+---+---+---+---+|   |   |   |   |   |   |   |   |   |   |   |   |   |    //counters for number of times value is rolled+---+---+---+---+---+---+---+---+---+---+---+---+---+

  0   1   2   3   4   5   6   7   8   9   10  11  12     //array index

We need some constants

  • int constants - NUM_ROLLS, NUM_SIDES, NUM_DICE, PRECISION, COLW1, COLW2, COLW3, etc.
  • string constants - HELLO, GOODBYE, etc.

We need some functions:

  • void displayMessage(string);  //HELLO, GOODBYE, etc. (constants declared in your lab12_XYZ.h file...)
  • int rollDice();  //returns a number between 2 and 12 (by rolling two dice and summing the result)
  • void displayResults(int[]);  //displays results in the array

In Lab 5, sample code was provided for generating a random number. Seed the random number generator in main(), then use rand() in the rollDice() function.

#include <cstdlib>#include <ctime>unsigned seed = time(0);srand(seed);  //seed the RNGint num = (rand() % NUM_SIDES) + 1;

 

For this assignment:

  • Header comments must be present in both CPP and H files
  • Hello and goodbye messages must be shown
  • Array(s) must be used for implementation
  • DO NOT make arrays global variables
  • Results should be formatted neatly (2 decimal places for odds, decimals lined up, etc.)
  • Use comments and good style practices

HINT: Make sure to initialize counter array before starting loop

HINT: To calculate odds percentage: odds = count * 100 / NUM_ROLLS;

SAMPLE OUTPUT:Welcome! This program will calculate the odds of rolling 2 - 12 with two 6-sided dice.
Number of  2s rolled:         2776  ( 2.78%)

Number of  3s rolled:         5518  ( 5.52%)

Number of  4s rolled:         8234  ( 8.23%)

Number of  5s rolled:        11273  (11.27%)

Number of  6s rolled:        13884  (13.88%)

Number of  7s rolled:        16594  (16.59%)

Number of  8s rolled:        13848  (13.85%)

Number of  9s rolled:        11102  (11.10%)

Number of 10s rolled:         8394  ( 8.39%)

Number of 11s rolled:         5580  ( 5.58%)

Number of 12s rolled:         2797  ( 2.80%)
Exiting program. Goodbye!

 

Lanauge is C++

Please make it as simple as possible.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr