Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Full code to implement the queue system simulation is attached. Understand the c

ID: 3540026 • Letter: F

Question

Full code to implement the queue system simulation is attached. Understand the code and use it as the starting point for the following simulation.

Let us say, we have two queues, regular queue and special queue in a super-market. Let us say, when server becomes available, (s)he services the next person in the special queue, if one exists in that queue. Otherwise, (s)he services the next person in the regular queue. Model this scenario, make the necessary code changes, find the average waiting times for both regular customers and special customers for various special customer% values as mentioned below and update the Excel spreadsheet using that data - A chart will appear in Chart1 tab automatically. Use the following configuration to run simulations: # of servers: 1, inter-arrival time: 5 and service time: 4. Run each simulation for 10,000 time units.

- 10% of incoming customers are special customers
- 20% %u2026
- 30%
- 40%
- 50%
- 100%
- 0%


//Header file QueueAsArray

#ifndef H_QueueAsArray
#define H_QueueAsArray

#include <iostream>
#include <cassert>

using namespace std;

template<class Type>
class queueType
{
public:
    const queueType<Type>& operator=(const queueType<Type>&);
        //overload the assignment operator
    void initializeQueue();
        //Function to initialize the queue to an empty state
        //Postcondition: count = 0, queueFront = 0;
        //               queueRear = maxQueueSize - 1;
    void destroyQueue();
        //Function to remove all elements from the queue
        //Postcondition: count = 0, queueFront = 0;
        //               queueRear = maxQueueSize - 1;

    bool isEmptyQueue();
        //Function to determine if the queue is empty.
        //Postcondition: returns true if the queue is empty;
        //               otherwise, it returns false.

    bool isFullQueue();
        //Function to determine if the queue is full.
        //Postcondition: returns true if the queue is full;
        //               otherwise, it returns false.

    void addQueue(const Type& queueElement);
        //Function to add queueElement to the stack
        //Precondition: queue exists and is not full
        //Postcondition: queue is changed and the queueElement
           //               is added to the queue

    Type front();
        //Function to returns the first element of the queue
        //Precondition: queue must exist and is not empty
         //Postcondition: If queue is empty, program terminates;
         //               otherwise the first element of the queue
         //               is returned
    Type back();
        //Function to returns the last element of the queue
        //Precondition: queue must exist and is not empty
         //Postcondition: If queue is empty, program terminates;
         //               otherwise the last element of the queue
        //               is returned
    void deleteQueue();
        //Function to remove the first element of the queue
        //Precondition: queue exists and is not empty
        //Postcondition: queue is changed and the first element
        //               is removed from the queue.

    queueType(int queueSize = 100);
        //constructor
    queueType(const queueType<Type>& otherQueue);
         // copy constructor
    ~queueType();
         //destructor

private:
    int maxQueueSize;
    int count;
    int queueFront;
    int queueRear;
    Type *list;     //pointer to the array that holds
                 //the queue elements
};


template<class Type>
void queueType<Type>::initializeQueue()
{
    queueFront = 0;
    queueRear = maxQueueSize - 1;
    count = 0;
}


template<class Type>
void queueType<Type>::destroyQueue()
{
    queueFront = 0;
    queueRear = maxQueueSize - 1;
    count = 0;
}


template<class Type>
bool queueType<Type>::isEmptyQueue()
{
   return(count == 0);
}

template<class Type>
bool queueType<Type>::isFullQueue()
{
   return(count == maxQueueSize);
}


template<class Type>
void queueType<Type>::addQueue(const Type& newElement)
{
   if(!isFullQueue())
   {  
        queueRear = (queueRear + 1) % maxQueueSize; //use mod operator
                        //to advance queueRear because
                         //the array is circular
           count++;
           list[queueRear] = newElement;
   }
   else
        cout<<"Cannot add to a full queue"<<endl;
}


template<class Type>
Type queueType<Type>::front()
{
   assert(!isEmptyQueue());
   return list[queueFront];
}

template<class Type>
Type queueType<Type>::back()
{
     assert(!isEmptyQueue());
     return list[queueRear];
}


