Question

In: Computer Science

**New code needed! Please do not reference code that has already been answered for this question...

**New code needed! Please do not reference code that has already been answered for this question as that code contains errors***

Write a C++ program to simulate a service desk. This service desk should be able to service customers that can have one of three different priorities (high, medium, and low). The duration for any customer is a random number (between 5 minutes and 8 minutes). You need to write a program that will do the following:

  1. Generate random 100 service requests.
  2. Each service request can be either high, medium, or low priority. (Your program should randomly allocate this priority to each service.)
  3. Each service request may need any time to be serviced between 5 and 8 minutes. (Your program should randomly allocate this time to each service.)
  4. Your program should simulate the case when you have one service station for all customers.
  5. Your program should simulate the case when you have two service stations for these 100 customers.
  6. For each case, output the following statistics:
    1. The number of requests for each priority along with the service time for each request
    2. The waiting time for each service request
    3. The average waiting time for service requests within each priority

You should submit your C++ source code along with screen shots of sample runs that showed successful runs for the above steps.

Solutions

Expert Solution

code in c++ with comments for better understanding.

#include<bits/stdc++.h>
using namespace std;
class Desk{
        public:
        int current_time;
        Desk(){
                current_time=0;
        }
        int getWaitingTime(int arrivalTime){
                //return the waiting time at this desk for a given arrival time
                return max(0, current_time-arrivalTime);
        }
        int process(int serviceTime){
                //process request at this desk and return the current time after service
                current_time+=serviceTime;
                return current_time;
        }

};
class ServiceRequest{
        public:
        static int max_id;
        int id;
        int arrivalTime;
        int service_time;
        int priority;// 0 for low, 1 for medium, 2 for high
        int waiting_time;
        int deskServedAt;//contains the desk at which this service was served
        ServiceRequest(){
                // set request id
                id=(++max_id);
                //assuming all request comes at t=0
                arrivalTime=0;
                //create a service with random priority and service time
                service_time = rand()%4+5;//generates service time between 5-8
                ///assign random priority
                priority=rand()%3;
        }
        //resets the counter for requests
        static void reset(){
                max_id=0;
        }
        void fulfillRequest(int timeFulfilledAt, int desk){
                waiting_time=timeFulfilledAt-service_time-arrivalTime;
                deskServedAt=desk;
        }
        void print(){
                cout<<"Request: #"<<id<<endl<<"Priority: ";
                switch(priority){
                        case 0: cout<<"LOW";
                        break;
                        case 1: cout<<"MEDIUM";
                        break;
                        case 2: cout<<"HIGH";
                        break;
                }
                cout<<endl<<"Service Time: "<<service_time<<" minutes"<<endl;
                cout<<"Service at Station: #"<<deskServedAt<<endl;
                cout<<"Waiting Time: "<<waiting_time<<" minutes"<<endl<<endl;
        }
};
class ServiceDesks{
        public:
        vector<Desk> desks;
        ServiceDesks(int deskCount): desks(deskCount){ServiceRequest::reset();}
        // function to service a request 
        void serviceWithMinimumTime(ServiceRequest &req){
                int arrival_time=req.arrivalTime;
                int min_desk=0;
                int min_time=desks[min_desk].getWaitingTime(arrival_time);
                //get the desk which will result to lowest waiting time
                for(int i=1;i<desks.size();i++){
                        if(min_time>desks[i].getWaitingTime(arrival_time)){
                                min_time = desks[i].getWaitingTime(arrival_time);
                                min_desk=i;
                        }
                }
                //this service will be served at desk min_desk
                int timeFulfilledAt = desks[min_desk].process(req.service_time);
                req.fulfillRequest(timeFulfilledAt, min_desk+1);
                //print request details
                req.print();
        }
};
// set max_id
int ServiceRequest::max_id = 0;

void doSimulation(int numOfRequests, int numberOfStations){
        //scenario one 100 requests with one service station
        int k=1;
        vector<ServiceRequest> arr(numOfRequests);
        //do simulation
        ServiceDesks d(numberOfStations);//with one serving desk
        //find average waiting time for each priority
        vector<float> averages(3,0);
        vector<int> count(3,0);
        for(ServiceRequest req:arr){
                d.serviceWithMinimumTime(req);
                averages[req.priority]+=req.waiting_time;
                count[req.priority]++;
        }
        cout<<"Average Waiting time for Priority HIGH: "<<averages[2]/count[2]<<endl;
        cout<<"Average Waiting time for Priority MEDIUM: "<<averages[1]/count[1]<<endl;
        cout<<"Average Waiting time for Priority LOW: "<<averages[0]/count[0]<<endl;
}
int main()
{
        srand(time(NULL));
        cout<<setprecision(2)<<fixed;
        doSimulation(100, 1);
        doSimulation(100, 2);
}

code screenshot

Sample Output Screenshots


Related Solutions

