Area according to the coordinates of the upper left and lower right corners of the rectangle

From , 2 Years ago, written in C++, viewed 103 times.
URL https://pastebin.vip/view/4a3e0096
  1. #include <iostream>
  2. using namespace std;
  3. class Point
  4. {
  5. public:
  6.     int x,y;
  7.     Point (int a,int b)
  8.     {
  9.         x=a;
  10.         y=b;
  11.         cout<<"A point ("<<x<<", "<<y<<") is created!"<<endl;
  12.     }
  13.     Point (const Point &p)
  14.     {
  15.         x=p.x;
  16.         y=p.y;
  17.         cout<<"A point ("<<x<<", "<<y<<") is copied!"<<endl;
  18.     }
  19.     ~Point ()
  20.     {
  21.         cout<<"A point ("<<x<<", "<<y<<") is erased!"<<endl;
  22.     }
  23.     int getX()
  24.     {
  25.         return x;
  26.     }
  27.     int getY()
  28.     {
  29.         return y;
  30.     }
  31. };
  32. class Rectangle
  33. {
  34. private:
  35.     Point leftTop,rightBottom;
  36. public:
  37.     Rectangle(int a,int b,int c,int d):leftTop(a,b),rightBottom(c,d)
  38.     {
  39.         cout<<"A rectangle ("<<a<<", "<<b<<") to ("<<c<<", "<<d<<") is created!"<<endl;
  40.     }
  41.     ~Rectangle()
  42.     {
  43.         cout<<"A rectangle ("<<leftTop.getX()<<", "<<leftTop.getY()<<") to ("<<rightBottom.getX()<<", "<<rightBottom.getY()<<") is erased!"<<endl;
  44.     }
  45.     Point &getLeftTop()
  46.     {
  47.         return leftTop;
  48.     }
  49.     Point getRightBottome()
  50.     {
  51.         return rightBottom;
  52.     }
  53.     int getArea()
  54.     {
  55.         int a,b,c,d;
  56.         a=leftTop.x;
  57.         b=leftTop.y;
  58.         c=rightBottom.x;
  59.         d=rightBottom.y;
  60.         return (c-a)*(b-d);
  61.     }
  62. };
  63. int main()
  64. {
  65.     int cases;
  66.     int x1, y1, x2, y2;
  67.     cin>>cases;
  68.     for (int i = 0; i < cases; i++)
  69.     {
  70.         cin>>x1>>y1>>x2>>y2;
  71.         Rectangle rect(x1,y1,x2,y2);
  72.         cout<<"Area: "<<rect.getArea()<<endl;
  73.         cout<<"Left top is ("<<rect.getLeftTop().getX()<<", "<<rect.getLeftTop().getY()<<")"<<endl;
  74.         cout<<"Right bottom is ("<<rect.getRightBottome().getX()<<", "<<rect.getRightBottome().getY()<<")"<<endl;
  75.     }
  76.     return 0;
  77. }

Reply to "Area according to the coordinates of the upper left and lower right corners of the rectangle"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website