Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma hdrstop
- #pragma argsused
- #include <tchar.h>
- #include <stdio.h>
- #include <conio.h>
- #include <iostream>
- using namespace std;
- //----------------------------------------------------------------------------
- class Offset
- {
- public:
- Offset()
- {
- offsetX = 0;
- offsetY = 0;
- }
- Offset( int x, int y )
- {
- offsetX = x;
- offsetY = x;
- }
- private:
- int offsetX;
- int offsetY;
- };
- //----------------------------------------------------------------------------
- class Point2D
- {
- public:
- Point2D()
- {
- pointX = 0;
- pointY = 0;
- }
- Point2D( int x , int y )
- {
- pointX = x;
- pointY = y;
- }
- void Print();
- void MoveRelative( Offset x);
- void MoveAbsolute( int x, int y );
- void Contains( int topX, int bottomX, int topY, int bottomY );
- private:
- int pointX;
- int pointY;
- };
- //-----------------------------------------------------------------------------
- int main()
- {
- Offset x(2,3);
- Point2D p(1,3);
- p.Print();
- p.MoveRelative(x);
- p.Contains(1,1,5,5);
- return 0;
- }
- //-----------------------------------------------------------------------------
- void Point2D::Print()
- {
- cout << "The value of x is " << pointX << endl
- << "The value of y is " << pointY << endl << endl;
- getch();
- }
- //-----------------------------------------------------------------------------
- void Point2D::MoveRelative( Offset x)
- {
- pointX += Offset.offsetX;
- pointY += Offset.offsetY;
- }
- //-----------------------------------------------------------------------------
- void Point2D::MoveAbsolute( int x, int y )
- {
- pointX = x;
- pointY = y;
- }
- //-----------------------------------------------------------------------------
- void Point2D::Contains(int topX, int topY, int bottomX, int bottomY)
- {
- if( ( topX >= pointX ) && ( topY >= pointY ) )
- {
- if ( ( bottomX <= pointX ) && ( bottomY <= pointY ) )
- {
- cout << "The point is inside the rectangle";
- }
- }
- else
- cout << "The point isn't inside the rectangle";
- getch();
- }
- //-----------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment