Bank Simulation problem... error that I cannot find.

I'm doing the classic "bank simulation program" where we must simulate a Queue of customers in a bank, with x amount of tellers and allocate these customers to tellers, etc... One important thing before I go on: we had to write our own Queue & QueueNode class

Anyhow, I think I'm very close, but for whatever reason, I have a problem:

When a customer is assigned to a teller, that teller (which should be busy), is still allowing other customers to be assigned to it.

My original thought was, well this means the teller[i].isFree() function is returning the wrong value, however, I'm pretty confident it is not.

I have attached my code below in the Customer.h, Teller.h, Queue.h, QueueNode.h, and Driver.cpp files. Any guidance would be MUCH appreciated as I am very lost with this error! I even followed the pseudocode from my textbook so something else has to be wrong...Could it be that I'm missing an extra step to check if the time it takes the customer to complete their service with the teller is equal to the system time? (i.e. to check if its expired). This is what I originally thought but I was told this was not so...

Teller.h

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
#ifndef TELLER_H_
#define TELLER_H_

#include <iostream>
#include "Customer.h"
#include "QueueNode.h"
#include "Queue.h"

using namespace std;

class Teller
{
private:
    //bool isOccupied;
    Customer customer;
protected:
    bool free;
public:
    Teller()
    {
        //isOccupied = false;
        free = true;
        Customer *c = &customer;
        c = NULL;
        /*
         * customer = NULL;
         * Customer *c = &customer;
         * c = NULL;
         */
    }
    bool isFree()
    {
        if(free)
            return true;
        if(customer.isDone())
            free = true;
        return free;

        /*
        if(isOccupied == false)
        {
            return true;
        }
        else if(customer.isDone())
        {
            isOccupied = false;
        }
        return isOccupied;
        */
    }
    void addCustomer(Customer C)
    {
        customer = C;
        free = false;
    }
    void CustMinutePasses()
    {
        if(!free)
        {
            customer.MinutePasses();
        }
    }
    Customer & getCustomer()
    {
        return customer;
    }
    void setAvailability(bool b)
    {
        free = b;
    }
};



#endif /* TELLER_H_ */ 


Customer.h:

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
#ifndef CUSTOMER_H_
#define CUSTOMER_H_

#include <iostream>
#include "QueueNode.h"
#include "Queue.h"
#include "Teller.h"
#include <cstdlib>

using namespace std;

class Customer
{
private:
    int serviceTime;
    int arrivalTime;
public:
    Customer()
    {
        serviceTime = 0;
        arrivalTime = 0;
    }

    Customer(int arrival, int maxService)
    {
        arrivalTime = arrival;
        serviceTime = maxService;
    }

    int getServiceTime()
    {
        return serviceTime;
    }
    bool isDone()
    {
        //return (serviceTime-- <= 0);
        serviceTime--;
        return serviceTime <= 0;
    }

    int getArrivalTime()
    {
        return arrivalTime;
    }
    void MinutePasses()
    {
        serviceTime--;
    }
};

#endif /* CUSTOMER_H_ */ 



Driver.cpp:

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
////////////////////////////////////////////////////////////////////
///Includes///
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <cstdlib>
#include "Queue.h"
#include "Customer.h"
#include "QueueNode.h"
#include "Teller.h"

using namespace std;


int main(int argc, char *argv[])
{
    srand(time(NULL)); //seeds the random time generator

    if(argc != 5)
    {
        cout << "You must enter at least 5 command line arguments " << endl;
        exit(1);
    }

    /******************Command Line Args-Variables***************************/
    double p = atof(argv[1]);
    int numTellers = atoi(argv[2]); //number of the tellers (M)
    int maxService = atoi(argv[3]);
    int maxClock = atoi(argv[4]); //simulation time (N)

    /******************Local Variables***************************/
    int numberOfCustomers = 0;
    int serv;
    int randProb;
    int totalWait;
    int AverageWaitTime;
    int wait;

    //Displays to user to double checks to make sure you entered in the arguments correctly
    cout << "------------------------------------------------------------" << endl;
    cout << "These are the arguments that you gave the program: " << endl;
    cout << endl;
    cout << "The p value is: " << p << endl;
    cout << "The number of tellers: " << numTellers << endl;
    cout << "The max service time is: " << maxService << endl;
    cout << "The max clock is: " << maxClock << endl;
    cout << endl;
    cout << "------------------------------------------------------------" << endl;
    cout << "\n";

    /******************Declaration of Queue & Vector***************************/
    Queue<Customer> line;
    vector<Teller> teller(numTellers);

    //loop to go through entire clock until the maxClock is reached
    for(int k = 1; k < maxClock; k++)
    {
        randProb = ((rand() % 100) + 1); //generates a random number seeded with system time
        if(randProb < p*100)
        {
            serv = ((rand() % maxService) + 1); //generates a random number seeded with system time
            Customer customer(k, serv); //passes in current time and service time (randomizeD)
            line.enqueue(customer); //pushes a customer onto the Queue.
            cout << "Customer arriving in queue at time: " << k << endl;
        }
        for(int i = 0; i < numTellers; i++) //goes through loop of tellers to determine their availability
        {
            teller[i].CustMinutePasses();
            if(teller[i].isFree() && (!line.isempty())) //checks to see if a teller is empty
            {
                cout << "Teller " << i << " is now free." << endl;
                Customer frontCustomer; //declares a customer called frontCustomer. This is the customer who is at the front of the Queue.
                line.dequeue(frontCustomer); //pulls off a customer from the Queue.
                numberOfCustomers++; //increases by 1 each time through to keep tracking of the # of Customers.
                totalWait = totalWait + frontCustomer.getArrivalTime();
                cout << "Customer going to teller " << i << " at time " << frontCustomer.getArrivalTime() << endl; //retrieves arrival time
                cout << "This customer had to wait in line for " << std::labs(totalWait) << " minutes." << endl; //labs() is a function used to determine absolute value
                cout << "this customer will be finished at time: " << (serv + k) << "." << endl;
                teller[i].addCustomer(frontCustomer); //assigns the frontCustomer to THAT teller
                cout << "The size of the Queue is " << line.queuecount() << endl;
                line.remove(frontCustomer); //once cycled through, removes the customer from the Queue.
            }
        }
        cout << endl;
        cout << "Time is: "<< k << endl;
        if((k % 5) == 0)
        {
            cout << endl;
            cout << "Number of customers: " << numberOfCustomers << " " << "Total wait so far: " << std::labs(totalWait) << endl; //labs() is a function used to determine absolute value
        }
        AverageWaitTime = totalWait/numberOfCustomers; //finds the average wait time of the customers.
        cout << "Average wait: " << std::labs(AverageWaitTime) << endl; //labs() is a function used to determine absolute value
    }
}
Topic archived. No new replies allowed.