PA4 solved in C++