Chapter 8 Exercise Set 0: Chapter ReviewΒΆ
Write function named
lower_right
that takes aRectangle
as an argument and returns aPoint
with the location of the lower right hand corner.Write a function named
find_area
that takes aRectangle
as an argument and returns the area of the rectangle.Use the
sizeof
operator you first met back in the Values section in chapter 2 to determine the size of aRectangle
.Compile and run the following program:
#include <iostream> using namespace std; struct A { char a; char b; }; struct B { char a; double b; }; struct C { A a; B b; }; int main() { A a = {'a', 'A'}; B b = {'B', 3.14}; C c = {{'c', 'C'}, {'d', 4.9}}; cout << "sizeof(a) is: " << sizeof(a) << endl; cout << "sizeof(b) is: " << sizeof(b) << endl; cout << "sizeof(c) is: " << sizeof(c) << endl; return 0; }
Can you explain the results? Do some web research to see if you can understand what you see. Try additional experiments to test your understanding.
Write a function with a
const
parameter, and then modify it in the function body. Try compiling it and note what happens on your system.Rewrite the
increment
function from the Modifiers section without iteration using the approach introduced in the Incremental development versus planning section.