Question

In: Computer Science

To be written in C++. A local movie theater has three ticket windows and two computerized...

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.

Solutions

Expert Solution

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 :-)


Related Solutions

Problem #4 – Logical Operators: Movie Ticket Price The local movie theater in town has a...
Problem #4 – Logical Operators: Movie Ticket Price The local movie theater in town has a ticket price of $12.00. But, if you are a senior (55 and older), or are under 10, or are seeing a matinee which screens from 3 pm to 5 pm, you get the discounted price of $7.00, nice! Hint 1: "55 and older" is INCLUSIVE Hint 2: under 10 is EXCLUSIVE Hint 3: the range 3 to 5 is INCLUSIVE Hint 4: limit 1...
XYZ operates a movie theater. A movie ticket is $16.00 per ticket, and costs nothing
  XYZ operates a movie theater. A movie ticket is $16.00 per ticket, and costs nothing. On average 40% of the customers will buy a soda ($6 each, cost $1); 60% will buy food ($6 average price with a cost of $2). The fixed costs are $387,600. Calculate the break-even quantity and $sales for tickets, soda and food(10 points)   The theater wishes to make $96,900 profit. Calculate the target profit quantity and sales for tickets, soda and popcorn (10 points)...
A movie theater has at most 90 seats available. Each adult movie ticket costs $14, and...
A movie theater has at most 90 seats available. Each adult movie ticket costs $14, and each child movie ticket costs $8. To make a profit, the theater must bring in more than $852 in ticket sales per show. A) In terms of A and C, write an inequality that represents the restriction on total occupancy. B) In terms of A and C, write an inequality that represents the restriction on total ticket sales. C) Make a graph that represents...
To conduct an experiment, a movie theater increased movie ticket prices from $9 to $10 and...
To conduct an experiment, a movie theater increased movie ticket prices from $9 to $10 and measured the change in ticket sales. The theater then gathered data over the following month to determine whether the price increase was profitable. Assume total costs to the theater are the same, whether the price of a ticket is $9 or $10. In order for the ticket price to have been profitable over the month, the elasticity of demand for movie tickets must be...
Consider the movie ticket and popcorn example discussed in Section 17.7. The theater sells two products,...
Consider the movie ticket and popcorn example discussed in Section 17.7. The theater sells two products, tickets and popcorn. Suppose the weekly demand for movie tickets is           Qdtix=500−25Ptix−20Ppopcorn, where Ptix and Ppopcorn are the prices of a ticket and a bag of popcorn, respectively. Suppose that each time a moviegoer buys a ticket, his demand for popcorn is           Qdpopcorn=3−0.4Ppopcorn, where Qdpopcorn is the number of bags of popcorn the moviegoer buys. Suppose further that the theater's...
The local movie theater industry has a demand curve of P=26-.2Q for a movie showing (please...
The local movie theater industry has a demand curve of P=26-.2Q for a movie showing (please note the decimal in front of the 2). It has a supply curve (MC curve) of $2, because the theater figures for each customer there will be a cleanup cost afterwards. In reality, a theater might sell food and drinks for extra profits, but this one does not. What is allocative efficiency? What is the price of a ticket and number of patrons (quantity)...
The local movie theater industry has a demand curve of P=26-.2Q for a movie showing (please...
The local movie theater industry has a demand curve of P=26-.2Q for a movie showing (please note the decimal in front of the 2). It has a supply curve (MC curve) of $2, because the theater figures for each customer there will be a cleanup cost afterwards. In reality, a theater might sell food and drinks for extra profits, but this one does not. What is allocative efficiency? What is the price of a ticket and number of patrons (quantity)...
In Python Suppose there is a movie theater who charges ticket based on ages. Less than...
In Python Suppose there is a movie theater who charges ticket based on ages. Less than 3 years old, free; between 3 to 12, $10; more than 12 years old, $15. Please design a program with loop to, 1) Ask the name then age of the audience, 2) Based on audience's input, tell the audience (with the person's name) how much is the ticket, 3) Stop the program when type in 'quit' in your program.
Instructions: A movie theater only keeps a percentage of the revenue earned from ticket sales. The...
Instructions: A movie theater only keeps a percentage of the revenue earned from ticket sales. The remainder goes to the movie distributor. Write a program that calculates a theater’s gross and net box office profit for a night. The program should ask for the name of the movie, and how many adults and child tickets were sold. The price of an adult ticket is $10.00 ad a child ticket is $6.00.) It should display a report similar to Movie Name:...
Database: Our AD is Movie Theater. Create an ER diagram with the following entities: Staff, Ticket,...
Database: Our AD is Movie Theater. Create an ER diagram with the following entities: Staff, Ticket, Movie, Session, Hall, Seat, Director, Actor, Distributor, and Roles. AND also identify the type of relations between the entities with notations and explain why you used it. **Read the question carefully before you answer**
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT