implemented the homework #3 assigned by instructor