N
news.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
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