Code solution for Assignment4