Please provide a new solution code for the following task. This question has been answered before but I'd like to request assistance for a new code.
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:
Please provide entire code and screenshot of output. Thank you!
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
Please upvote if you find this helpful and feel free to comment.
pls don't dislike or like if you are not satisfied.
Get Answers For Free
Most questions answered within 1 hours.