Advertisement
skb50bd

Area of A Rectangle Using Two Co-Ordinates. [Class-Objects]

May 25th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Point{
  6.    
  7. private:
  8.     int x, y;
  9.    
  10. public:
  11.     void readData ()
  12.     {
  13.         cin >> x;
  14.         cin >> y;
  15.     }
  16.    
  17.     int getx () { return x;}
  18.     int gety () { return y;}
  19. };
  20.  
  21. class Rectangle{
  22.    
  23. private:
  24.     class Point tr, bl;
  25.    
  26. public:
  27.     void setPoint ()
  28.     {
  29.         cout << "Top-Right Point: ";
  30.         tr.readData();
  31.         cout << "Bottom-Left Point: ";
  32.         bl.readData();
  33.     }
  34.  
  35.     int getx1() { return tr.getx();}
  36.     int getx2() { return bl.getx();}
  37.     int gety1() { return tr.gety();}
  38.     int gety2() { return bl.gety();}
  39. };
  40.  
  41. void area (Rectangle X);
  42.  
  43. main()
  44. {
  45.     class Rectangle R;
  46.  
  47.     cout << "This Program Can Calculate the Area of A Rectangle Using 2 (Cartesian) Co-Ordinates" << endl;
  48.  
  49.     cout << "Enter Points" << endl;
  50.     R.setPoint();
  51.  
  52.     area (R);
  53.  
  54.     return 0;
  55. }
  56.  
  57. void area (Rectangle X)
  58. {
  59.     int A, x1, x2, y1, y2;
  60.  
  61.     x1 = X.getx1();
  62.     x2 = X.getx2();
  63.     y1 = X.gety1();
  64.     y2 = X.gety2();
  65.  
  66.     A = (x1 - x2) * (y1 - y2);
  67.  
  68.     cout << "Area is: " << A;
  69.     return;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement