Funtions definition for ProgrammingAssignment2.