Bank Teller Simulation, test of queue data type (doesn't compile)

lactoseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SnurreCommented:
Coul'd you give some more info...

What is the Compile Error mess if you even get one??

Some Code would be good too...
0
lactoseAuthor Commented:
I posted the question, but for some reason it didn't appear, so here goes again:
---------------------------

Hi, I'm trying to compile Tim Budd's bank teller simulation ( http://ftp.ccs.neu.edu/pub/people/york/budd/bank.cpp ) on a UNIX system with g++ and it keeps giving me following errors:


bank.cpp:42: ANSI C++ forbids declaration `operator <' with no type
bank.cpp:45: ANSI C++ forbids declaration `operator ==' with no type
bank.cpp: In function `int main(...)':
bank.cpp:90: no matching function for call to `queue<list<Customer,allocator<Customer> >,deque<list<Customer,allocator<Customer> >,allocator<list<Customer,allocator<Customer> > >,0> >::push (Customer &)'
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/../../../../include/g++-3/stl_queue.h:63: candidates are: void queue<list<Customer,allocator<Customer> >,deque<list<Customer,allocator<Customer> >,allocator<list<Customer,allocator<Customer> > >,0> >::push(const list<Customer,allocator<Customer> > &)
bank.cpp:94: conversion from `list<Customer,allocator<Customer> >' to non-scalar type `Customer' requested



and here's the source code (repeated):
//------------------------------------

//
//     bank teller simulation routine
//


# 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;
}
0
SnurreCommented:
OK... Try the Following...

The errors:
bank.cpp:42: ANSI C++ forbids declaration `operator <' with no type
bank.cpp:45: ANSI C++ forbids declaration `operator ==' with no type
bank.cpp: In function `int main(...)':
bank.cpp:90: no matching function for call to `queue<list<Customer,allocator<Customer> >,deque<list<Customer,allocator<Customer> >,allocator<list<Customer,allocator<Customer> > >,0> >::push (Customer &)'
/usr/local/lib/gcc-lib/sparc-sun-solaris2.8/2.95.3/../../../../include/g++-3/stl_queue.h:63: candidates are: void queue<list<Customer,allocator<Customer> >,deque<list<Customer,allocator<Customer> >,allocator<list<Customer,allocator<Customer> > >,0> >::push(const list<Customer,allocator<Customer> > &)
bank.cpp:94: conversion from `list<Customer,allocator<Customer> >' to non-scalar type `Customer' requested


They are cause by the following:
The Operators... If you have some operator overloding, Check them so that you are sure that they are declared correctly...

And the other errors that conserns some vectors... Check the Line that has the followning
`queue<list<Customer,allocator<Customer> >,deque<list<Customer,allocator<Customer> >,allocator<list<Customer,allocator<Customer> > >,0> >::push (Customer &)'
for '<' and '>' It looks like you have lost them on some spots...
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

efnCommented:
You have to declare a return type for the < and == operators in Customer.  bool would be an appropriate type.  For example:

bool operator < (Customer & c)     // order by arrival time

You're getting the other errors because line is a queue of lists of Customers and newCustomer is a Customer, not a list of Customers.  So the compiler complains when you try to push newCustomer into line, because newCustomer is not the type of object that line contains.

Similarly, it complains when you try to assign the list of customers returned by line.front() to frontCustomer, because it doesn't know how to store a list as a Customer.

It looks like the code wants to treat line as a queue of Customers, so it would make sense to declare it that way.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lactoseAuthor Commented:
yeah, I've figured that much myself by now ;)
0
lactoseAuthor Commented:
I was just looking for a quick fix from you guys :)
I can't understand how some of these sources get posted by authors claiming they actually work yet the code explicitly tries to push object of class Customer into a queue OF LISTS of Customer class. weird.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.