Advertisement
skb50bd

Mid I-2: Points

Jun 24th, 2015
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point{
  5. private:
  6.     int x, y;
  7. public:
  8.     Point():x(0), y(0){}
  9.     ~Point(){}
  10.  
  11.     int getX() {return x;}
  12.     int getY() {return y;}
  13.     void setData(int a, int b) {x = a, y = b;}
  14.  
  15.     void readPoint(){
  16.         cin >> x >> y;
  17.     }
  18.  
  19.     void showPoint(){
  20.         cout << "x = " << x << "  " << "y = " << y << endl;
  21.     }
  22. };
  23.  
  24. Point addPoint(Point A, Point B){
  25.     Point temp;
  26.     temp.setData(A.getX() + B.getX(), A.getY() + B.getY());
  27.     return temp;
  28. }
  29.  
  30. Point subPoint(Point A, Point B){
  31.     Point temp;
  32.     temp.setData(A.getX() - B.getX(), A.getY() - B.getY());
  33.     return temp;
  34. }
  35.  
  36. int main(){
  37.     Point P[4];
  38.  
  39.     for(int i = 0; i < 2; i++)
  40.         P[i].readPoint();
  41.  
  42.     P[2] = addPoint(P[0], P[1]);
  43.     P[3] = subPoint(P[0], P[1]);
  44.  
  45.     for(int i = 2; i < 4; i++)
  46.         P[i].showPoint();
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement