Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Point{
- private:
- int x, y;
- public:
- Point():x(0), y(0){}
- ~Point(){}
- int getX() {return x;}
- int getY() {return y;}
- void setData(int a, int b) {x = a, y = b;}
- void readPoint(){
- cin >> x >> y;
- }
- void showPoint(){
- cout << "x = " << x << " " << "y = " << y << endl;
- }
- };
- Point addPoint(Point A, Point B){
- Point temp;
- temp.setData(A.getX() + B.getX(), A.getY() + B.getY());
- return temp;
- }
- Point subPoint(Point A, Point B){
- Point temp;
- temp.setData(A.getX() - B.getX(), A.getY() - B.getY());
- return temp;
- }
- int main(){
- Point P[4];
- for(int i = 0; i < 2; i++)
- P[i].readPoint();
- P[2] = addPoint(P[0], P[1]);
- P[3] = subPoint(P[0], P[1]);
- for(int i = 2; i < 4; i++)
- P[i].showPoint();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement