Re: grouping different kinds of food

From: news.hku.hk (billychu_at_hkusua.hku.hk)
Date: 04/25/04


Date: Sun, 25 Apr 2004 23:15:00 +0800

just to add some points,
food[6].showname(); //may return banana
food[7].showname(); //may return pear
and so on ..........
i mean, we don't know how many kinds of food are there and their total
amount. So it's not possible to inherit the class with "known" names.
Thanks for your attention.

"news.hku.hk" <billychu@hkusua.hku.hk> wrote in message
news:408bc292@newsgate.hku.hk...
> I would like to group different kinds of food.
> There are unknown number of kinds of food e.g. apple, orange, lemon,
melon,
> ........
> of course it's only a finite number but i don't know.
> also suppose apple will have different price for different objects.
>
> i have a class food such that:
>
> food[1].showname(); //return string apple
> food[2].showname(); // return string orange
> food[3].showname(); //return string lemon
> food[4].showname(); //return string apple
> food[5].showname(); //return string orange
> //some more up to food[100].showname();
>
> food[1].showprice(); //return integer value 13
> food[2].showprice(); // return integer value 21
> food[3].showprice(); //return integer value 19
> food[4].showprice(); //return integer value 20
> food[5].showprice(); //return integer value 11
> //some more up to food[100].showprice();
>
> what i want to do is to output the total price for different food like
this:
>
> apple: 23
> orange: 32
> lemon: 19
>
> could you tell me how to do this ??
>
> Thanks a lot
> Regards,
> Billy
>
>