template<class Type>
void queueType<Type>::deleteQueue()
{
   if(!isEmptyQueue())
   {  
        count--;
           queueFront = (queueFront + 1) % maxQueueSize; //use the mod
                        //operator to advance queueFront
                         //because the array is circular
   }
   else
        cout<<"Cannot remove from an empty queue"<<endl;
}


//constructor
template<class Type>
queueType<Type>::queueType(int queueSize)  
{
    if(queueSize <= 0)
    {
        cout<<"Size of the array to hold the queue must "
            <<"be positive."<<endl;
        cout<<"Creating an array of size 100."<<endl;

        maxQueueSize = 100;
    }
    else
           maxQueueSize = queueSize; //set maxQueueSize to queueSize

    queueFront = 0;                   //initialize queueFront
    queueRear = maxQueueSize - 1;        //initialize queueRear
    count = 0;
    list = new Type[maxQueueSize]; //create the array to
                            //hold the queue elements
    assert(list != NULL);
}


template<class Type>
queueType<Type>::~queueType()   //destructor
{
   delete [] list;
}

template<class Type>
const queueType<Type>& queueType<Type>::operator=
                       (const queueType<Type>& otherQueue)
{
    cout<<"Write the definition of the function "
        <<"to overload the assignment operator"<<endl;
}

template<class Type>
queueType<Type>::queueType(const queueType<Type>& otherQueue)
{
    cout<<"Write the definition of the copy constructor"<<endl;
}


#endif


#include <iostream>
#include <string>
#include <cstdlib>

#include "Simulation.h"
#include "queueAsArray.h"

using namespace std;


//*************** customerType ************

customerType::customerType(int customerN, int arrvTime, int wTime,
                           int tTime)
{
    setCustomerInfo(customerN, arrvTime, wTime, tTime);
}

int customerType::getWaitingTime() const
{
    return waitingTime;
}

void customerType::incrementWaitingTime()
{
    waitingTime++;
}

void customerType::setWaitingTime(int time)
{
    waitingTime = time;
}

void customerType::setCustomerInfo(int customerN, int arrvTime,
                                   int wTime, int tTime)
{
    customerNumber = customerN;
    arrivalTime = arrvTime;
    waitingTime = wTime;
    transactionTime = tTime;
}

int customerType::getArrivalTime()
{
    return arrivalTime;
}

int customerType::getTransactionTime()
{
    return transactionTime;
}

int customerType::getCustomerNumber()
{
    return customerNumber;
}
//**************** serverType **********

serverType::serverType()
{
    status = "free";
    transactionTime = 0;
}

bool serverType::isFree() const
{
    return (status == "free");
}

void serverType::setBusy()
{
    status = "busy";
}

void serverType::setFree()
{
    status = "free";
}

void serverType::setTransactionTime(int t)
{
    transactionTime = t;
}

void serverType::setTransactionTime()
{
    int time;

    time = currentCustomer.getTransactionTime();

    transactionTime = time;
}


void serverType::decreaseTransactionTime()
{
    transactionTime--;
}

int serverType::getRemainingTransactionTime()
{
    return transactionTime;
}

void serverType::setCurrentCustomer(customerType cCustomer)
{
    currentCustomer = cCustomer;
}

int serverType::getCurrentCustomerNumber()
{
    return currentCustomer.getCustomerNumber();
}

int serverType::getCurrentCustomerArrivalTime()
{
    return currentCustomer.getArrivalTime();
}

int serverType::getCurrentCustomerWaitingTime()
{
    return currentCustomer.getWaitingTime();
}

int serverType::getCurrentCustomerTransactionTime()
{
    return currentCustomer.getTransactionTime();
}


//************** serverListType ***********

serverListType::serverListType(int num)
{
    numOfServers = num;
    servers = new serverType[num];
}

serverListType::~serverListType()
{
    delete [] servers;
}

int serverListType::getFreeServerID()
{
    int serverID = -1;

    int i;

    for(i = 0; i < numOfServers; i++)
        if(servers[i].isFree())
        {
            serverID = i;
            break;
        }
    return serverID;
}

