Question

In: Computer Science

simulate the reception of a bank in C++ . You will have customers requesting transactions (open...

simulate the reception of a bank in C++ .

You will have customers requesting transactions (open account, deposit money, close account, withdraw money). You are required to simulate per the following parameters and rules: Customers coming at random times Each customer will require random amount of service time You may have 1-3 tellers based on the # of customers Once you have more than 4 customers waiting you need to get the 2nd teller Once you have more than 8 customers waiting you need to get the 3rd teller Once the line size gets smaller, you should remove the tellers in opposite order of their addition (the last one joining should be the first one leaving) The reception operates from 10:00 AM until 1:00 PM At the end of the day, you need to run the following reports: A list of customers coming along with the type of transactions they requested. This report should be sorted by: Last name of the customer Amount of money involved Time of arrival Average waiting time per customers Average number of customers waiting

Solutions

Expert Solution

# include <list.h>
# include <vector.h>
# include <stack.h>
# include <string>

//
//      class Customer
//              a single customer waiting in the bank teller line

class randomInteger {
        public:
                unsigned int operator () (unsigned int);
};

unsigned int randomInteger::operator () (unsigned int max)
{
                // rand return random integer
                // convert to unsigned to make positive
                // take remainder to put in range
        unsigned int rval = rand();
        return rval % max;
}

randomInteger randomizer;

class Customer {
public:
                // constructors
        Customer (int at) : arrivalTime(at), 
                        processTime(2 + randomizer(6)) {}
        Customer () : arrivalTime(0), processTime(0) { }
        
                // operations
        bool done    () { return --processTime < 0; }
        int  arrival () { return arrivalTime; }

        operator < (Customer & c)        // order by arrival time
                { return arrivalTime < c.arrivalTime; }
                
        operator == (Customer & c)  // no two customers are alike
                { return false; }
                
protected:
        unsigned int arrivalTime;
        unsigned int processTime;
};

//
//      class Teller
//              a teller servicing customers in a bank teller line

class Teller {
public:
        Teller() { free = true; }
        
        bool isFree()   // see if teller is free to work
        { 
                if (free) return true;
                if (customer.done())
                        free = true;
                  return free;
        }

        void addCustomer(Customer & c) // start servicing customer
        {
                customer = c;
                free = false;
        }

protected:
        bool free;
        Customer customer;
};

void main() {
        int numberOfTellers = 5;
        int numberOfMinutes = 60;
        double totalWait = 0;
        int numberOfCustomers = 0;
        vector < Teller > teller(numberOfTellers);
        queue < list< Customer > > line;
        
        for (int time = 0; time < numberOfMinutes; time++) {
                if (randomizer(10) < 9) {
                        Customer newCustomer(time);
                        line.push(newCustomer);
                        }
                for (int i = 0; i < numberOfTellers; i++) {
                        if (teller[i].isFree() & ! line.empty()) {
                                Customer frontCustomer = line.front();
                                numberOfCustomers++;
                                totalWait += (time - frontCustomer.arrival());
                                teller[i].addCustomer(frontCustomer);
                                line.pop();
                                }
                        }
                }
        cout << "average wait:" <<   (totalWait / numberOfCustomers) << endl;
}

Other references are:

http://web.eecs.utk.edu/~leparker/Courses/CS302-Fall06/Labs/Lab6/index.html

/* ---program3.cpp------------------------------------------------------------------
   A driver file for the Queue class which simulates a Queue at a bank. User 
   inputs a simulation time, transaction time, number of servers, and how often
   a new customer arrives. The driver then uses the Queue class to determine the
   average wait time of each customer, and how many customers remain in the line
   at the end of the simulation.

   Written by: Tyler Frye                       Tennessee Technological University
   Written for: CSC 2110                        Written on: March 06, 2010
   ---------------------------------------------------------------------------------*/

#include <iostream>
#include <iomanip>
using namespace std;
#include "Queue.h"

struct Teller_s {
        bool active;
        int time_At;
};

int main() {
        //Min/Max values for user input
        const int    MIN_SIM_TIME   = 0, MAX_SIM_TIME   = 10000,
                     MIN_TRANS_TIME = 0, MAX_TRANS_TIME = 100,
                                 MIN_NUM_SERV   = 0, MAX_NUM_SERV   = 10,
                                 MIN_ARRIV_TIME = 0, MAX_ARRIV_TIME = 100;
                                 
        char runAgain = 'Y'; //Set runAgain so the program runs
        int sim_Time, trans_Time, num_Serv, arriv_Time; //User input variables
        int i, c_Time; //Counters
        int customers, wait_Time; //Total customers and integer for customer waiting time
        while (runAgain != 'N') {
                i = 0; c_Time = 0;
                customers = 0; wait_Time = 0;
                
                Queue bankQ; //Create queue object
                
                cout << "\n------------------------------------------"
                         << "\n- Welcome to the Bank Simulation Program -"
                         << "\n------------------------------------------";
                
                //Menu information
                cout << "\n\nPlease input the following data(Time in minutes):\n";
                cout << "\nLength of the Simulation: ";
                cin >> sim_Time;
                while (sim_Time <= MIN_SIM_TIME || sim_Time > MAX_SIM_TIME) {
                        cout << "Invalid input. Please re-enter: ";
                        cin >> sim_Time;
                }
                cout << "Average Transaction Time: ";
                cin >> trans_Time;
                while (trans_Time <= MIN_TRANS_TIME || trans_Time > MAX_TRANS_TIME) {
                        cout << "Invalid input. Please re-enter: ";
                        cin >> trans_Time;
                }
                cout << "Average Number of Servers: ";
                cin >> num_Serv;
                while (num_Serv <= MIN_NUM_SERV || num_Serv > MAX_NUM_SERV) {
                        cout << "Invalid input. Please re-enter: ";
                        cin >> num_Serv;
                }
                cout << "Average Time Between Arrivals: ";
                cin >> arriv_Time;
                while (arriv_Time <= MIN_ARRIV_TIME || arriv_Time > MAX_ARRIV_TIME) {
                        cout << "Invalid input. Please re-enter: ";
                        cin >> arriv_Time;
                }
                
                //Dynamically allocate an array for the teller structure
                Teller_s * tellArray = new Teller_s[num_Serv];
                
                //Set all tellers to empty
                for (i = 0; i < num_Serv; i++) {
                        tellArray[i].active = false;
                        tellArray[i].time_At = trans_Time;
                }
                
                while (c_Time < sim_Time) { //Run until simulation time is reached
                        if (c_Time % arriv_Time == 0) { //Check if a customer should be enqueued
                                bankQ.enqueue();
                                customers++;
                        }

                        for (i = 0; i < num_Serv; i++) {
                                if (tellArray[i].active == false && bankQ.getSize() != 0) { //Dequeue if a teller is open
                                        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--;  //Decrement time spent at teller
                                }
                                if (tellArray[i].time_At == 0) {
                                        tellArray[i].active = false; //Set teller to open if time limit is reached
                                }
                        }
                        
                        wait_Time += bankQ.getSize(); //Set wait time to persons left in queue
                        c_Time++;
                }
                //Output user input data
                cout << "\n---------------"
                         << "\n- Data Output -"
                         << "\n---------------\n";
                         
                cout << setw(31) << left << "Simulation Time: ";
                cout << sim_Time << endl;
                
                cout << setw(31) << left << "Average Transaction Time: ";
                cout << trans_Time << endl;
                
                cout << setw(31) << left << "Average Number of Servers: ";
                cout << num_Serv << endl;
                
                cout << setw(31) << left << "Average Time Between Arrivals: ";
                cout << arriv_Time << endl << endl;
                
                //Output calculated data
                cout << "Average Total Wait Time: ";
                cout << fixed << setprecision(2)
                         << (float)wait_Time/customers;
                cout << "\nCustomers in line at end of simulation: "
                 << bankQ.getSize() << endl;
                
                //Ask to run again
                cout << "\nRun 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);
                }
                //Deallocate teller structure array
                delete [] tellArray;
        }       
        return 0;
}
/* ---Queue.h------------------------------------------------------------------
   A eader file for the Queue class which simulates a Queue in a bank
   environment.   

   Operations are:
   Queue(): Default constructor that sets first and last to null, and size to 0
   enqueue(): Adds a person into the queue and increments mySize
   dequeue(): Removes a person from the queue and decrements mySize
   front(): Returns the object in the front of the queue
   getSize(): Returns the current size of the queue
   ~Queue(): Deallocates the queue      

   Written by: Tyler Frye                       Tennessee Technological University
   Written for: CSC 2110                        Written on: March 06, 2010
   ---------------------------------------------------------------------------------*/
   
