Code for the second assignment.