int serverListType::getNumberOfBusyServers()
{
    int busyServers = 0;

    int i;

    for(i = 0; i < numOfServers; i++)
        if(!servers[i].isFree())
            busyServers++;
    return busyServers;
}

void serverListType::setServerBusy(int serverID,
                                   customerType cCustomer,
                                   int tTime)
{
    servers[serverID].setBusy();
    servers[serverID].setTransactionTime(tTime);
    servers[serverID].setCurrentCustomer(cCustomer);
}

void serverListType::setServerBusy(int serverID,
                                   customerType cCustomer)
{
    int time;

    time = cCustomer.getTransactionTime();

    servers[serverID].setBusy();
    servers[serverID].setTransactionTime(time);
    servers[serverID].setCurrentCustomer(cCustomer);
}

void serverListType::updateServers()
{
    int i;

    for(i = 0; i < numOfServers; i++)
        if(!servers[i].isFree())
        {
            servers[i].decreaseTransactionTime();
            if(servers[i].getRemainingTransactionTime() == 0)
            {
                cout<<"Server No: "<<(i+1)<<" Customer number "
                    <<servers[i].getCurrentCustomerNumber()
                    <<" departed at "<<endl
                    <<"             clock unit "
                    <<servers[i].getCurrentCustomerArrivalTime()
                    + servers[i].getCurrentCustomerWaitingTime()
                    + servers[i].getCurrentCustomerTransactionTime()
                    <<endl;
                servers[i].setFree();
            }
        }
}

void serverListType::updateServers(ofstream& outFile)
{
    int i;

    for(i = 0; i < numOfServers; i++)
        if(!servers[i].isFree())
        {
            servers[i].decreaseTransactionTime();
            if(servers[i].getRemainingTransactionTime() == 0)
            {
                outFile<<"Server No: "<<(i+1)<<" Customer number "
                       <<servers[i].getCurrentCustomerNumber()
                        <<" departed at "<<endl
                        <<"             clock unit "
                        <<servers[i].getCurrentCustomerArrivalTime()
                        + servers[i].getCurrentCustomerWaitingTime()
                        + servers[i].getCurrentCustomerTransactionTime()
                        <<endl;
                servers[i].setFree();
            }
        }
}

//*************** waitQueue ************


waitingCustomerQueueType::waitingCustomerQueueType(int size)
                          :queueType<customerType>(size)
{
}

waitingCustomerQueueType::~waitingCustomerQueueType()
{
}

void waitingCustomerQueueType::updateWaitingQueue()
{
    customerType cust;

    cust.setWaitingTime(-1);
    int wTime = 0;
   
    addQueue(cust);

    while(wTime != -1)
    {
        cust = front();
        deleteQueue();

        wTime = cust.getWaitingTime();
        if(wTime == -1)
            break;
        cust.incrementWaitingTime();
        addQueue(cust);
    }
}


#include <fstream>
#include <string>
#include "queueAsArray.h"

using namespace std;


//**************** customerType ****************

class customerType
{
public:
    customerType(int customerN = 0, int arrvTime = 0,
                 int wTime = 0, int tTime = 0);
    //constructor to initialize the data members
    //according to the parameters
    //In the object declaration if no value is specified,
    //the default is assigned.
    //Postcondition: customerNumber = customerN;
    //                 arrivalTime = arrvTime;
    //               waitingTime = wTime;
    //                 transactionTime = tTime
    void setCustomerInfo(int customerN, int arrvTime,
                         int wTime, int tTime);
    //Function to set the data members according
        //to the parameters.
    //Postcondition: customerNumber = customerN;
    //                 arrivalTime = arrvTime;
    //               waitingTime = wTime;
    //                 transactionTime = tTime
    int getWaitingTime() const;
    //Function to return the waiting time of a customer.
    //Postcondition: The value of waitingTime is returned.
    void setWaitingTime(int time);
    //Function to set the waiting time of a customer.
    //Postcondition: waitingTime = time
    void incrementWaitingTime();
    //Function to increment the waiting time.
    //Postcondition: waitingTime++
    int getArrivalTime();
    //Function to return the arrival time of a customer.
    //Postcondition: The value of arrivalTime is returned.
    int getTransactionTime();
    //Function to return the transaction time of a customer.
     //Postcondition: The value of transactionTime is returned.
    int getCustomerNumber();
    //Function to return the customer number.
    //Postcondition: The value of customerNumber is returned.

private:
    int customerNumber;
    int arrivalTime;
    int waitingTime;
    int transactionTime;
};


    //************* serverType ****************

