1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
//Phase II Testing Program
#include<iostream>
#include"DataElement.h"
#include"SortedList.h"
#include"Event.h"
#include"Queue.h"
using namespace std;
const int SIZE = 6;
void processArrival(int& customer, DataElement iFile[], int length, SortedList<Event>& eList, Queue<DataElement>& bQueue);
void processDeparture(SortedList<Event>& eList, Queue<DataElement>& bQueue, int& wTime);
int main()
{
//Set up an array of DataElement with the data the bank provided:
DataElement bankData[SIZE] = { DataElement(20,5), DataElement(22,4), DataElement(23,2), DataElement(30,3), DataElement(40,3), DataElement(41,4) };
Queue<DataElement> bankQueue;//Declare an instance of class template Queue
SortedList<Event> eventList;//Declares an instance of class template List
int customer = 0;
int waitingTime;
int counter = 1;
int totalWaitingTime = 0;
//Create an array to save waiting time and transaction begin time and just add them both above
//Testing the function processArrial():
Event aEvent1('A', 20); //create an arrival event
eventList.insertSorted(aEvent1); //insert above arrival event into eventList
char eStatus = eventList.getEntry(1).getEventStatus();
while (!eventList.isEmpty())
{
char eStatus = eventList.getEntry(1).getEventStatus(); // Saves the event status of an event at position one
if (eStatus == 'A')
{
processArrival(customer, bankData, SIZE, eventList, bankQueue);// Function Call
customer++;
}
else
{
processDeparture(eventList, bankQueue, waitingTime);
}
}
system("pause");
return 0;
}
void processArrival(int& customer, DataElement iFile[], int length, SortedList<Event>& eList, Queue<DataElement>& bQueue)
{
// Check if the bankQueue is empty
if (bQueue.isEmpty())
{
Event eDeparture;
eDeparture.setEventStatus('D'); //Sets the event status
int dOccurrence = iFile[customer].getArrivalTime() + iFile[customer].getTransactionTime(); //Occurrence of the departure
// I want to create an array of int dOccurrence[15] to store all the dOccurrence times
eDeparture.setOccurTime(dOccurrence); //Sets the Occurrence time of the departure
eList.insertSorted(eDeparture); // Added Departure event to eList... using the address of operator, so will this value make it out to the main function?
}
// insert a customer into the bQueue
bQueue.enqueue(iFile[customer]); // Do i start at one? since i added customer 0 already who is also already seeing the teller
eList.remove(1);// does this delete the newest arrival event
if (customer != length - 1)
{
Event aEvent;
aEvent.setEventStatus('A');
int aOccurrence = iFile[customer + 1].getArrivalTime();
aEvent.setOccurTime(aOccurrence);
// to create an array of aOccurrence times can should I use a struct with two int data variables to store aOccurrence and Customer sub 0,1,2,3...
// int aOccurrence = iFile[customer + 1].getArrivalTime() + iFile[customer + 1].getTransactionTime();
}
}
void processDeparture(SortedList<Event>& eList, Queue<DataElement>& bQueue, int& wTime)
{
bQueue.dequeue();
if (!bQueue.isEmpty())
{
//eList.getEntry(1).getOccurTime(); // accesses the list at entry 1, then uses the . operator to get its OccurTime of departur;
Event dEvent('D', eList.getEntry(1).getOccurTime() + bQueue.peekFront().getTransactionTime());
eList.insertSorted(dEvent);
wTime = eList.getEntry(1).getOccurTime() - bQueue.peekFront().getArrivalTime();
}
else
{
wTime = 0;
}
eList.remove(1);
}
|