Question: c++: implement customer.h, QueueType.h, QueueType.cpp, PriorityQueue.cpp, and PriorityQueue.cpp bank simulator where the program will take number of tellers, arrival time and service time. Example of

c++: implement customer.h, QueueType.h, QueueType.cpp, PriorityQueue.cpp, and PriorityQueue.cpp bank simulator where the program will take number of tellers, arrival time and service time.

Example of input:

numberOfTellers3

customer1 arrival 15 service 60

customer2 arrival 30 service 30

customer3 arrival 50 service 114

customer4 arrival 65 service 22

There are three workers for bank in this particular example. Since customer1 walks in without any customer, customer1 will get the service right away. Customer1 depart time can be calculated by adding arrival time and service time: 75 (15+60). Customer2 gets service immediately since arrival is 30. Customer2 will depart at 60. Customer3 can be serviced immideately as well since there are three workers and arrive time is before customer4. Customer3 will depart at time 164. Customer4's arrival time is 65 and since all tellers are busy he has to wait. Since customer2 departs the earliest customer4 will get the service from the teller who served customer2. Customer4's deapart tiem will be customer2's deaprttime + customer4's service time. (60+ 22) which is 88.

The output of the program must look like this:

customer2 wait 0 service 60

customer1 wait 0 service 75

customer4 wait 5 service 88

customer3 wait 0 service 164

Your program must declare two instances of the QueType class. The first will store information about each customer arrival that has not yet been processed. When your program starts, you should open the input file and read in the customer arrival data (for at least 10 customers). For each arrival, create a QueueItem and insert it into the queue. You can assume that the data stored in the file will be sorted by arrival time.

The second instance of QueueType will store information about customers waiting in line. In other words, if a customer arrives and cannot be serviced, that customer's arrival and service information is stored in the waiting queue. ItemType for this First In First Out queue is Customer.

Your program must also declare an instance of the PriorityQueue to store information about customers currently being serviced. When a teller is freed, the next customer in the waiting line is removed from the waiting line and put into the line of customers being serviced (PriorityQueue).

The PriorityQueue enqueue function will insert items (customers) into the queue where departure time is considered as the priority of the inserted item (i.e. an item i has a departure time less than the departure times of all items after i in the queue.) If no customers are waiting, the teller remains unoccupied until another customer arrives.

The Customer class:

This class has data members customer name(String), Arrival (int), service (int) and wait(int). member functions are: At least setters and getters for all data members.

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

codes:

QueueType.h

class FullQueue

{};

class EmptyQueue

{};

typedef char ItemType;

class QueType

{

public:

QueType();

// Class constructor.

// Because there is a default constructor, the precondition

// that the queue has been initialized is omitted.

QueType(int max);

// Parameterized class constructor.

~QueType();

// Class destructor.

void MakeEmpty();

// Function: Initializes the queue to an empty state.

// Post: Queue is empty.

bool IsEmpty() const;

// Function: Determines whether the queue is empty.

// Post: Function value = (queue is empty)

bool IsFull() const;

// Function: Determines whether the queue is full.

// Post: Function value = (queue is full)

void Enqueue(ItemType newItem);

// Function: Adds newItem to the rear of the queue.

// Post: If (queue is full) FullQueue exception is thrown

// else newItem is at rear of queue.

void Dequeue(ItemType& item);

// Function: Removes front item from the queue and returns it in item.

// Post: If (queue is empty) EmptyQueue exception is thrown

// and item is undefined

// else front element has been removed from queue and

// item is a copy of removed element.

private:

int front;

int rear;

ItemType* items;

int maxQue;

};

QueueType.cpp #include "QueType.h"

QueType::QueType(int max)

// Parameterized class constructor

// Post: maxQue, front, and rear have been initialized.

// The array to hold the queue elements has been dynamically

// allocated.

{

maxQue = max + 1;

front = maxQue - 1;

rear = maxQue - 1;

items = new ItemType[maxQue];

}

QueType::QueType() // Default class constructor

// Post: maxQue, front, and rear have been initialized.

// The array to hold the queue elements has been dynamically

// allocated.

{

maxQue = 501;

front = maxQue - 1;

rear = maxQue - 1;

items = new ItemType[maxQue];

}

QueType::~QueType() // Class destructor

{

delete [] items;

}

void QueType::MakeEmpty()

// Post: front and rear have been reset to the empty state.

{

front = maxQue - 1;

rear = maxQue - 1;

}

bool QueType::IsEmpty() const

// Returns true if the queue is empty; false otherwise.

{

return (rear == front);

}

bool QueType::IsFull() const

// Returns true if the queue is full; false otherwise.

{

return ((rear + 1) % maxQue == front);

}

void QueType::Enqueue(ItemType newItem)

// Post: If (queue is not full) newItem is at the rear of the queue;

// otherwise a FullQueue exception is thrown.

{

if (IsFull())

throw FullQueue();

else

{

rear = (rear +1) % maxQue;

items[rear] = newItem;

}

}