class serverType
{
public:
    serverType();
        //default constructor
        //Set the values of the data members to their default
        //values.
        //Postcondition: currentCustomer is initialized by its
        //               default constructor; status = "free";
        //               the transaction time is initialized to 0.
    bool isFree() const;
        //Function to determine whether a server is free.
        //Postcondition: Returns true if the server is free;
        //               otherwise, returns false.
    void setBusy();
        //Function to set the status of a server to "busy".
        //Postcondition: status = "busy"
    void setFree();
        //Function to set the status of a server to "free".
        //Postcondition: status = "free"
    void setTransactionTime(int t);
        //Function to set the transaction time according
        //to the parameter t.
        //Postcondition: transactionTime = t
    void setTransactionTime();
        //Function to set the transaction time according
        //to the transaction time of the current customer.
        //Postcondition:
        //   transactionTime = currentCustomer.transactionTime
    int getRemainingTransactionTime();
        //Function to return the remaining transaction time.
        //Postcondition: The value of the data member
        //               transactionTime is returned.
    void decreaseTransactionTime();
        //Function to decrease the transaction time by 1.
        //Postcondition: transactionTime--
    void setCurrentCustomer(customerType cCustomer);
        //Function to set the info of the current customer
        //according to the parameter cCustomer.
        //Postcondition: currentCustomer = cCustomer
    int getCurrentCustomerNumber();
        //Function to return the customer number of the
        //current customer.
        //Postcondition: The value of the data member
        //               customerNumber of the current customer
        //               is returned.
    int getCurrentCustomerArrivalTime();
        //Function to return the arrival time of the current customer.
        //Postcondition: The value of the data member arrivalTime
        //               of the current customer is returned.
    int getCurrentCustomerWaitingTime();
        //Function to return the current waiting time of the
        //current customer.
        //Postcondition: The value of the data member
        //               waitingTime of the current
        //               customer is returned.
    int getCurrentCustomerTransactionTime();
        //Function to return the transaction time of the
        //current customer.
        //Postcondition: The value of the data member
        //               transactionTime of the current customer
        //               is returned.

private:
    customerType currentCustomer;
    string status;
    int transactionTime;
};


class serverListType
{
public:
   serverListType(int num = 1);
        //constructor to initialize a list of servers
        //Postcondition: numOfServers = num
        //   A list of servers, specified by num, is created.
        //   If no value is specified for num, its default
        //   value is assumed
   ~serverListType();
        //destructor
        //Postcondition: The list of servers is destroyed.
   int getFreeServerID();
        //Function to search the list of servers.
        //Postcondition: If a free server is found, return its ID;
        //   otherwise, return -1.
   int getNumberOfBusyServers();
        //Function to return the number of busy servers.
        //Postcondition: The number of busy servers is returned.
   void setServerBusy(int serverID, customerType cCustomer,
                      int tTime);
        //Function to set a server to "busy".
        //Postcondition: To serve the customer specified by
        //    cCustomer the server specified by serverID is set
        //    to busy, and the transaction time is set according
        //    to the parameter tTime.
   void setServerBusy(int serverID, customerType cCustomer);
        //Function to set a server to busy.
        //Postcondition: To serve the customer specified by
        //    cCustomer, the server specified by serverID is
        //    set to "busy", and the transaction time is set
        //    according to the customer%u2019s transaction time.
   void updateServers();
        //Function to update the transaction time of each    
        //busy server.
         //Postcondition: The transaction time of each busy
        //   server is decremented by one time unit. If the
        //   transaction time of a busy server is reduced to
        //   zero, the server is set to free and a message
        //   indicating which customer was served, together
        //   with the customer's departing time, is printed
        //   on the screen.
   void updateServers(ofstream& outFile);
        //Function to update the transaction time of each
        //busy server.
        //Postcondition: The transaction time of each busy
        //   server is decremented by one time unit. If the
        //   transaction time of a busy server is reduced to
        //   zero, the server is set to free and a message
        //   indicating which customer was served, together
        //   with the customer's departing time, is sent to
        //   a file.

private:
    int numOfServers;
    serverType *servers;
};


