The Bank Queue Problem

Pages: 12
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//Phase II Testing Program
#include <iostream>
#include <iomanip>
#include"DataElement.h"
#include"SortedList.h"
#include"Event.h"
#include"Queue.h"
#define ANSI_COLOR_GREEN   "\x1b[32m"
#define ANSI_COLOR_RESET   "\x1b[0m"

using namespace std;

const int SIZE = 6;//CONSTANT USED FOR ARRAYS

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()
{
	//Array for the Arrival time and transaction length
	DataElement bankData[SIZE] = { DataElement(20,5), DataElement(22,4), DataElement(23,2), DataElement(30,3), DataElement(40,3), DataElement(41,4) };
	Queue<DataElement> bankQueue;//Declares an instance of class template Queue
	SortedList<Event> eventList;//Declares an instance of class template SortedList

	int customer = 0;
	int waitingTime;
	int counter = 1;
	double totalWaitingTime = 0;
	// Arrays for displaying information
	int transactionTime[SIZE];
	int waitTimes[SIZE];
	int departureTimes[SIZE];
	int transactionStart[SIZE];
	

	//Create an arrival event for customer[0]
	Event aEvent1('A', bankData[customer].getArrivalTime());
	eventList.insertSorted(aEvent1);//Insert arrival event into the eventList
	waitTimes[0] = 0;//Customer[0] walked into an empty bank, wait time is 0

	//Event while loop
	while (!eventList.isEmpty())
	{
		Event eStatus = eventList.getEntry(1);

		if (eStatus.getEventStatus() == 'A')
		{
			processArrival(customer, bankData, SIZE, eventList, bankQueue);// Function Call
			customer++;
		}
		else
		{
			if (counter != SIZE + 1) // ADDED
			{
				//cout << eventList.getEntry(1).getOccurTime() << endl;
				departureTimes[counter - 1] = eventList.getEntry(1).getOccurTime();
				//cout << departureTimes[counter-1] << endl;
			}

			processDeparture(eventList, bankQueue, waitingTime);

			if (counter != SIZE)// ADDED
			{
				waitTimes[counter] = waitingTime;// Waiting time array 
				totalWaitingTime += waitingTime;// Total waiting time to be used for average wait time
				counter++;
			}
		}

	}
	for (int k = 0; k < SIZE; k++)
	{
		transactionStart[k] = bankData[k].getArrivalTime() + waitTimes[k];
	}


	//**************************************************************************************************************************************
	//*******************************************display the information********************************************************************
	cout << "The computer simualtion will commence....." << endl;
	cout << "The data is summerized as follows:" << endl;
	cout << ANSI_COLOR_GREEN << "================================================================================================" << ANSI_COLOR_RESET << endl;
	cout << "Customer";
	cout << setw(20) << "Arrival Time" << setw(26) << "Transaction Begins" << setw(22) << "Departure Time" << setw(20) << "Waiting Time" << endl;
	for (int i = 0; i < SIZE; i++)
	{
		cout << i + 1 << setw(17) << bankData[i].getArrivalTime() << setw(20) << transactionStart[i] << setw(26) << departureTimes[i] << setw(21);
		cout << waitTimes[i] << endl;
	}
	cout << ANSI_COLOR_GREEN << "------------------------------------------------------------------------------------------------" << ANSI_COLOR_RESET << endl;
	cout << "The average wait time of the 6 customers is " << totalWaitingTime / SIZE << endl;
	cout << "Simulaiton is complete" << endl;

	//system("pause");
	return 0;
}
void processArrival(int& customer, DataElement iFile[], int length, SortedList<Event>& eList, Queue<DataElement>& bQueue)
{
	if (bQueue.isEmpty())
	{
		// Enters this IF statment only if the  BANK LINE IS EMPTY 
		Event eDeparture('D', iFile[customer].getArrivalTime() + iFile[customer].getTransactionTime()); //Create and set the departure event
		eList.insertSorted(eDeparture); // Inserts the departure event into the event list
	}

	bQueue.enqueue(iFile[customer]);// Inserts a customer into the bQueue
	eList.remove(1);
	if (customer != length - 1)
	{
		Event aEvent('A', iFile[customer + 1].getArrivalTime());// Creates an arrival event
		eList.insertSorted(aEvent);// Inserts the arrival event into the event list
	}
}

void processDeparture(SortedList<Event>& eList, Queue<DataElement>& bQueue, int& wTime)
{
	bQueue.dequeue();// Keep here
	if (!bQueue.isEmpty())
	{
		Event dEvent('D', eList.getEntry(1).getOccurTime() + bQueue.peekFront().getTransactionTime());// Creates a departure event and sets it
		eList.insertSorted(dEvent);// Inserts the departure event into the event list

		wTime = eList.getEntry(1).getOccurTime() - bQueue.peekFront().getArrivalTime();
	}
	else
	{
		wTime = 0;
	}
	eList.remove(1);
}


when you fix the few bugs in the header files and run this source.cpp you will see what I ended up with. I will check out that site today. Thank you for the advice.
Topic archived. No new replies allowed.
Pages: 12