updated hw2A.cpp