home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C09 / Rectangle.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  639 b   |  25 lines

  1. //: C09:Rectangle.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Accessors & mutators
  7.  
  8. class Rectangle {
  9.   int _width, _height;
  10. public:
  11.   Rectangle(int w = 0, int h = 0)
  12.     : _width(w), _height(h) {}
  13.   int width() const { return _width; } // Read
  14.   void width(int w) { _width = w; } // Set
  15.   int height() const { return _height; } // Read
  16.   void height(int h) { _height = h; } // Set
  17. };
  18.  
  19. int main() {
  20.   Rectangle r(19, 47);
  21.   // Change width & height:
  22.   r.height(2 * r.width());
  23.   r.width(2 * r.height());
  24. } ///:~
  25.