Bank Queue Simulation

Hi, I'm trying to learn more about classes/vectors/queues, so I've been playing around with code I find online. The code in question is from this site:
http://stdcxx.apache.org/doc/stdlibug/10-3.html

I tried to adjust the code so that multiple customers can come in per minute. I changed the process time in class Customer to constant 1. I also added another for loop in main() and marked where i made the change.I think whats happening is that all 10 customers that walk in go straight to the 1st teller because they are Customer(t) for the same t. how can I change this so that each customer goes to a different teller? Thanks in advance!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687`` ``````#include #include #include #include using namespace std; class Customer { public: int arrivalTime; int processTime; Customer (int at = 0) : arrivalTime (at), processTime (1) {} // are we done with our transaction? bool done () { return --processTime < 0; } // order by arrival time bool operator< (const Customer& c) const { return arrivalTime < c.arrivalTime; } }; class Teller { public: Teller (): free (true) { } bool isFree () { // are we free to service new customer? if (free) return true; if (customer.done()) free = true; return free; } // start serving new customer void addCustomer (const Customer &c) { customer = c; free = false; } private: bool free; Customer customer; }; int main () { const int numberOfTellers = 2; const int numberOfMinutes = 10; const int custPerMin = 10; double totalWait = 0; int numberOfCustomers = 0; vector teller (numberOfTellers); queue line; for (int t = 0; t < numberOfMinutes; t++) { for (int j = 0; j < custPerMin; j++) // 10 Customers per minute { line.push (Customer (t)); for (int i = 0; i < numberOfTellers; i++) { if (teller[i].isFree () && !line.empty ()) { Customer& frontCustomer = line.front (); numberOfCustomers++; totalWait += t - frontCustomer.arrivalTime; teller[i].addCustomer (frontCustomer); line.pop (); } } } } cout << "average wait: " << (totalWait / numberOfCustomers) << endl; } ``````
Topic archived. No new replies allowed.