freelanceprogrammers.org Forum Index » C

algorithm problems


View user's profile Post To page top
wu_weidong Posted: Mon Jul 21, 2003 8:42 pm


Joined: 20 Jul 2003

Posts: 6
algorithm problems
Hi again,
I`ve actually posted about this problem before, but I`ve worked on it some more and changed the way I read in from the input files. One problem is that sometimes it`ll give me the "Access violation" problem and then highlight the { in the FFCtr constructor.
 
FFCtr::FFCtr(int op_status, int eff){ FFCtr::op_status = op_status;   FFCtr::eff = eff;}
 
Sometimes it`ll highlight the line return FFCus::cust_in_queue; in
int FFCus::r_custqueue(){ return FFCus::cust_in_queue;}
 
Sometimes it`ll run, but the output is wrong and the program hangs.
 

I`m supposed to simulate this fast food stall with six customer queues and 6 counters using classes.
Each queue is assumed to hold at most 6 customers (including the one st the counter).
 
From the input file, (in the first line) the first number in the pair indicates the operational status of a counter, where 1 signifies that the counter is open while 0 signifies that it is closed. The second number in the pair is the operator efficiency, which is the number of customers that the operator can check out in a minute. The second part of the input file comprises the repeated patterns of arrival time (in units of minutes) followed by the customers` names (each of which is a single letter) and the number of items the customer wishes to order.
 
What I`m trying to do here is obtain the output when given the input file. Both files are attached (ffs2.txt and output.txt).
My method is that I`ll read everything in the input file, and store the operator efficiency and status, names and items in class FFCtr and FFS respectively first. All the alphabets are stored as "name" and the integer behind each alphabet is stored as "item" for the corresponding "name". Both variables "name" and "item" are stored as 2D array, i.e. name[minute][i].
 
I would then try to arrange the queue by first finding the shortest queue (because all customers would join the shortest queue), then put the customers in each minute into the queues one by one (I run a minute by minute for loop in the main program when I call all the functions). I then display the output, and update the queues by updating the items already served for each customer. When all of a customer`s items are served, I take him out of the queue and shift everyone upwards by 1 position, so the first customer will always be at position 0 on the queue.
 
Can someone please tell me if my logic is correct and what I am doing wrong in my program? I really need this urgently.
 
To anyone who had the patience to finish this long message, thank you very much!!
 
Regards,
Rayne
Reply with quote
Send private message
View user's profile Post To page top
wu_weidong Posted: Mon Jul 21, 2003 9:07 pm


Joined: 20 Jul 2003

Posts: 6
algorithm problems
Sorry, but the output file I posted was wrong. The correct version is attached
Reply with quote
Send private message
View user's profile Post To page top
jateen_b Posted: Mon Jul 28, 2003 7:37 pm


Joined: 25 Jul 2003

Posts: 5
algorithm problems
hi Its me jateen
My question is

Where r the virtual tables stored? On
stack, heap or is it implementation dependant????

please send answer with reason.

________________________________________________________________________
Want to chat instantly with your online friends? Get the FREE Yahoo!
Messenger http://uk.messenger.yahoo.com/
Reply with quote
Send private message
View user's profile Post To page top
shantanu_k06 Posted: Mon Jul 28, 2003 8:38 pm


Joined: 19 Jul 2003

Posts: 29
algorithm problems
--- jateen bodkhe <jateen_b@...> wrote:
> hi Its me jateen
> My question is
>
> Where r the virtual tables stored? On
> stack, heap or is it implementation dependant????
>
> please send answer with reason.

Interesting question, and a brain-teaser too. :-) Am
trying to guess the answer.

A virtual table is implemented using a table of
pointer to virtual methods. Now, since virtual methods
being polymorphic in nature are resolved at runtime
thru late binding. That means, the lookup has to be at
runtime. But from where? Hmm....I think it should be
from the HEAP because unless that`s already there, no
object instantiation is possible to begin with.

Tell me, did I guess it right?

Regards,
Shantanu


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
ravi_jobs2002 Posted: Tue Jul 29, 2003 1:35 pm


Joined: 29 Jul 2003

Posts: 1
algorithm problems
Hi,
Virtual Tables will store in stack, since virtual
table is nothing but array of pointers.

Regards,
Ravi

--- jateen bodkhe <jateen_b@...> wrote:
> hi Its me jateen
> My question is
>
> Where r the virtual tables stored? On
> stack, heap or is it implementation dependant????
>
> please send answer with reason.
>
>
________________________________________________________________________
> Want to chat instantly with your online friends?
> Get the FREE Yahoo!
> Messenger http://uk.messenger.yahoo.com/
>
>


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
Reply with quote
Send private message
View user's profile Post To page top
sflam108 Posted: Tue Jul 29, 2003 8:50 pm


Joined: 25 Jul 2003

Posts: 48
algorithm problems
Although the loop up is done at runtime, the address and size of the
table is already known at compiled time.

The physical location is platform specific. Since the size of the table
is know at compiled time, the table can be store in the executable
image.

HTH
Shyan


> -----Original Message-----
> From: Shantanu Kumar [mailto:shantanu_k06@...]
> Sent: Monday, July 28, 2003 10:39
> To: Programmers-Town@yahoogroups.com
> Subject: Re: *(&Programmers-Town&)* Another small one( this time its
c++)
>
>
> A virtual table is implemented using a table of
> pointer to virtual methods. Now, since virtual methods
> being polymorphic in nature are resolved at runtime
> thru late binding. That means, the lookup has to be at
> runtime. But from where? Hmm....I think it should be
> from the HEAP because unless that`s already there, no
> object instantiation is possible to begin with.
>
> Tell me, did I guess it right?
>
> Regards,
> Shantanu
>
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help