Chapter 8 Exercise Set 0: Chapter Review¶
Write function named
lower_rightthat takes aRectangleas an argument and returns aPointwith the location of the lower right hand corner.Write a function named
find_areathat takes aRectangleas an argument and returns the area of the rectangle.Use the
sizeofoperator 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
constparameter, and then modify it in the function body. Try compiling it and note what happens on your system.
A more efficient increment¶
Rewrite the
incrementfunction from the Modifiers section without iteration using the approach introduced in the Incremental development versus planning section.