#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();
                
                //Destructor
                ~Queue();
                
        private:
                
                class Node {
                
                        public:
                        
                                ElementType data;
                                Node *next;                              

                                Node(ElementType i) { // Node constructor
                                        data = i;
                                        next = NULL;
                                }

                }; //--- end of Node class
                
                typedef Node *NodePointer;
                
                Node *first;
                Node *last;
                int mySize;
                
}; //--- end of Queue class

#endif
/* ---Queue.cpp------------------------------------------------------------------
   An implementation file for the Queue class which simulates a Queue in a bank
   environment.   

   Operations are:
   Queue(): Default constructor that sets first and last to null, and size to 0
   enqueue(): Adds a person into the queue and increments mySize
   dequeue(): Removes a person from the queue and decrements mySize
   front(): Returns the object in the front of the queue
   getSize(): Returns the current size of the queue
   ~Queue(): Deallocates the queue      

   Written by: Tyler Frye                       Tennessee Technological University
   Written for: CSC 2110                        Written on: March 06, 2010
   ---------------------------------------------------------------------------------*/
#include <iostream>
using namespace std;
#include "Queue.h"

Queue::Queue() {
        mySize = 0;
        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;
                first = nPtr;
        } else { //Insert into the queue at the end
                while (predPtr->next) {
                        predPtr = predPtr->next;
                }
                nPtr->next = predPtr->next;
        }
        mySize++;
        last = nPtr; //Set last to new pointer
}

void Queue::dequeue() {
        if (first) {
                NodePointer dPtr = first;
                first = first->next; //Set first to the second node in the list
                delete dPtr; //Delete the node that has been dequeued
        }
        mySize--;
}

ElementType Queue::front() {
        if (first) {
                NodePointer ptr = first;
                return ptr->data;
        }
}

int Queue::getSize() {
        return mySize;
}

Queue::~Queue() {
        if (first) {
                //Deallocate all nodes in queue
                NodePointer current = first;
                NodePointer temp = first;
                
                temp = current->next;
                delete current;
                current = temp;
        }
}

Related Solutions

I will be creating a simulation of the reception of a bank in C++ (based off...
I will be creating a simulation of the reception of a bank in C++ (based off the requirements listed below). I plan to develop a test plan that I will use to make sure the key requirements are all covered by a test case. *I just need help defining how each of the requirements below can be tested. I can use a numbering system to map each requirement to the appropriate test case(s). High level information would be appreciated. I...
A bank provides financial services for customers. A customer approaches a bank branch and can open...
A bank provides financial services for customers. A customer approaches a bank branch and can open bank account(s). Before opening an account, the customer must fill a form for creating a customer record and then submit the form to a staff member. The system will create a new customer personal record based on the captured customer’s details from an online form. Consider the above processing requirements description of the Bank Management System application Your tasks are:            1.Draw the Entity...
Write a C/C++ program that simulate a menu based binary numbercalculator. This calculate shall have...
Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities:Covert a binary string to corresponding positive integersConvert a positive integer to its binary representationAdd two binary numbers, both numbers are represented as a string of 0s and 1sTo reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the following three functions:int binary_to_decimal(string...
Willow Brook National Bank operates a drive-up teller window that allows customers to complete bank transactions...
Willow Brook National Bank operates a drive-up teller window that allows customers to complete bank transactions without getting out of their cars. On weekday mornings, arrivals to the drive-up teller window occur at random, with an arrival rate of 24 customers per hour or 0.4 customers per minute. Also assume that the service times for the drive-up teller follow an exponential probability distribution with a service rate of 36 customers per hour, or 0.6 customers per minute. Determine the probabilities...
Willow Brook National Bank operates a drive-up teller window that allows customers to complete bank transactions...
Willow Brook National Bank operates a drive-up teller window that allows customers to complete bank transactions without getting out of their cars. On weekday mornings, arrivals to the drive-up teller window occur at random, with an arrival rate of 30 customers per hour or 0.5 customers per minute. (a) What is the mean or expected number of customers that will arrive in a four-minute period? (b) Assume that the Poisson probability distribution can be used to describe the arrival process....
Bank A and Bank B have each developed an improved process for serving customers. The waiting...
Bank A and Bank B have each developed an improved process for serving customers. The waiting period from the moment a customer enters until he or she reaches the counter needs to be shortened. A random sample of 10 customers is selected from each bank and the results​ (in minutes) are shown in the accompanying data table Bank A 2.18 2.38 3.02 3.02 3.11 4.57 4.29 4.37 5.28 5.83 Bank B 3.97 4.41 4.13 5.18 5.33 6.84 6.36 8.58 8.55...
You have an open organ pipe that plays a middle C note (262 Hz) at a...
You have an open organ pipe that plays a middle C note (262 Hz) at a temperature of 25 ◦C. (a) How long is this pipe? (b) How many overtones are present within this pipe within the audible range? (c) If the temperature dropped to 5 ◦C, by what percentage would the frequency of this note change? (d) If the pipe had a closed end instead of an open one, what are the frequencies of the first 3 harmonic resonances...
C++ In this assignment you will use your Card class to simulate a deck of cards....
C++ In this assignment you will use your Card class to simulate a deck of cards. You will create a Deck class as follows: The constructor will create a full 52-card deck of cards. 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace for each suit: Clubs, Diamonds, Hearts, Spades Each card will be created on the heap and the deck will be stored using an STL vector of Card pointers. The destructor will free the...
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing...
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing or AWT and relational databases. We will have a Bank Accounts database. Each account will have an account number, the name of the owner and the account balance. The program must allow the following options: a) Create an account: request the account information and save it in the database. b) Enter the ATM: it will allow you to request the account number and will...
If you are the manager of a large retail bank and you find that some customers...
If you are the manager of a large retail bank and you find that some customers are not profitable, how could you manage the divestment process? Please Give a well explained answer using proper terminology
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT