So OK, you've apparently been given a homework assignment, and are now providing us with the text of that assignment. Apparently, you're hoping that someone here will just hand you a solution.
Good luck with that.
Perhaps you might benefit from reading
this.
Look, at some point you need to demonstrate that you're putting some effort of your own into this process. It's not enough to simply re-state the question. Several posters have been offering help, but you haven't shown any work of your own yet. We're happy to help, but we don't want to do all of your work for you. So talk to us. Tell us what you think about the suggestions that have been given so far. Tell us what you understand, or what confuses you. Try to be specific. Show us that you're really trying, and not just waiting for someone to offer up some code that does what you want.
Good luck.
[ October 27, 2008: Message edited by: Mike Simmons ]