In: Computer Science
To be written in C++. A local movie theater has three ticket windows and two computerized ticket kiosks. Some transactions, such as group discounts, can only be done at the ticket windows. An arriving customer looks at the lines, and chooses to stand in the shortest one that can handle his or her transaction. Group sales take four minutes to process. Normal ticket sales take two minutes at a window and three minutes at a kiosk. Internet ticket sales pickups take one minute at a kiosk and two minutes at a window. Write a simulation of this process, using queues to represent the five lines. The data set should consist of randomly arranged customer arrivals, with 5% group sales, 20% Internet ticket sales pickups, and 75% regular ticket sales. A data set will contain 200 customers. All of the customers tend to arrive shortly before the start of a movie, so we are simplifying the simulation to say that they all arrive at the same time. From this simulation, the theater wants you to determine the maximum length of each line, the average waiting time for each line, and the time required for each line to empty. As a hint, think about using a list to create the data set by adding 10 group, 40 Internet, and 150 regular customers and then shuffling the list. The list is then traversed, transferring each customer to the shortest queue that can handle the customer’s transaction.
The code has been explained in the comments:
Please refer to the screenshots for indentation:
Please comment before downvote for any doubt, will resolve asap:
Code:
#include <bits/stdc++.h>
using namespace std;
vector <string> generate_queue(){ // To generate random queue
with given parameters
vector <string> Q;
for(int i = 0; i < 10; i++)
// inserting 10% group
{
Q.push_back("Group");
}
for(int i = 0; i < 40; i++)
//inserting 20% Internet
{
Q.push_back("Internet");
}
for(int i = 0; i < 150; i++)
//inserting 75% regular
{
Q.push_back("Regular");
}
random_shuffle ( Q.begin(), Q.end() );
// shuffling the queue
return Q;
}
int main(){
vector <string> Q = generate_queue();
queue <string> W1;
// Queue for 1st window
queue <string> W2;
// Queue
for 2nd window
queue <string> W3;
// Queue
for 3rd window
queue <string> K1;
// Queue
for 1st Kiosk
queue <string> K2;
// Queue
for 2nd Kiosk
for(int i = 0; i < Q.size(); i++)
{
if(Q[i] == "Group")
{
if(W1.size()
<= W2.size() && W1.size() <= W3.size())
{
W1.push("G");
}
else
if(W2.size() <= W3.size())
{
W2.push("G");
}
else
{
W3.push("G");
}
}
else if(Q[i] == "Regular")
{
if(W1.size()
<= W2.size() && W1.size() <= W3.size() &&
W1.size() <= K1.size() && W1.size() <=
K2.size())
{
W1.push("R");
}
else
if(W2.size() <= W3.size() && W2.size() <= K2.size()
&& W2.size() <= K2.size())
{
W2.push("R");
}
else
if(W3.size() <= K2.size() && W3.size() <=
K2.size())
{
W3.push("R");
}
else
if(K1.size() <= K2.size())
{
K1.push("R");
}
else
{
K2.push("R");
}
}
else if(Q[i] == "Internet")
{
if(W1.size()
<= W2.size() && W1.size() <= W3.size() &&
W1.size() <= K1.size() && W1.size() <=
K2.size())
{
W1.push("I");
}
else
if(W2.size() <= W3.size() && W2.size() <= K2.size()
&& W2.size() <= K2.size())
{
W2.push("I");
}
else
if(W3.size() <= K2.size() && W3.size() <=
K2.size())
{
W3.push("I");
}
else
if(K1.size() <= K2.size())
{
K1.push("I");
}
else
{
K2.push("I");
}
}
}
cout << "Max queue size for window 1 : "
<< W1.size() << endl;
cout << "Max queue size for window 2 : "
<< W2.size() << endl;
cout << "Max queue size for window 3 : "
<< W3.size() << endl;
cout << "Max queue size for Kiosk 1 : "
<< K1.size() << endl;
cout << "Max queue size for Kiosk 2 : "
<< K2.size() << endl;
int wait_time = 0;
float avg_W1 = 0;
int W1_len = W1.size();
while(!W1.empty())
// Processing Window 1
{
avg_W1 += wait_time;
if(W1.front() == "G")
{
wait_time
+= 4;
}
else if(W1.front() ==
"R")
{
wait_time
+= 2;
}
else
{
wait_time
+= 2;
}
W1.pop();
}
avg_W1 = avg_W1/W1_len;
int t2e_W1 = wait_time;
wait_time = 0;
float avg_W2 = 0;
int W2_len = W2.size();
while(!W2.empty())
// Processing Window 2
{
avg_W2 += wait_time;
if(W2.front() == "G")
{
wait_time
+= 4;
}
else if(W2.front() ==
"R")
{
wait_time
+= 2;
}
else
{
wait_time
+= 2;
}
W2.pop();
}
avg_W2 = avg_W2/W2_len;
int t2e_W2 = wait_time;
wait_time = 0;
float avg_W3 = 0;
int W3_len = W3.size();
while(!W3.empty()) // Processing Window 3
{
avg_W3 += wait_time;
if(W3.front() == "G")
{
wait_time
+= 4;
}
else if(W3.front() ==
"R")
{
wait_time
+= 2;
}
else
{
wait_time
+= 2;
}
W3.pop();
}
avg_W3 = avg_W3/W3_len;
int t2e_W3 = wait_time;
wait_time = 0;
float avg_K1 = 0;
int K1_len = K1.size();
while(!K1.empty())
// Processing Kiosk 1
{
avg_K1 += wait_time;
if(K1.front() == "I")
{
wait_time
+= 1;
}
else {
wait_time
+= 3;
}
K1.pop();
}
avg_K1 = avg_K1/K1_len;
int t2e_K1 = wait_time;
wait_time = 0;
float avg_K2 = 0;
int K2_len = K2.size();
while(!K2.empty())
// Processing Kiosk 2
{
avg_K2 += wait_time;
if(K2.front() == "I")
{
wait_time
+= 1;
}
else {
wait_time
+= 3;
}
K2.pop();
}
avg_K2 = avg_K2/K2_len;
int t2e_K2 = wait_time;
cout << "\nFor Window 1 : \n";
cout << "Average Wait Time : " <<
avg_W1 << " \n";
cout << "Time to empty : " << t2e_W1
<< " \n";
cout << "\nFor Window 2 : \n";
cout << "Average Wait Time : " <<
avg_W2 << " \n";
cout << "Time to empty : " << t2e_W2
<< " \n";
cout << "\nFor Window 3 : \n";
cout << "Average Wait Time : " <<
avg_W3 << " \n";
cout << "Time to empty : " << t2e_W3
<< " \n";
cout << "\nFor Kiosk 1 : \n";
cout << "Average Wait Time : " <<
avg_K1 << " \n";
cout << "Time to empty : " << t2e_K1
<< " \n";
cout << "\nFor Kiosk 2 : \n";
cout << "Average Wait Time : " <<
avg_K2 << " \n";
cout << "Time to empty : " << t2e_K2
<< " \n";
return 0;
}
Screenshots:
Queue:

Code:





OUTPUT:

If any issue do comment, will resolve asap :-)