add in answer to ex9.cpp