Implement the Exercise 2.42

Post both my header file and cpp file here for the solution of Exercise 2.42 of C++ Primer 5th Edition.