modified hw2A.cpp