Thread: queue and objects

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    1

    queue and objects

    First this is a homework assignment, so I don't want the answer just a point in the right direction.
    The problem is a bank simulation. I have 3 classes: Tellers, Customers, and InLine. The line is the queue.
    The customers class has an array of objects defined in main like this:
    Customers customer[300];

    My question is this, is it possible to insert an object customer into the queue? I have tried many ways but nothing seems to work.

    example
    line.enqueue(x); //i would like for x to be a customer object.
    Does this make sense to anyone, if so please point me in the right direction.
    Thank you,
    Diana

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Did you mean that the InLine class has an array of Customers (it wouldn't make sense for the Customers class to have an array of Customers)?

    Yes it would be possible. You'd have to keep track of the start and end of the line, so you know which objects in the array are in line and which are dummies that aren't valid.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I would rename your classes "Teller" and "Customer" because an object of those classes represents one teller or one customer. Then name your array "customers".
    Code:
    Customer customers[300];
    
    //assign a customer to the array:
    Customer customer3;
    customers[2] = customer3;
    However, as Daved pointed out, your Inline class should contain the array. In addition, the Inline class will contain the methods to add customers to the array and keep track of how many customers there are in the array.

    You also need to be aware of what happens when you pass an object by value to a function vs. what happens when you pass an object by reference to a function. You always want to pass objects by reference to avoid copying.
    Last edited by 7stud; 11-11-2005 at 07:36 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Queue Problem
    By SMurf in forum C Programming
    Replies: 3
    Last Post: 04-26-2008, 11:30 AM
  3. stack and heap objects
    By John_L in forum C++ Programming
    Replies: 4
    Last Post: 03-18-2008, 10:20 AM
  4. Implementing of queue using objects?
    By Argo_Jeude in forum C++ Programming
    Replies: 5
    Last Post: 08-07-2007, 11:55 AM
  5. Queue and Objects
    By xddxogm3 in forum C++ Programming
    Replies: 5
    Last Post: 10-26-2003, 09:41 PM