Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-15
6
Medium Priority
?
2,425 Views
Last Modified: 2012-05-04
0
Comment
Question by:lactose
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

577 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