kolioi

52. Area and Perimeter of Rectangle C++

Jan 5th, 2019
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Rectangle
  6. {
  7. public:
  8.     Rectangle(double w, double h) : width(w), height(h) {}
  9.  
  10.     double perimeter() const
  11.     {
  12.         return 2 * (width + height);
  13.     }
  14.  
  15.     double area() const
  16.     {
  17.         return width * height;
  18.     }
  19.  
  20. private:
  21.     double width, height;
  22. };
  23.  
  24. int main()
  25. {
  26.     double w, h;
  27.     cin >> w >> h;
  28.  
  29.     Rectangle rect(w, h);
  30.  
  31.     cout << rect.area() << endl << rect.perimeter() << endl;
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment