C Bank Problem Implement the eventdriven simulation of a ban

C++ Bank Problem

Implement the event-driven simulation of a bank that this chapter described. 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 file of arrival and transaction times. Each line of the file 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 sufficient 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 example, the input file shown in the left columns of the following table should produce the output shown in the right column.

******STL Queue and Priority Queue may be used.

Code given in the book

Solution

// 1. bank.cpp
#include <iostream>
#include <iomanip>
using namespace std;
#include \"Queue.h\"
struct Teller_s {
   bool active;
   int time_At;
};
int main() {
   char runAgain;
   while (runAgain != \'N\') {
       int sim_Time, trans_Time, num_Serv, arriv_Time;
       int i = 0, c_Time = 0; //Counters
       int customers = 0, left, wait_Time = 0;
       Queue bankQ;
      
       cout << \"\ ------------------------------------------\"
           << \"\ - Welcome to the Bank Simulation Program -\"
           << \"\ ------------------------------------------\";
      
       //Menu information
       cout << \"\ \ Please input the following data(Time in minutes):\ \";
       cout << \"\ Length of the Simulation: \";
       cin >> sim_Time;
       cout << \"Average Transaction Time: \";
       cin >> trans_Time;
       cout << \"Average Number of Servers: \";
       cin >> num_Serv;
       cout << \"Average Time Between Arrivals: \";
       cin >> arriv_Time;
      
       Teller_s tellArray[num_Serv];
      
       //Set all tellers to empty
       for (i = 0; i < num_Serv; i++) {
           tellArray[i].active = false;
           tellArray[i].time_At = 0;
       }
      
       while (c_Time < sim_Time) {
      
           if (c_Time % arriv_Time == 0) {
               bankQ.enqueue();
               customers++;
           }
           if (bankQ.front() != NULL) {
               for (i = 0; i < num_Serv; i++) {
                   if (tellArray[i].active == false) {
                       bankQ.dequeue();
                       tellArray[i].active = true;
                       tellArray[i].time_At = trans_Time;                      
                   }
               }
           }
          
          
           for (i = 0; i < num_Serv; i++) {
               if (tellArray[i].active == true) {
                   tellArray[i].time_At--;
               }
               if (tellArray[i].time_At == 0 && tellArray[i].active == true) {
                   tellArray[i].active = false;
               }
           }
          
           left = bankQ.getSize();
           cout << endl << left;
           wait_Time += left;
           c_Time++;
       }
      
       cout << \"\ ---------------\"
           << \"\ - Data Output -\"
           << \"\ ---------------\ \";
          
       cout << \"Simulation Time: \";
       cout << sim_Time << endl;
      
       cout << \"Average Transaction Time: \";
       cout << trans_Time << endl;
      
       cout << \"Average Number of Servers: \";
       cout << num_Serv << endl;
      
       cout << \"Average Time Between Arrivals: \";
       cout << arriv_Time << endl << endl;
      
       cout << \"Average Total Wait Time: \";
       cout << fixed << setprecision(2) << (float)wait_Time/customers;
       cout << endl << wait_Time << endl;
      
       cout << \"\ \ Run the program again? (y/n): \";
       cin >> runAgain;
       runAgain = (char)toupper(runAgain);
       while (runAgain != \'Y\' && runAgain != \'N\') {
           cout << \"Invalid Entry, please re-enter: \";
           cin >> runAgain;
           runAgain = (char)toupper(runAgain);
       }
   }  
   return 0;
}

// 2. LinkedList.h
#ifndef QUEUE
#define QUEUE
#include <iostream>
using namespace std;
typedef int ElementType;
class Queue {
  
   public:
      
       //Default constructor
       Queue();
      
       //Add to the back of the queue
       void enqueue();
      
       //Remove from the front of the queue
       void dequeue();
  
       //Returns the front of the queue
       ElementType front();
      
       //Return size of the queue
       int getSize();
      
   private:
      
       class Node {
      
           public:
          
               ElementType data;
               Node *next, *prev;              
               Node(ElementType i) { // Node constructor
                   data = i;
                   next = NULL;
                   prev = NULL;
               }
       }; //--- end of Node class
      
       typedef Node *NodePointer;
      
       Node *first;
       Node *last;
      
};

// 3. Queue.cpp
#include <iostream>
using namespace std;
#include \"Queue.h\"
Queue::Queue() {
   first = NULL;
   last = NULL;  
}
void Queue::enqueue() {
   NodePointer nPtr = new Node(1);
   NodePointer predPtr = first;
  
   if (first == NULL) { //Insert if queue is empty
       nPtr->next = first;
       nPtr->prev = first;
       first = nPtr;
   } else {
       while (predPtr->next != NULL) {
           predPtr = predPtr->next;
       }
       nPtr->prev = predPtr;
       nPtr->next = predPtr->next;
       predPtr->next = nPtr;
   }
  
   last = nPtr; //Set last to new pointer
}
void Queue::dequeue() {
   NodePointer dPtr = first;
   first = first->next;
}
ElementType Queue::front() {
   NodePointer ptr = first;
   return ptr->data;
}
int Queue::getSize() {
   int mySize = 0;
   NodePointer ptr = first;
   while (ptr != NULL) {
       ptr = ptr->next;
       mySize++;
   }
   return mySize;
}

C++ Bank Problem Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events will represent the line of customers in
C++ Bank Problem Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events will represent the line of customers in
C++ Bank Problem Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events will represent the line of customers in
C++ Bank Problem Implement the event-driven simulation of a bank that this chapter described. A queue of arrival events will represent the line of customers in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site