void QueType::Dequeue(ItemType& item)

// Post: If (queue is not empty) the front of the queue has been

// removed and a copy returned in item;

// othersiwe a EmptyQueue exception has been thrown.

{

if (IsEmpty())

throw EmptyQueue();

else

{

front = (front + 1) % maxQue;

item = items[front];

}

}

PriorityQueue.h

#include

#include

template

struct QueueNode

{

ItemType info;

int priority;

QueueNode* next;

};

class FullQueue

{};

class EmptyQueue

{};

template

class PriorityQueue

{

public:

PriorityQueue();

// Class constructor.

PriorityQueue(int max);

~PriorityQueue();

void MakeEmpty();

bool IsEmpty() const;

bool IsFull() const;

void Enqueue(ItemType newItem, int priority=1);

ItemType Dequeue();

int Length();

int Peek();

ItemType PeekPriority();

void PrintQueue(std::ostream &out);

private:

QueueNode* front;

int cap;

int queueNodeLength;

};

PriorirtyQueue.cpp

//Include the files

#include

#include

#include "PriorityQueue.h"

using std::exception;

using namespace std;

//Constructor

template

PriorityQueue::PriorityQueue()

{

cap=100;

queueNodeLength=0;

front=NULL;

}

//Constructor

template

PriorityQueue::PriorityQueue(int max)

{

cap=max;

queueNodeLength=0;

front=NULL;

}

//Define method to get the length

template

int PriorityQueue::Length()

{

return queueNodeLength;

}

//Define MakeEmpty()

template

void PriorityQueue::MakeEmpty()

{

//Define

QueueNode * tp=front;

//Loop

while(tp!=NULL)

{

//Get current node

QueueNode * deleNode=tp->next;

//Remove

delete tp;

//Set value

tp=deleNode;

}

//Set

front=NULL;

//Set value

queueNodeLength=0;

}

//Define method IsFull()

template

bool PriorityQueue::IsFull() const

{

//Check condition

return (queueNodeLength==cap);

}

//Define IsEmpty()

template

bool PriorityQueue::IsEmpty() const

{

//Check condition

return (front == NULL);

}

//Define Dequeue()

template

ItemType PriorityQueue::Dequeue()

{

//Check condition

if (IsEmpty())

throw EmptyQueue();

//Else

else

{

//Declare

QueueNode *tkp = front;

//Set value

ItemType retVal=tkp->info;

//Set value

front = front->next;

//Delete

free(tkp);

//Decrease size

queueNodeLength--;

//return

return retVal;

}

}

//Define Enqueue()

template

void PriorityQueue::Enqueue(ItemType newItem, int priority)

{

//Check condition

if (IsFull())

throw FullQueue();

//Otherwise

else

{

//Define

QueueNode *tkp, *q;

//Set vlaue

tkp = new QueueNode;

//Set value

tkp->info = newItem;

//Set priority

tkp->priority = priority;

//Check condition

if (front == NULL || priority < front->priority)

{

//Set value

tkp->next = front;

//Set value

front = tkp;

}

//Otherwise

else

{

//Set value

q = front;

//Loop

while (q->next != NULL && q->next->priority <= priority)

//Set value

q=q->next;

//Set value

tkp->next = q->next;

//Set

q->next = tkp;

}

//Decrease size

queueNodeLength++;

//Display

cout<

}

}

//Define Peek()

template

int PriorityQueue::Peek()

{

//Check condition

if (IsEmpty())

//Throw

throw EmptyQueue();

//Return

return front->info;

}

//Define PeekPriority()

template

ItemType PriorityQueue::PeekPriority()

{

//Check condition

if (IsEmpty())

throw EmptyQueue();

//Return

return front->priority;

}

//Define PrintQueue()

template

void PriorityQueue::PrintQueue(std::ostream &out)

{

//outputline

out<

//Set value

QueueNode *tkp=front;

//Check condition

if (IsEmpty())

//Throw

throw EmptyQueue();

//Otherwise

else

{

//Loop

while(tkp!= NULL)

{

//Display

out

//Next

tkp = tkp->next;

}

//OutputLine

out<

}

}

//Define destructor

template

PriorityQueue::~PriorityQueue()

{

//Call Function

MakeEmpty();

}

Customer.h

#include using namespace std;

class Customer { private: string name; int arrival; int service; int wait; Customer() { name = ""; Arrival = 0; service = 0; wait = 0; } Customer(string newName, int newArrival, int nweService, int newWait) { name = newName; arrival = newArrival; service = nweService; wait = newWait; }

void setName(string newName) { name = newName; }

void getName() const { return name; }

void setArrival(int newArrival) { arrival = newArrial; }

void getArrival() const { return arrival; }

void setService(int newService) const { service = newService; }

void getService() const { return service; }

void setWait(int newWait) const { wait = newWait; }

void getWait() const { return wait; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!