Question

In: Computer Science

Write a C++ program to simulate a service desk. This service desk should be able to...

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

Tips: Use a loop that will process 100 times, se each service request as an index for the queue, declare random numbers to generate priorities and service times, 5-8 for service, 1-3 for priority, generate 2 deques: one for service, 1 for priority, use push_front(high) and push_front(low) to add values to the deque, for medium priority use size()/2 to find the missle position of the deque using insert(name.insert(position, value).

Solutions

Expert Solution

main.cpp

------------------------------------------------------------------

#include <cstdlib>

#include <iostream>

#include <string>

#include <array>

#include <vector>
#include "Priority.h"

#include "Service.h"

#include "Customer.h"
using namespace std;
const string APP_NAME = "Service Desk Simulation";


const array<string, 3> MENU_OPTIONS = {

"Simulate 1 Service Station",

"Simulate 2 Services Station",

"End Simulation"

};


const int CUSTOMERS = 100;
const int SERVICE_MIN = 5;

const int SERVICE_MAX = 8;
//Print main menu options

void printMenuOptions() {

cout << endl << "---------------------------" << endl;

cout << APP_NAME << endl;

cout << "---------------------------" << endl;
for (int i=0; i<MENU_OPTIONS.size(); i++) {

cout << i+1 << ". " << MENU_OPTIONS[i] << endl;

}
cout << endl << "Select an option: ";

}
//Returns random service duration between 5 and 8
double getRandomServiceDuration() {

return 5 + (static_cast<double>(rand() % (8 - 5 + 1)));

}
//Returns random service priority in {high, medium, low}

Priority getRandomServicePriority() {

Priority p;
int r = 1 + (static_cast<int>(rand() % (3 - 1 + 1)));
switch (r) {

case 1:

p = Priority::high;

break;

case 2:

p = Priority::medium;

break;

case 3:

default:

p = Priority::low;

break;

}
return p;

}


void simulate(int numStations, vector<Service*> services) {

Service* station1;

Service* station2;

int total = 0;

int waiting1 = 0;

int waiting2 = 0;

int totCustHigh = 0;

int totCustMedium = 0;

int totCustLow = 0;

double avgTimeHigh = 0;

double avgTimeMedium = 0;

double avgTimeLow = 0;

double totTimeHigh = 0;

double totTimeMedium = 0;

double totTimeLow = 0;
for (std::vector<Service*>::iterator it = services.begin(); it != services.end(); ++it) {

  

station1 = *(it);
total++;
cout << "Customer #" << total << " Waiting Time @ Station #1:" << waiting1 << " minutes" << endl;
waiting1 += station1->getDuration();
switch (station1->getPriority()) {

case Priority::high:

totCustHigh++;

totTimeHigh += station1->getDuration();

avgTimeHigh = totTimeHigh / totCustHigh;

break;

case Priority::medium:

totCustMedium++;

totTimeMedium += station1->getDuration();

avgTimeMedium = totTimeMedium / totCustMedium;

break;

case Priority::low:

totCustLow++;

totTimeLow += station1->getDuration();

avgTimeLow = totTimeLow / totCustLow;

break;

}
if (numStations == 2) {

++it;

station2 = *(it);

total++;
cout << "Customer #" << total << " Waiting Time @ Station #2:" << waiting2 << " minutes" << endl;
waiting2 += station2->getDuration();
switch (station2->getPriority()) {

case Priority::high:

totCustHigh++;

totTimeHigh += station2->getDuration();

avgTimeHigh = totTimeHigh / totCustHigh;

break;

case Priority::medium:

totCustMedium++;

totTimeMedium += station2->getDuration();

avgTimeMedium = totTimeMedium / totCustMedium;

break;

case Priority::low:

totCustLow++;

totTimeLow += station2->getDuration();

avgTimeLow = totTimeLow / totCustLow;

break;

}
}
}

  

cout << endl;

cout << "Customers served:" << total << " of 100" << endl;

cout << "[Customers by Priority] High:" << totCustHigh;

cout << " Medium:" << totCustMedium;

cout << " Low:" << totCustLow << endl;
cout << "[Average Waiting Time] High:" << avgTimeHigh << " minutes";

cout << " Medium:" << avgTimeMedium << " minutes";

cout << " Low:" << avgTimeLow << " minutes" << endl;
}
int main(int argc, char** argv) {

vector<Service*> services;

bool exitApp = false;

int choice = 0;

  

for (int i=0; i<CUSTOMERS; i++) {

Service * randService = new Service(getRandomServicePriority(), getRandomServiceDuration());

randService->setCustomer(new Customer());

services.push_back(randService);

}
  

while (!exitApp) {

  

printMenuOptions();

cin >> choice;
switch (choice) {

case 1:

  

simulate(1, services);

break;

case 2:

  

simulate(2, services);

break;

case 3:

  

exitApp = true;

break;

default:

cout << endl << "Incorrect choice. Please try again." << endl;

}
}
return 0;

}

------------------------------------------------------------------------------------------------------

Customer.cpp

-------------------------------------------

#include "Customer.h"
Customer::Customer() {

name = "";

}
Customer::Customer(const Customer& orig) {

}
Customer::~Customer() {

}

---------------------------------------------------------------------------------------------------------

Customer.h

--------------------------------------------------

#ifndef CUSTOMER_H

#define CUSTOMER_H
#include <string>
class Customer {

public:

Customer();

Customer(const Customer& orig);

virtual ~Customer();
private:

std::string name;
};
#endif

-------------------------------------------------------------------------------------------------

Service.cpp

------------------------------------------------------------

#include "Service.h"

#include "Priority.h"
Service::Service(Priority _priority, double _duration) {

priority = _priority;

duration = _duration;

}
Service::Service(const Service& orig) {

}
Service::~Service() {

}
Priority Service::getPriority() {

return priority;

}
double Service::getDuration() {

return duration;

}
void Service::setCustomer(Customer* _customer) {

customer = _customer;

}
std::string Service::getPriorityDescription() {

std::string description;
switch (priority) {

case Priority::high:

description = "High";

break;

case Priority::medium:

description = "Medium";

break;

case Priority::low:

description = "Low";

break;

default:

description = "";

break;

}
return description;

}

-------------------------------------------------------------------------------------------

Service.h

-------------------------------------------------

#ifndef SERVICE_H

#define SERVICE_H
#include <string>

#include "Priority.h"

#include "Customer.h"
class Service {

public:

Service(Priority _priority, double _duration);

Service(const Service& orig);

virtual ~Service();
Priority getPriority();

std::string getPriorityDescription();

double getDuration();

Customer* getCustomer();

void setCustomer(Customer* _customer);
private:

Priority priority;

double duration;

Customer* customer;
};
#endif

--------------------------------------------------------------------------------

Priority.h

--------------------------------------------

#ifndef PRIORITY_H

#define PRIORITY_H
enum class Priority { high, medium, low };
#endif


Related Solutions

Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
Write a program to simulate the Distributed Mutual Exclusion in ‘C’.
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
please write in c using linux or unix Write a program that will simulate non -...
please write in c using linux or unix Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Please write in C using linux or unix. Write a program that will simulate non -...
Please write in C using linux or unix. Write a program that will simulate non - preemptive process scheduling algorithm: First Come – First Serve Your program should input the information necessary for the calculation of average turnaround time including: Time required for a job execution; Arrival time; The output of the program should include: starting and terminating time for each job, turnaround time for each job, average turnaround time. Step 1: generate the input data (totally 10 jobs) and...
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program...
Write Algoritm , code and output. In C++ In Operating Systems , Simulate with a program to schedule disk in seek optimization.
Write a Java program to simulate the rolling of two dice. The application should use an...
Write a Java program to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12. Your application should roll the dice 36,000,000 times. Store the results of each roll...
Write a c++ Program To simulate the messages sent by the various IoT devices, a text...
Write a c++ Program To simulate the messages sent by the various IoT devices, a text le called device data.txt is provided that contains a number of device messages sent, with each line representing a distinct message. Each message contains a device name, a status value and a Unix epoch value which are separated by commas. Your c++ program will read this le line by line. It will separate the message into device name, status value and epoch value and...
In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling...
In C, write a program that will simulate the operations of the following Round-Robin Interactive scheduling algorithm. It should implement threads for the algorithm plus the main thread using a linked list to represent the list of jobs available to run. Each node will represent a Job with the following information: int ProcessID int time time needed to finish executing The thread representing the scheduler algorithm should continue running until all jobs end. This is simulated using the time variable...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game...
Programming Language: C++ Overview For this assignment, write a program that will simulate a single game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice is equal to 7 or 11, the player wins immediately....
1) Write an 8051 C program that will simulate a traffic light. Green will turn on...
1) Write an 8051 C program that will simulate a traffic light. Green will turn on for 2 seconds, Yellow for 1 second and Red for 2 seconds. The green, yellow and red LEDs are connected to Ports P11, P12 and P13. 2) Write an 8051 C program that will turn on or turn off an LED using a switch. The LED is connected to Port P15 while the switch is connected to Port P11.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT