Guest User

Untitled

a guest
Oct 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #pragma hdrstop
  2. #pragma argsused
  3.  
  4. #include <tchar.h>
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <iostream>
  8.  
  9. using namespace std;
  10. //----------------------------------------------------------------------------
  11. class Offset
  12. {
  13.     public:
  14.         Offset()
  15.         {
  16.             offsetX = 0;
  17.             offsetY = 0;
  18.         }
  19.  
  20.         Offset( int x, int y )
  21.         {
  22.             offsetX = x;
  23.             offsetY = x;
  24.         }
  25.  
  26.     private:
  27.         int offsetX;
  28.         int offsetY;
  29.  
  30. };
  31. //----------------------------------------------------------------------------
  32. class Point2D
  33. {
  34.     public:
  35.  
  36.         Point2D()
  37.         {
  38.             pointX = 0;
  39.             pointY = 0;
  40.         }
  41.  
  42.         Point2D( int x , int y )
  43.         {
  44.             pointX = x;
  45.             pointY = y;
  46.         }
  47.  
  48.  
  49.  
  50.         void Print();
  51.         void MoveRelative( Offset x);
  52.         void MoveAbsolute( int x, int y );
  53.         void Contains( int topX, int bottomX, int topY, int bottomY );
  54.  
  55.  
  56.     private:
  57.         int pointX;
  58.         int pointY;
  59.  
  60. };
  61. //-----------------------------------------------------------------------------
  62.  
  63. int main()
  64. {
  65.     Offset x(2,3);
  66.     Point2D p(1,3);
  67.     p.Print();
  68.  
  69.     p.MoveRelative(x);
  70.  
  71.     p.Contains(1,1,5,5);
  72.  
  73.  
  74.     return 0;
  75. }
  76. //-----------------------------------------------------------------------------
  77. void Point2D::Print()
  78. {
  79.     cout << "The value of x is " << pointX << endl
  80.          << "The value of y is " << pointY << endl << endl;
  81.     getch();
  82. }
  83. //-----------------------------------------------------------------------------
  84. void Point2D::MoveRelative( Offset x)
  85. {
  86.     pointX += Offset.offsetX;
  87.     pointY += Offset.offsetY;
  88.  
  89.  
  90. }
  91. //-----------------------------------------------------------------------------
  92. void Point2D::MoveAbsolute( int x, int y )
  93. {
  94.     pointX = x;
  95.     pointY = y;
  96. }
  97. //-----------------------------------------------------------------------------
  98. void Point2D::Contains(int topX, int topY, int bottomX, int bottomY)
  99. {
  100.     if( ( topX >= pointX ) && ( topY >= pointY ) )
  101.     {
  102.         if ( ( bottomX <= pointX ) && ( bottomY <= pointY ) )
  103.         {
  104.             cout << "The point is inside the rectangle";
  105.         }
  106.     }
  107.     else
  108.     cout << "The point isn't inside the rectangle";
  109.  
  110.     getch();
  111. }
  112. //-----------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment