Table Of Contents
Previous Section Next Section

Program 52: The Case of the Disappearing Rectangle

What's the area of our sample?

  1 /************************************************
  2  * Demonstration of the rectangle class.        *
  3  ************************************************/
  4 #include <iostream>
  5
  6 /************************************************
  7  * rectangle -- hold constant information about *
  8  *              a rectangle.                    *
  9  *                                              *
 10  * Members:                                     *
 11  *      area -- Area of the rectangle.          *
 12  *      width -- width of the rectangle.        *
 13  *      height - length of the rectangle.       *
 14  ************************************************/
 15 class rectangle
 16 {
 17     public:
 18         const int area;   // Rectangle's Area
 19         const int width;  // Rectangle's Width
 20         const int height; // Rectangle's Height
 21
 22     public:
 23         // Create a rectangle and assign the
 24         // initial values
 25         rectangle(
 26             const int i_width,  // Initial width
 27             const int i_height  // Initial height
 28         ) : width(i_width),
 29             height(i_height),
 30             area(width*height)
 31         {}
 32         // Destructor defaults
 33         // Copy constructor defaults
 34         // Assignment operator defaults
 35 };
 36
 37 int main()
 38 {
 39     // Rectangle to play with
 40     rectangle sample(10, 5);
 41
 42     std::cout << "Area of sample is " <<
 43         sample.area << std::endl;
 44     return (0);
 45 }

(Next Hint 210. Answer 93.)

Table Of Contents
Previous Section Next Section