C++ Question

Status
Not open for further replies.
I have data structures project where I have to use Queues. It is a simulation of a supermarket checkout line. The queue represents the checkout line. The total number of lines is specified by the user, therefore, I declared an array of queues like:

LQueue *queueArr = new LQueue[numOfLines];

The queue is implemented with links (vice an array).

Each node of the Queue holds an object called Customer. Each customer has an attribute called "DepartureTime" which is an integer. And the customer class has a function called :

void SetDepartureTime(int time)

I don't know how to access the Customer Object's SetDepartureTime function once it is in the queue.

Thanks in advance.

Faisal
 
Thanks for the reply gumbo, but the Queue class is something totally different than a customer class. A customer supports setting their departure time. A queue is nothing more than a line which allows you to put people in it and take people out. Putting a functino in the queue which sets a customers departure will make my professor break out the red pen..
 
Okay, so I fiddled with my LQueue.h class and changed all access to public (another OOP no no, but I'll take the hit at this point). Everything seems to work okay now as I can access the customer object while in the cue through the following code:

queueArr.front->c.setSTime(timeOfNextDeparture);


Everything compiles just fine, but when I try to run the simulation with more than one checkout line, I get a memory access error. And here is where I hit the wall in my knowledge. I use Visual C++ 6.0 and I am clueless when it comes to using the debugger.

Here is a link to a page I have setup with my code.

http://www.faisalmahmoud.dns2go.com
 
Richard,

Nope, it's my lousy attempt to access that SetDepartureTime function from my customer object in the queue with this code

queueArr.front->c.setSTime(timeOfNextDeparture);


I commented out that one line and all memory errors disappeared.

But I'm back at square one, how do I set this attribute of an object inside a queue, which is part of an array of queues

God, I love this learning to be a software engineer thing.

lol,
Faisal
 

0

Ars Scholae Palatinae
609
Originally posted by fmahmoud:
Thanks for the srand() tip O.

And what do you mean by reformat my code?

Regards,
Faisal

I have serious problems reading non-indented code. So even though I was sure that you were trying to access something whilie front was still NULL, I imported the code into a text editor and indented everything so it looked more rational to me. Then I was able to trace execution more easily and see that there was a good chance that front had never been populated.
 
Status
Not open for further replies.