Chapter 8 Exercise Set 0: Chapter Review

  1. Write function named lower_right that takes a Rectangle as an argument and returns a Point with the location of the lower right hand corner.

  2. Write a function named find_area that takes a Rectangle as an argument and returns the area of the rectangle.

  3. Use the sizeof operator you first met back in the Values section in chapter 2 to determine the size of a Rectangle.

  4. 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.

  5. 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.

A more efficient increment

  1. Rewrite the increment function from the Modifiers section without iteration using the approach introduced in the Incremental development versus planning section.