Solved 1-5 in C++