Please answer with a new answer not one that has already been answered on here before....
Please answer with a new answer not one that has already been answered on here before. Many supervisors are not well-trained on the difficult task of terminating an employee and instead resort to other methods of forcing someone out of the organization. Methods include giving the employee unpleasant work tasks, reducing their hours, or modifying their jobs in some negative way. What are the ethical issues raised by this strategy and what are the risks to the organization?
Question 1 has already been answered. Please answer question 2 below the table only. Find out...
Question 1 has already been answered. Please answer question 2 below the table only. Find out the NPV, IRR and Payback period for each of the following three projects. Assume I=6%.                                                                                                                                    (60 points) Project CF0 CF1 CF2 CF3 CF4 CF5 A -12,000 3000 3000 4000 4000 1000 B -12,000 4000 4000 3000 3000 1000 C -12,000 3000 3000 3000 3000 1000 D -12,000 5000 3000 5000 3000 0 E -12,000 3000 3000 3000 3000 5000 F...
******I KNOW THIS QUESTION HAS ALREADY BEEN ANSWERED; HOWEVER I WOULD LIKE A DIFFERENT ANSWER***** With...
******I KNOW THIS QUESTION HAS ALREADY BEEN ANSWERED; HOWEVER I WOULD LIKE A DIFFERENT ANSWER***** With the aid of supply and demand diagrams, explain how each of the following would likely affect the prices and quantities of cigarettes sold in the US. (a) A cure is found for lung cancer. (b) There is a substantial increase in wages in tobacco growing states. (c) A fertilizer that increases the yield per acre of tobacco is discovered. (d) There is a substantial...
PLEASE ANSWER C&D ONLY . THE REST HAS ALREADY BEEN ANSWERED. Say the marginal tax rate...
PLEASE ANSWER C&D ONLY . THE REST HAS ALREADY BEEN ANSWERED. Say the marginal tax rate is 20 percent and that government expenditures do not change with output. Say also that the economy is at potential output and that the deficit is $450 billion.     a. What is the size of the cyclical deficit? Answer = $0   b. What is the size of the structural deficit?    Answer = $450 billion.    c. How would your answers to a and...
This problem has already been half answered, but can someone finish it and check the answers....
This problem has already been half answered, but can someone finish it and check the answers. I'll include the link. Finished ASAP please! https://www.chegg.com/homework-help/questions-and-answers/use-weighted-average-costing-wanda-company-produces-finished-product-two-processing-depart-q29753062 USE WEIGHTED AVERAGE COSTING: Wanda Company produces its finished product in two processing departments--Mixing and Finishing. The following information is available for the month of March: Mixing Department: The beginning work-in-process inventory was $17,130 ($14,880 direct materials and $2,250 conversion costs) and consisted of 1,200 units. During March, an additional 10,600 units were started into production....
Please note, questions 1 and 2 have already been answered and are listed down below. I...
Please note, questions 1 and 2 have already been answered and are listed down below. I need help with question 3. Case Study: Topic and Detailed Instructions A central theme of contemporary operations management is focus on the customer. This is commonly understood to mean that if a company does focus on its customers and it if is able to consistently deliver what the customer wants in a cost-effective manner, then the company should be successful. The hard part is...
Please answer Question 2 only. Question 1 has been answered, but need to compare answers from...
Please answer Question 2 only. Question 1 has been answered, but need to compare answers from Question 2 with Question 1. Child-abuse victims and developing cancer: Truth or myth? Is physical childhood abuse somehow related to the development of cancer later in life? A recent survey revealed that people who have been physically abused as children were 49% more likely to develop cancer as adults. ------------------------------------------------------------------- 1. Suppose in a region in Saskatchewan, among a group of 20 adults with...
***I understand this question has already been asked, but could I possibly get a new answer?...
***I understand this question has already been asked, but could I possibly get a new answer? I am trying to study a variety of companies and answers so I will be more prepared for whatever is on the test.*** DoorDash as the company. 1. Select a company that has undergone an initial public offering within the last five years and obtain the prospectus (these are usually available on the company’s website, EDGAR for companies listed on the U. S. stock...
***I understand this question has already been asked, but could I possibly get a new answer?...
***I understand this question has already been asked, but could I possibly get a new answer? I am trying to study a variety of companies and answers so I will be more prepared for whatever is on the test.*** DoorDash as the company. 1. Select a company that has undergone an initial public offering within the last five years and obtain the prospectus (these are usually available on the company’s website, EDGAR for companies listed on the U. S. stock...
Just need 2a and 2b answered. Already have number one. Just included in case you needed...
Just need 2a and 2b answered. Already have number one. Just included in case you needed it for part two. 1. On January 1, 2020, Hawkeye Air leased a new airplane for a term of 8 years. The expected life of the airplane is 20 years. There are no rights to purchase the asset at the end of the term, no bargain purchase option, and no residual value guarantee. The lease stipulates that Hawkeye Air makes annual payments of $550,000...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT