High school programming graduation exam solution implemented in c++