?
Solved

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

Posted on 2003-03-15
6
Medium Priority
?
2,279 Views
Last Modified: 2012-05-04
0
Comment
Question by:lactose
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:Snurre
ID: 8143175
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
 

Author Comment

by:lactose
ID: 8143247
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
 
LVL 2

Expert Comment

by:Snurre
ID: 8143271
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 15

Accepted Solution

by:
efn earned 225 total points
ID: 8143724
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
 

Author Comment

by:lactose
ID: 8144521
yeah, I've figured that much myself by now ;)
0
 

Author Comment

by:lactose
ID: 8144550
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question