Question

Please provide a new solution code for the following task. This question has been answered before...

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:

  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

Please provide entire code and screenshot of output. Thank you!

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
This question has been answered before. Please provide a new code and screenshot of output. Thank...
This question has been answered before. Please provide a new code and screenshot of output. Thank you! Create a C# program that accepts an e-mail address and a password as input and validates it using the following methods (Please note, this is not all-inclusive.): For the E-Mail Address: Best practice for validating an email address: It is case sensitive in the local portion of the address (left of the rightmost @ character) Has non-alphanumeric characters in the local-part (including +...
A new rideshare company “Sany” has just entered the Boston market. The company offers 2 types...
A new rideshare company “Sany” has just entered the Boston market. The company offers 2 types of rideshare services, a shared service (called SanyShared) and a non-shared service (called SanyPersonal). In addition, the company also offers a food delivery service, delivering food from merchant restaurants to customers (called SanyFood). A Sany driver would like your help in figuring out how many of each service he should accept. A SanyShared request takes 30 minutes to complete, and pays $5 flat. A...
1. Willow Brook National Bank operates a drive-up teller window that allows customers to complete bank...
1. Willow Brook National Bank operates a drive-up teller window that allows customers to complete bank transactions without getting out of their cars. On weekday mornings, arrivals to the drive-up teller window occur at random, with an arrival rate of 6 customers per hour or 0.1 customers per minute. Also assume that the service times for the drive-up teller follow an exponential probability distribution with a service rate of 54 customers per hour, or 0.9 customers per minute. Determine the...
Matrix Multiplication with Threads - C/C++ **Read entire question before answering** **Don't copy / paste code...
Matrix Multiplication with Threads - C/C++ **Read entire question before answering** **Don't copy / paste code without testing it. I will downvote your answer and mark as spam.** I have posted this question several times, do not copy / paste the same code that has been posted, IT DOESN'T WORK!! In this assignment you will use the Pthreads library to write a program that multiplies two square arrays and compare the difference between the imperative and parallel implementations of this...
This is an intro to Java question. Please include pseudo code for better understanding. I am...
This is an intro to Java question. Please include pseudo code for better understanding. I am hoping to use this to do some reviewing. We are mainly focusing on input and output declarations and invoking API methods. Problem 6: Log It (10 points) Use API (Data Structure Algorithms) High-Low is a simple number guessing game where one player thinks of a random integer number between 0 to some maximum value and another player attempts to guess that number. With each...
This programming task will be a bit different. It will be more like what you would...
This programming task will be a bit different. It will be more like what you would receive if you were a maintenance engineer working in a corporate information systems or technology department. In other words, you will have some prebuilt source code provided for you that you must alter so it will meet the given programming specification.. Build a program from what you have been given as a starting-point. Rename the “starter code”. Do not add any modules; just, use...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments,...
Homework 3 Before attempting this project, be sure you have completed all of the reading assignments, hands-on labs, discussions, and assignments to date. Create a Java class named HeadPhone to represent a headphone set. The class contains:  Three constants named LOW, MEDIUM and HIGH with values of 1, 2 and 3 to denote the headphone volume.  A private int data field named volume that specifies the volume of the headphone. The default volume is MEDIUM.  A private...
I did already posted this question before, I did get the answer but i am not...
I did already posted this question before, I did get the answer but i am not satisfied with the answer i did the code as a solution not the description as my solution, so i am reposting this question again. Please send me the code as my solution not the description In this project, build a simple Unix shell. The shell is the heart of the command-line interface, and thus is central to the Unix/C programming environment. Mastering use of...
Using the following code answer the next couple questions: #include<stdio.h> #include<stdlib.h> #include<string.h> /* Rewrite using a...
Using the following code answer the next couple questions: #include<stdio.h> #include<stdlib.h> #include<string.h> /* Rewrite using a pointer to char str[] */ void array_to_ptr () { int n=0, len; char str[ ] = "Hello World!"; len = strlen(str); for( n=0; n<len; n++) {     putc(str[n], stdout); } printf("\nlength = %d\n", n); } int contains (char * str, char c); int * makearray(int n); int main (void) { printf("Question #2 - array_to_ptr:\n"); array_to_ptr();   printf("\n------------------------------------\n\n"); printf("Question #3 - contains:\n"); printf("Test #1: "); if...
please can you make it simple. For example using scanner or hard coding when it is...
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm 1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT