Code for Assignment 3, problems 3, 4, 5