Advertisement
PomozMi

Jipp 1

Sep 22nd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1.  
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Point
  7. {
  8. private:
  9.     int x, y, z;
  10. public:
  11.     int podaj_x(){ return x; }
  12.     int podaj_y(){ return y; }
  13.     int podaj_z(){ return z; }
  14.     void viewPoint();
  15.     Point operator+(const Point&);
  16.     Point operator-(const Point&);
  17.     Point(){}
  18.     Point(int x, int y, int z);
  19.     ~Point();
  20. };
  21. Point::Point(int x, int y, int z) {
  22.     this->x = x;
  23.     this->y = y;
  24.     this->z = z;
  25. }
  26.  
  27. Point::~Point()
  28. {
  29. }
  30. void Point::viewPoint(){
  31.  
  32.     cout << "x: " << x << endl;
  33.     cout << "y: " << y << endl;
  34.     cout << "z: " << z << endl;
  35. }
  36. Point Point::operator + (const Point & prm){
  37.     Point wynik;
  38.     wynik.x = x + prm.x;
  39.     wynik.z = z + prm.z;
  40.     wynik.y = y + prm.y;
  41.     return wynik;
  42. }
  43. Point Point:: operator-(const Point & parm){
  44.     Point szmaty;
  45.     szmaty.x = x - parm.x;
  46.     szmaty.y = y - parm.y;
  47.     szmaty.z = z - parm.z;
  48.     return szmaty;
  49. }
  50. int main(){
  51.     Point a(2, 5, 6);
  52.     Point b(2, 6, 7);
  53.     Point result, rezult;
  54.  
  55.     a.viewPoint();
  56.     b.viewPoint();
  57.     cout << endl << "a+b=  " << endl;
  58.  
  59.     rezult = a + b;
  60.     cout << endl;
  61.     rezult.viewPoint();
  62.     cout << endl << "ODEJMOWNIAE\n a-b=";
  63.     result = a - b;
  64.     result.viewPoint();
  65. }
  66.  
  67. //#endif //!zad7.h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement