Wednesday, October 15, 2008

How Many Legs? An Exercise in Classes and Objects

So I ran across a puzzle about cats on a bus. It's here. As you'll see if you follow the link there are seven girls, each with seven backpacks, each with seven large cats, etc. The question is how: many legs in total?

As I looked at it it struck me as an interesting problem for objects and properties. If I created an Access database with a Backpack class and a Cat class and so on I could just instantiate a Bus object and then interrogate its Legs property.

Well it worked. It's not elegant, and there aren't a lot of comments, but it's an interesting exercise on classes and objects. You can download the database here.

2 comments:

Anonymous said...

answer = 10990 legs

Stephen said...

TC_Admin: yep!