fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point
  5. {
  6. public:
  7. Point(int x, int y): itsX(x), itsY(y) {}
  8.  
  9. int GetX() const { return itsX; }
  10. int GetY() const { return itsY; }
  11.  
  12. private:
  13. int itsX;
  14. int itsY;
  15. };
  16.  
  17. class MyRectangle
  18. {
  19. public:
  20. MyRectangle(int top, int left, int bottom, int right):
  21. itsUpperLeft(left, top),
  22. itsUpperRight(right, top),
  23. itsLowerRight(right, bottom),
  24. itsLowerLeft(left, bottom)
  25. {
  26. itsTop = top;
  27. itsLeft = left;
  28. itsBottom = bottom;
  29. itsRight = right;
  30. }
  31.  
  32. Point GetUpperLeft() const { return itsUpperLeft; }
  33. Point GetLowerleft() const { return itsLowerLeft; }
  34. Point GetUpperRight() const { return itsUpperRight; }
  35. Point GetLowerRight() const { return itsLowerRight; }
  36.  
  37. int GetArea() const;
  38.  
  39. private:
  40. Point itsUpperLeft;
  41. Point itsUpperRight;
  42. Point itsLowerLeft;
  43. Point itsLowerRight;
  44.  
  45. int itsTop;
  46. int itsLeft;
  47. int itsBottom;
  48. int itsRight;
  49. };
  50.  
  51. int MyRectangle::GetArea() const
  52. {
  53. int Width = itsRight - itsLeft;
  54. int Height = itsTop - itsBottom;
  55. return ( Width * Height );
  56. }
  57.  
  58. int main()
  59. {
  60. MyRectangle Rectangle( 100, 20, 50, 80 );
  61.  
  62. int Area = Rectangle.GetArea();
  63.  
  64. std::cout << "Area: " << Area << endl;
  65. std::cout << "Upper Left X Coordinate: ";
  66. std::cout << Rectangle.GetUpperLeft().GetX();
  67. }
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
Area: 3000
Upper Left X Coordinate: 20