Code for HW2 of C++ course.