//**************** waitQueue *************

class waitingCustomerQueueType: public queueType<customerType>
{
public:
    waitingCustomerQueueType(int size = 100);
        //constructor
        //Postcondition: The queue is initialized
         //   according to the parameter size. The value of
        //   size is passed to the constructor of queueType.
        //   If no value is specified for size, its default
        //   value is assumed
    ~waitingCustomerQueueType();
        //destructor
        //Postcondition: The queue is destroyed
    void updateWaitingQueue();
        //Function to increment the waiting time of each
        //customer in the queue by one time unit.
        //Postcondition: The waiting time of each customer in
        //   the queue is incremented by one time unit.
};



Explanation / Answer

Actually ,ordering of the classes must be changed.


#ifndef H_QueueAsArray

#define H_QueueAsArray

#include<queue>

#include <iostream>

#include <cassert>


using namespace std;


template<class Type>

class queueType

{

public:

const queueType<Type>& operator=(const queueType<Type>&);

//overload the assignment operator

void initializeQueue();

//Function to initialize the queue to an empty state

//Postcondition: count = 0, queueFront = 0;

// queueRear = maxQueueSize - 1;

void destroyQueue();

//Function to remove all elements from the queue

//Postcondition: count = 0, queueFront = 0;

// queueRear = maxQueueSize - 1;


bool isEmptyQueue();

//Function to determine if the queue is empty.

//Postcondition: returns true if the queue is empty;

// otherwise, it returns false.


bool isFullQueue();

//Function to determine if the queue is full.

//Postcondition: returns true if the queue is full;

// otherwise, it returns false.


void addQueue(const Type& queueElement);

//Function to add queueElement to the stack

//Precondition: queue exists and is not full

//Postcondition: queue is changed and the queueElement

// is added to the queue


Type front();

//Function to returns the first element of the queue

//Precondition: queue must exist and is not empty

//Postcondition: If queue is empty, program terminates;

// otherwise the first element of the queue

// is returned

Type back();

//Function to returns the last element of the queue

//Precondition: queue must exist and is not empty

//Postcondition: If queue is empty, program terminates;

// otherwise the last element of the queue

// is returned

void deleteQueue();

//Function to remove the first element of the queue

//Precondition: queue exists and is not empty

//Postcondition: queue is changed and the first element

// is removed from the queue.


queueType(int queueSize = 100);

//constructor

queueType(const queueType<Type>& otherQueue);

// copy constructor

~queueType();

//destructor


private:

int maxQueueSize;

int count;

int queueFront;

int queueRear;

Type *list; //pointer to the array that holds

//the queue elements

};



template<class Type>

void queueType<Type>::initializeQueue()

{

queueFront = 0;

queueRear = maxQueueSize - 1;

count = 0;

}



template<class Type>

void queueType<Type>::destroyQueue()

{

queueFront = 0;

queueRear = maxQueueSize - 1;

count = 0;

}



template<class Type>

bool queueType<Type>::isEmptyQueue()

{

return(count == 0);

}


template<class Type>

bool queueType<Type>::isFullQueue()

{

return(count == maxQueueSize);

}



template<class Type>

void queueType<Type>::addQueue(const Type& newElement)

{

if(!isFullQueue())

{

queueRear = (queueRear + 1) % maxQueueSize; //use mod operator

//to advance queueRear because

//the array is circular

count++;

list[queueRear] = newElement;

}

else

cout<<"Cannot add to a full queue"<<endl;

}



template<class Type>

Type queueType<Type>::front()

{

assert(!isEmptyQueue());

return list[queueFront];

}


template<class Type>

Type queueType<Type>::back()

{

assert(!isEmptyQueue());

return list[queueRear];

}



template<class Type>

void queueType<Type>::deleteQueue()

