This looks at lot like homework being posted to the forum again.
Yep, yet another code beggar (*); I hope we never have to meet one of those in
the industry; there's enough crappy code around already.
kind regards,
Jos
(*) actually I call them something else but this is a family forum so I won't repeat
that here ;-)