The textbook frequently reiterates two fundamental themes: the value of self-testing and the necessity of elaborating on what we study.
"Unlike a test that evaluates knowledge, practice tests are done by students on their own, outside of class... Although most students prefer to take as few tests as possible, hundreds of experiments show that self-testing improves learning and retention… Short, frequent exams are most effective, especially when test takers receive feedback on the correct answers" (Dunlosky, Rawson, Marsh, Nathan, & Willingham, 2013, p. 49).
To elaborate means "to work out carefully or minutely; develop to perfection" (3), or "to add details to; expand" (4). "Research comparing excellent adult learners with less capable ones also confirmed that the most successful learners elaborate what they read and construct explanations for themselves" (Greeno, Collins, & Resnick, 1996, p. 19). Students elaborate on their study by mentally connecting general concepts to problems and identifying which techniques to use to solve a problem and why those techniques are appropriate.
This section revisits two previous programs and asks you to modify them. Each program consists of a single class and a simple driver. Your task is converting some member functions to overloaded operators and changing the corresponding function calls in the driver to use the operators. The following sub-sections outline the required conversions, and the complete worked examples follow.
Time
Time is a good class example because it's a relatively simple and familiar concept, having a modest number of attributes and operations. The most challenging operations, converting between an instance of Time and a single integer representing seconds, were completed in the previous examples. The following figure illustrates the next step in the evolution of the Time problem.
Chapter 9 Class Version
Overloaded Operator Version
Overloaded operators problem with the Time class. Convert the add and I/O functions in the previous Time Example to overloaded operators, and update the driver to use the operators instead of the functions.
The member variables may remain unchanged or, as the UML diagram suggests, you may initialize them to 0: Default constructor examples (b)
If you initialize the member variables, make an empty default constructor: Default constructor examples (d); otherwise, leave it unchanged
Version 2: Replace both operator+ functions with a single friend function supporting Time + Time, Time + int, and int + Time (A single friend overloaded operator+)
Compare your solution to the worked example in the next section.
fraction
The fraction class's arithmetic operations are more complex than Time's, but the Chapter 9 fraction example solves them completely.
Chapter 9 Class Version
Overloaded Operator Version
Overloaded operators problem with the fraction class. Convert the arithmetic (add, sub, mult, and div) and and I/O (print and read) functions in the original version to overloaded operators. The number of parameters in the arithmetic operators indicates they are friend functions. Modify the driver to use the operators.
The constructor is unchanged
Replace the arithmetic functions with overloaded operators
Replace the I/O functions with inserter and extractor operators
Carefully compare your solution to the worked example following the Time solution.