mber of times ay value for a

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

In addition to the instructions on the screenshot, please ensure that your program is made in C++ with comments. Please also ensure that screenshots are taken for the source code and the executed version, including all possible cases. Finally, add your code in a manner so I can just copy and paste it for review. Thanks. 

1. Write an application that will roll a six-sided die N times. The program will display the
number of times each face comes up. The program will also calculate the minimum and
max value for a face. Finally, the program will calculate the range of the roll. Remember,
range is the difference between a maximum value and a minimum value in a data set i.e
Range = max Value - minValue.
Example Date set = {2, 30, 10, 20, 100}
minValue = 2
max Value = 100
range = max - min
= 100-2 =98
Your program must should have at least one function that return the frequency of each
face as a dynamic 1D array.
Transcribed Image Text:1. Write an application that will roll a six-sided die N times. The program will display the number of times each face comes up. The program will also calculate the minimum and max value for a face. Finally, the program will calculate the range of the roll. Remember, range is the difference between a maximum value and a minimum value in a data set i.e Range = max Value - minValue. Example Date set = {2, 30, 10, 20, 100} minValue = 2 max Value = 100 range = max - min = 100-2 =98 Your program must should have at least one function that return the frequency of each face as a dynamic 1D array.
Expert Solution
Step 1 Source Code Of Program

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int seed;
int n;
int die;
int *frequency = new int(6);  //dynamic 1D array
int min, max;
int range;

seed = time(0);
srand(seed);

for (int i=0; i<6; i++)
frequency[i] = 0;

cout << "How many dice should be rolled? ";
cin >> n;

for (int i=0; i<n; i++)
{
die = rand()%6;
switch(die)
{
case 0:
frequency[0]++;
break;
case 1:
frequency[1]++;
break;
case 2:
frequency[2]++;
break;
case 3:
frequency[3]++;
break;
case 4:
frequency[4]++;
break;
case 5:
frequency[5]++;
break;
}
}

cout << "Face\tFrequency" << endl;
for (int i=0; i<6; i++)
{
cout << i+1 << "\t" << frequency[i] << endl;
}

min = max = range = frequency[0];

for (int i=1; i<6; i++)
{
if (frequency[i] < min)
min = frequency[i];
if (frequency[i] > max)
max = frequency[i];
}

range = max - min;

cout << "Min: " << min << endl;
cout << "Max: " << max << endl;
cout << "Range: " << range << endl;

return 0;
}

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Transmission media
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education