Chapter 11 Exercise Set 0: Chapter ReviewΒΆ
As you did back in the A more efficient increment exercise in chapter 8, rewrite the
incrementfunction from the Another example section more effeciently without iteration.In the Initialize or construct? section, you defined a constructor for
Times that had two integers and a double as parameters. The combination of function name and the ordered types of its parameters is known as the function signature. The C++ compiler uses this signature to determine which version of an overloaded function to call.Try creating a new
Timewith this constructor by passing it threeintarguments:Time current_time(9, 14, 3);
What happens? Now define a new constructor with the following
Time(int h, int m, int s);
Print out a different message inside each constructor so you can see which one was called. Create
current_timeagain and run your program. What happens?Rewrite the
distancefunction from Structues as parameters as a member function of thePointstruct.Overload the
-operator for points, to supportPoint p1(7, 4); Point p2(3, 1); Point p3 = p1 - p2; cout << p3 << end;
which should print
(4, 3).Add two constructors to the
Rectanglestructs introduced in the Structures chapter with the following protoypes:Rectangle::Rectangle(Point upper_left, double width, double length); Rectangle::Rectangle(Point upper_left, Point lower_right);
Add a member function
areatoRectanglereturns the area of the rectangle.