{

if(!isEmptyQueue())

{

count--;

queueFront = (queueFront + 1) % maxQueueSize; //use the mod

//operator to advance queueFront

//because the array is circular

}

else

cout<<"Cannot remove from an empty queue"<<endl;

}



//constructor

template<class Type>

queueType<Type>::queueType(int queueSize)

{

if(queueSize <= 0)

{

cout<<"Size of the array to hold the queue must "

<<"be positive."<<endl;

cout<<"Creating an array of size 100."<<endl;


maxQueueSize = 100;

}

else

maxQueueSize = queueSize; //set maxQueueSize to queueSize


queueFront = 0; //initialize queueFront

queueRear = maxQueueSize - 1; //initialize queueRear

count = 0;

list = new Type[maxQueueSize]; //create the array to

//hold the queue elements

assert(list != NULL);

}



template<class Type>

queueType<Type>::~queueType() //destructor

{

delete [] list;

}


template<class Type>

const queueType<Type>& queueType<Type>::operator=

(const queueType<Type>& otherQueue)

{

cout<<"Write the definition of the function "

<<"to overload the assignment operator"<<endl;

}


template<class Type>

queueType<Type>::queueType(const queueType<Type>& otherQueue)

{

cout<<"Write the definition of the copy constructor"<<endl;

}


#include <fstream>

#include <string>

#include "queueAsArray.h"


using namespace std;



//**************** customerType ****************


class customerType

{

public:

customerType(int customerN = 0, int arrvTime = 0,

int wTime = 0, int tTime = 0);

//constructor to initialize the data members

//according to the parameters

//In the object declaration if no value is specified,

//the default is assigned.

//Postcondition: customerNumber = customerN;

// arrivalTime = arrvTime;

// waitingTime = wTime;

// transactionTime = tTime

void setCustomerInfo(int customerN, int arrvTime,

int wTime, int tTime);

//Function to set the data members according

//to the parameters.

//Postcondition: customerNumber = customerN;

// arrivalTime = arrvTime;

// waitingTime = wTime;

// transactionTime = tTime

int getWaitingTime() const;

//Function to return the waiting time of a customer.

//Postcondition: The value of waitingTime is returned.

void setWaitingTime(int time);

//Function to set the waiting time of a customer.

//Postcondition: waitingTime = time

void incrementWaitingTime();

//Function to increment the waiting time.

//Postcondition: waitingTime++

int getArrivalTime();

//Function to return the arrival time of a customer.

//Postcondition: The value of arrivalTime is returned.

int getTransactionTime();

//Function to return the transaction time of a customer.

//Postcondition: The value of transactionTime is returned.

int getCustomerNumber();

//Function to return the customer number.

//Postcondition: The value of customerNumber is returned.


private:

int customerNumber;

int arrivalTime;

int waitingTime;

int transactionTime;

};



//************* serverType ****************


class serverType

{

public:

serverType();

//default constructor

//Set the values of the data members to their default

//values.

//Postcondition: currentCustomer is initialized by its

// default constructor; status = "free";

// the transaction time is initialized to 0.

bool isFree() const;

//Function to determine whether a server is free.

//Postcondition: Returns true if the server is free;

// otherwise, returns false.

void setBusy();

//Function to set the status of a server to "busy".

//Postcondition: status = "busy"

void setFree();

//Function to set the status of a server to "free".

//Postcondition: status = "free"

void setTransactionTime(int t);

//Function to set the transaction time according

//to the parameter t.

//Postcondition: transactionTime = t

void setTransactionTime();

//Function to set the transaction time according

//to the transaction time of the current customer.

//Postcondition:

// transactionTime = currentCustomer.transactionTime

int getRemainingTransactionTime();

//Function to return the remaining transaction time.

//Postcondition: The value of the data member

// transactionTime is returned.

void decreaseTransactionTime();

//Function to decrease the transaction time by 1.

//Postcondition: transactionTime--

void setCurrentCustomer(customerType cCustomer);

//Function to set the info of the current customer

//according to the parameter cCustomer.

//Postcondition: currentCustomer = cCustomer

int getCurrentCustomerNumber();

//Function to return the customer number of the

//current customer.

//Postcondition: The value of the data member

// customerNumber of the current customer

// is returned.

int getCurrentCustomerArrivalTime();

//Function to return the arrival time of the current customer.

//Postcondition: The value of the data member arrivalTime

// of the current customer is returned.

int getCurrentCustomerWaitingTime();

//Function to return the current waiting time of the

//current customer.

//Postcondition: The value of the data member

// waitingTime of the current

// customer is returned.

int getCurrentCustomerTransactionTime();

//Function to return the transaction time of the

//current customer.

//Postcondition: The value of the data member

// transactionTime of the current customer

// is returned.


private:

customerType currentCustomer;

string status;

int transactionTime;

};



