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

  1. //: C09:Rectangle2.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 with "get" and "set"
  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 getWidth() const { return width; }
  14.   void setWidth(int w) { width = w; }
  15.   int getHeight() const { return height; }
  16.   void setHeight(int h) { height = h; }
  17. };
  18.  
  19. int main() {
  20.   Rectangle r(19, 47);
  21.   // Change width & height:
  22.   r.setHeight(2 * r.getWidth());
  23.   r.setWidth(2 * r.getHeight());
  24. } ///:~
  25.