Code from CS 2150 (UVa), C++