class serverListType

{

public:

serverListType(int num = 1);

//constructor to initialize a list of servers

//Postcondition: numOfServers = num

// A list of servers, specified by num, is created.

// If no value is specified for num, its default

// value is assumed

~serverListType();

//destructor

//Postcondition: The list of servers is destroyed.

int getFreeServerID();

//Function to search the list of servers.

//Postcondition: If a free server is found, return its ID;

// otherwise, return -1.

int getNumberOfBusyServers();

//Function to return the number of busy servers.

//Postcondition: The number of busy servers is returned.

void setServerBusy(int serverID, customerType cCustomer,

int tTime);

//Function to set a server to "busy".

//Postcondition: To serve the customer specified by

// cCustomer the server specified by serverID is set

// to busy, and the transaction time is set according

// to the parameter tTime.

void setServerBusy(int serverID, customerType cCustomer);

//Function to set a server to busy.

//Postcondition: To serve the customer specified by

// cCustomer, the server specified by serverID is

// set to "busy", and the transaction time is set

// according to the customer%u2019s transaction time.

void updateServers();

//Function to update the transaction time of each

//busy server.

//Postcondition: The transaction time of each busy

// server is decremented by one time unit. If the

// transaction time of a busy server is reduced to

// zero, the server is set to free and a message

// indicating which customer was served, together

// with the customer's departing time, is printed

// on the screen.

void updateServers(ofstream& outFile);

//Function to update the transaction time of each

//busy server.

//Postcondition: The transaction time of each busy

// server is decremented by one time unit. If the

// transaction time of a busy server is reduced to

// zero, the server is set to free and a message

// indicating which customer was served, together

// with the customer's departing time, is sent to

// a file.


private:

int numOfServers;

serverType *servers;

};



//**************** waitQueue *************


class waitingCustomerQueueType: public queueType<customerType>

{

public:

waitingCustomerQueueType(int size = 100);

//constructor

//Postcondition: The queue is initialized

// according to the parameter size. The value of

// size is passed to the constructor of queueType.

// If no value is specified for size, its default

// value is assumed

~waitingCustomerQueueType();

//destructor

//Postcondition: The queue is destroyed

void updateWaitingQueue();

//Function to increment the waiting time of each

//customer in the queue by one time unit.

//Postcondition: The waiting time of each customer in

// the queue is incremented by one time unit.

};




#endif


#include <iostream>

#include <string>

#include <cstdlib>


#include "Simulation.h"

#include "queueAsArray.h"


using namespace std;



//*************** customerType ************


customerType::customerType(int customerN, int arrvTime, int wTime,

int tTime)

{

setCustomerInfo(customerN, arrvTime, wTime, tTime);

}


int customerType::getWaitingTime() const

{

return waitingTime;

}


void customerType::incrementWaitingTime()

{

waitingTime++;

}


void customerType::setWaitingTime(int time)

{

waitingTime = time;

}


void customerType::setCustomerInfo(int customerN, int arrvTime,

int wTime, int tTime)

{

customerNumber = customerN;

arrivalTime = arrvTime;

waitingTime = wTime;

transactionTime = tTime;

}


int customerType::getArrivalTime()

{

return arrivalTime;

}


int customerType::getTransactionTime()

{

return transactionTime;

}


int customerType::getCustomerNumber()

{

return customerNumber;

}

//**************** serverType **********


serverType::serverType()

