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

Implement the event-driven simulation of a bank. A queue of arrival events will

ID: 3823930 • Letter: I

Question

Implement the event-driven simulation of a bank. A queue of arrival events will represent the line of customers in the bank. Maintain the arrival events and departure events in a priority queue, sorted by the time of the event. Use a link-based implementation for the event list. The input is a text le of arrival and transaction times. Each line of the le contains the arrival time and required transaction time for a customer. The arrival times are ordered by increasing time. Your program must count customers and keep track of their cumulative waiting time. These statistics are suf cient to compute the average waiting time after the last event has been processed. Display a trace of the events executed and a summary of the computed statistics (the total number of arrivals and average time spent waiting in line).

For this assignment you may (and probably should) use the C++ STL queue and priority_queue

_________________________________

So at a very high level. You are creating a priority queue that has the events. You can have arrival and departure events. This is sorted by the time of arrival or departure (respectively). Because it is a priority queue, every add or delete action forces the built-in functions of the priority queue to sort it on the time of arrival. Priority queues normally sort o the highest (time) but we want it to sort on lowest. As a result you have a mix of arrival and departure events mixed in with each other.

If it is an arrival type of event at the top of the priority queue: Get the value of the top item, then pop it off. If there are no people in the bankline (queue) and the teller is available then process that event. In processing the event, we add a departure event to the priority queue (and it will sort itself), starting at the current time plus the listed transaction time (teller is unavailable for more customers during that transaction. In that departure even we keep track of the original arrival time.

If it is a departure event at the top of the priority queue: Get the value of the top item then pop it off and process the departure. If there are no people in the bankline (queue). Because someone just finished with the teller, the teller is now available for another customer. Look in the bankline (queue) to see if there are any people in the bankline.

When you have a departure event, you have enough information to determine how much the customer waited.

This is c++ language problem of data structures, can someone help me on this problem?

Explanation / Answer

This is the code for the given query and i hope it helps you to increase your skills on such programs. Hope it helps!!! HEADER FILE #ifndef SIMULATION #include #include #include #include using namespace std; class SimulateClass{ private: typedef list eventList; typedef queue bankQueue; void processArrival(int, ifstream& , eventList&, bankQueue& ); void processDeparture(int, eventList&, bankQueue& ); void displaySimulation(); int arrivalCount; int waitingTime; int departureCalls; int newEvent; public: SimulateClass(); void simulateBank(); }; #endif SOURCE FILE #include "simulation.h" #include #include using namespace std; SimulateClass::SimulateClass():arrivalCount(-1),waitingTime(0),departureCalls(0),newEvent(0){ } void SimulateClass::simulateBank(){ bankQueue bQueue; eventList eList; ifstream inFile; inFile.open("C:\Users\James\Documents\Visual Studio 2008\Projects\bankQueueSim\bankQueueSim\BankList.txt"); if (!inFile) cout > arrivalTime; eList.push_front(arrivalTime); newEvent = eList.front(); while (!eList.empty() ) { newEvent = eList.front(); if ( (newEvent == eList.back() ){ processArrival(newEvent, inFile, eList, bQueue ); ++arrivalCount; } else{ processDeparture(newEvent, eList, bQueue ); ++departureCalls; } } displaySimulation(); } inFile.close(); } void SimulateClass::processArrival( int arrivalEvent, ifstream &inFile , eventList &eList, bankQueue &bQueue ){ int transactionTime, arrivalTime; bool BoolFrontBQueue = bQueue.empty(); bQueue.push(arrivalEvent); eList.remove(arrivalEvent); // changed from pop_front to this. if ( BoolFrontBQueue ){ inFile >> transactionTime; waitingTime = arrivalEvent + transactionTime; eList.push_back(waitingTime); } if ( !inFile.eof() ){ inFile >> arrivalTime; ++arrivalCount; if ( arrivalTime eList.front() eList.push_back(arrivalTime); } } } void SimulateClass::processDeparture(int departureEvent, eventList &eList, bankQueue &bQueue ){ int transactionTime; bQueue.pop(); eList.pop_front(); if (!bQueue.empty() ){ transactionTime = eList.front(); waitingTime = departureEvent + transactionTime; if ( waitingTime eList.front() eList.push_back(waitingTime); } } } void SimulateClass::displaySimulation(){ cout