Facebook
From Capacious Frog, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 58
  1. #include <iostream>
  2. using namespace std;
  3. class Rectangle
  4. {
  5. public:
  6.         Rectangle(float w, float h) {
  7.                 width = w;
  8.                 height = h;
  9.         }
  10.         ~Rectangle() {}
  11.         float GetArea() {
  12.                 return width * height;
  13.         }
  14.         void SetWH(float w, float h) {
  15.                 SetWidth( w);
  16.                 SetHeight(h);
  17.         }
  18.         void SetWidth(float w) {
  19.                 width = w;
  20.        
  21.         }
  22.         void SetHeight(float h) {
  23.        
  24.                 height = h;
  25.         }
  26.         float GetCircumference() {
  27.                 return 2*width +2* height;
  28.  
  29.         }
  30.        
  31.         Rectangle(Rectangle &r):Rectangle(r.width,r.height) {
  32.                
  33.         }
  34. private:
  35.         float width;
  36.         float height;
  37. };
  38.  
  39.  
  40. int main()
  41. {
  42.         Rectangle rect(4,5);
  43.         cout << "rect's Area: " << rect.GetArea() << endl;
  44.         cout << "rect'sCircumference: " << rect.GetCircumference() << endl<<endl;
  45.         Rectangle rect2(rect);
  46.         cout << "rect2's Area: " << rect2.GetArea() << endl;
  47.         cout << "rect2's Circumference: " << rect2.GetCircumference() << endl << endl;
  48.         rect2.SetWidth(10);
  49.         rect2.SetHeight(20);
  50.         cout << "rect's Area: " << rect.GetArea() << endl;
  51.         cout << "rect'sCircumference: " << rect.GetCircumference() << endl << endl;
  52.         cout << "rect2's Area: " << rect2.GetArea() << endl;
  53.         cout << "rect2's Circumference: " << rect2.GetCircumference() << endl << endl;
  54. }
  55.