{

status = "free";

transactionTime = 0;

}


bool serverType::isFree() const

{

return (status == "free");

}


void serverType::setBusy()

{

status = "busy";

}


void serverType::setFree()

{

status = "free";

}


void serverType::setTransactionTime(int t)

{

transactionTime = t;

}


void serverType::setTransactionTime()

{

int time;


time = currentCustomer.getTransactionTime();


transactionTime = time;

}



void serverType::decreaseTransactionTime()

{

transactionTime--;

}


int serverType::getRemainingTransactionTime()

{

return transactionTime;

}


void serverType::setCurrentCustomer(customerType cCustomer)

{

currentCustomer = cCustomer;

}


int serverType::getCurrentCustomerNumber()

{

return currentCustomer.getCustomerNumber();

}


int serverType::getCurrentCustomerArrivalTime()

{

return currentCustomer.getArrivalTime();

}


int serverType::getCurrentCustomerWaitingTime()

{

return currentCustomer.getWaitingTime();

}


int serverType::getCurrentCustomerTransactionTime()

{

return currentCustomer.getTransactionTime();

}



//************** serverListType ***********


serverListType::serverListType(int num)

{

numOfServers = num;

servers = new serverType[num];

}


serverListType::~serverListType()

{

delete [] servers;

}


int serverListType::getFreeServerID()

{

int serverID = -1;


int i;


for(i = 0; i < numOfServers; i++)

if(servers[i].isFree())

{

serverID = i;

break;

}

return serverID;

}


int serverListType::getNumberOfBusyServers()

{

int busyServers = 0;


int i;


for(i = 0; i < numOfServers; i++)

if(!servers[i].isFree())

busyServers++;

return busyServers;

}


void serverListType::setServerBusy(int serverID,

customerType cCustomer,

int tTime)

{

servers[serverID].setBusy();

servers[serverID].setTransactionTime(tTime);

servers[serverID].setCurrentCustomer(cCustomer);

}


void serverListType::setServerBusy(int serverID,

customerType cCustomer)

{

int time;


time = cCustomer.getTransactionTime();


servers[serverID].setBusy();

servers[serverID].setTransactionTime(time);

servers[serverID].setCurrentCustomer(cCustomer);

}


void serverListType::updateServers()

{

int i;


for(i = 0; i < numOfServers; i++)

if(!servers[i].isFree())

{

servers[i].decreaseTransactionTime();

if(servers[i].getRemainingTransactionTime() == 0)

{

cout<<"Server No: "<<(i+1)<<" Customer number "

<<servers[i].getCurrentCustomerNumber()

<<" departed at "<<endl

<<" clock unit "

<<servers[i].getCurrentCustomerArrivalTime()

+ servers[i].getCurrentCustomerWaitingTime()

+ servers[i].getCurrentCustomerTransactionTime()

<<endl;

servers[i].setFree();

}

}

}


void serverListType::updateServers(ofstream& outFile)

{

int i;


for(i = 0; i < numOfServers; i++)

if(!servers[i].isFree())

{

servers[i].decreaseTransactionTime();

if(servers[i].getRemainingTransactionTime() == 0)

{

outFile<<"Server No: "<<(i+1)<<" Customer number "

<<servers[i].getCurrentCustomerNumber()

<<" departed at "<<endl

<<" clock unit "

<<servers[i].getCurrentCustomerArrivalTime()

+ servers[i].getCurrentCustomerWaitingTime()

+ servers[i].getCurrentCustomerTransactionTime()

<<endl;

servers[i].setFree();

}

}

}


//*************** waitQueue ************



waitingCustomerQueueType::waitingCustomerQueueType(int size)

:queueType<customerType>(size)

{

}


waitingCustomerQueueType::~waitingCustomerQueueType()

{

}


void waitingCustomerQueueType::updateWaitingQueue()

{

customerType cust;


cust.setWaitingTime(-1);

int wTime = 0;

addQueue(cust);


while(wTime != -1)

{

cust = front();

deleteQueue();


wTime = cust.getWaitingTime();

if(wTime == -1)

break;

cust.incrementWaitingTime();

addQueue(cust);

}

}