This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Context -
A movie theater is testing a ticket purchasing system that allows customers to select their seat in the theater at the time of purchase. This movie theater has 30 available seats in each theater (numbered 0-29) and once a seat has been selected by one customer, it is marked as booked and cannot be selected by another customer. For the purposes of this simulation, we will assume that patrons are not willing to purchase a ticket if their preferred seat is unavailable, so they will leave without buying a ticket.
Problem -
The purpose of this program is to determine whether this seat selection system is efficient. In order to test efficiency, the manager of the theater has set an acceptable success rate to compare the observed success rate against.
If the observed success rate is less than the acceptable success rate, the simulated set of transactions fails to meet the minimum requirements for efficiency.
To begin the simulation, the user will input a number of iterations to be evaluated as well as the number of attempted transactions per iteration. Iterations can be thought of as showtimes in a given theater. Each iteration begins with 30 empty seats which can then be booked by customers.
We will simulate the selection of seats by using the rand() function to generate random numbers ranging from 0 to 29 corresponding to seats in the theater. In order to use the rand() function, you must first include stdlib.h and call the srand() function and pass a seed value to it. The seed value will be input by the user. Ex:
Input -
The user will input 4 values:
- The number of iterations/showtimes to be evaluated
- The number of transactions attempted for each iteration
- The acceptable success rate
- The seed for random number generation
You will be expected to validate all four inputs. All four values should be non-negative and the success rate should be between 0 and 1 (inclusive). Iterations must be greater than zero. If one of the four input values is not valid, the output should be
Output -
Your program should output:
- The acceptable success rate determined by the user
- The average attempted sales per iteration
- The average completed sales per iteration
- The observed success rate (number of total completed sales / number of total attempted sales)
- Whether or not the observed success rate is acceptable
Example 1:
When input is : 10 100 0.5 -1
Output is : Error. Invalid parameters.
Example 2:
When input is : 8 15 0.65 3
Output is :
Acceptable success rate: 0.65
Average attempted sales: 15.00
Average completed sales: 12.25
Observed success rate: 0.82
Observed success rate is acceptable.
Hints -
- In order to get a float or double from an integer operation, you can typecast as shown below
- While the total number of seats is a whole number, success rate and averages can have decimal values. You are expected to represent non-integer values to two decimal places.
So this is my hw for what I have to do
This is my code and ill post what I'm getting on my output
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int iterations, numAttempted, seed;
int seat[30]={0},comp = 0, count = 0;
double successRate;
cout <<"Enter Number of Iterations to be evaluated : ";
cin >> iterations;
cin >> numAttempted;
cin >> successRate;
cin >> seed;
if(iterations < 0){
cout <<" Error Invalid Parameters ";
return 0;
}
else{
while(iterations--){
//int seat[30]={0},comp = 0;
//cout<<"Enter transactions for " << count << " Iteration: ";
cin >> numAttempted;
if(numAttempted < 0){
cout <<" Error Invalid Parameters ";
return 0;
}
else{
//cout << "Enter Success Rate : " << successRate << endl;
cin>>successRate;
//cout << "Enter Seed Value : " << seed << endl;
cin >> seed;
}}
if(successRate >= 0 && successRate <=1 && seed > 0){
srand(seed);
for(int i = 0; i < numAttempted; i ){
int num = rand() % 30;
if(seat[num] == 0){
seat[num] = 1;
comp ; }}
}
else{
cout <<" Error Invalid Parameters ";
return 0; }}
cout << "Acceptable success rate: " << successRate << endl;
cout << "Average attempted sales: " << (double)numAttempted/30.0 << endl;
cout << "Average completed sales: " << (double)comp/30.0 << endl;
cout << "Observed success rate: " << comp/numAttempted << endl;
if(successRate > (comp/numAttempted))
cout << "Observed success rate not in acceptable range." << endl;
else
cout << "Observed success rate is acceptable." << endl;
return 0;
}
Input : 8 15 0.65 3
Output :
Enter Number of Iterations to be evaluated :
Acceptable success rate: 0.65
Average attempted sales: 0.5
Average completed sales: 0.466667
Observed success rate: 0
Observed success rate not in acceptable range.
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cpp_questio...