So far, students have been using classes such as
and class templates such as
vector. In this lab, they
see how classes are created and will "extend" C++'s data types by creating
Fractionfor doing arithmetic with fractions. The lab exercise uses points in the plane as an example and the students imitate what is done with them for fractions. By the end of the exercise, they will created a class for fractions with one arithmetic operation — multiplication — and will have overloaded the operator
The first project (#12.1) asks them to extend the class by overloading +, − /, ==, !=, <, >, <=, and >= and then construct a menu-driven fraction calculator. I assign this as their homework, occasionally allowing teams of two to work on it.