Guest User

Untitled

a guest
Nov 19th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5.  
  6. class point {
  7. public:
  8.     double tab[3];
  9.     point() {tab[0] = 0; tab[1] = 0; tab[2] = 0;}
  10.     point(const double(&r)[3]) {tab[0] = r[0]; tab[1] = r[1]; tab[2] = r[2];}
  11.     point(const double a1, const double a2, const double a3) {tab[0] = a1; tab[1] = a2; tab[2] = a3;}
  12.  
  13.     double distance(const point po) {
  14.         return sqrt((po.tab[0]-tab[0])*(po.tab[0]-tab[0])+(po.tab[1]-tab[1])*(po.tab[1]-tab[1])+(po.tab[2]-tab[2])*(po.tab[2]-tab[2]));
  15.     }
  16.     friend
  17.     ostream& operator<< (ostream &wyjscie, point const& p) {
  18.         wyjscie << p.tab[0] << " " << p.tab[1] << " " << p.tab[2];
  19.     }
  20.     point operator +(const point &p) {
  21.         tab[0] += p.tab[0];
  22.         tab[1] += p.tab[1];
  23.         tab[2] += p.tab[2];
  24.     }
  25.     point operator -(const point &p) {
  26.         tab[0] -= p.tab[0];
  27.         tab[1] -= p.tab[1];
  28.         tab[2] -= p.tab[2];
  29.     }
  30.     point &operator =(const point &p) {
  31.         tab[0] = p.tab[0];
  32.         tab[1] = p.tab[1];
  33.         tab[2] = p.tab[2];
  34.     }
  35. };
  36.  
  37. int main() {
  38.     double x[2][3] = {{1.0, 1.0, 1.0}, {1.0, 2.0, 3.0}};
  39.     point p1(x[0]), p2(x[1]);
  40.     const point p3(0.4, 0.2, 0.1);
  41.  
  42.     cout << p1.tab[1] << endl;
  43.  
  44.     cout << p1 << ", " << p2 << '\n';
  45.     point p4;
  46.     cout << p4 << endl;
  47.     p4 = p1 + p2;
  48.     cout << p4;
  49.  
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment