Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- class point {
- public:
- double tab[3];
- point() {tab[0] = 0; tab[1] = 0; tab[2] = 0;}
- point(const double(&r)[3]) {tab[0] = r[0]; tab[1] = r[1]; tab[2] = r[2];}
- point(const double a1, const double a2, const double a3) {tab[0] = a1; tab[1] = a2; tab[2] = a3;}
- double distance(const point po) {
- 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]));
- }
- friend
- ostream& operator<< (ostream &wyjscie, point const& p) {
- wyjscie << p.tab[0] << " " << p.tab[1] << " " << p.tab[2];
- }
- point operator +(const point &p) {
- tab[0] += p.tab[0];
- tab[1] += p.tab[1];
- tab[2] += p.tab[2];
- }
- point operator -(const point &p) {
- tab[0] -= p.tab[0];
- tab[1] -= p.tab[1];
- tab[2] -= p.tab[2];
- }
- point &operator =(const point &p) {
- tab[0] = p.tab[0];
- tab[1] = p.tab[1];
- tab[2] = p.tab[2];
- }
- };
- int main() {
- double x[2][3] = {{1.0, 1.0, 1.0}, {1.0, 2.0, 3.0}};
- point p1(x[0]), p2(x[1]);
- const point p3(0.4, 0.2, 0.1);
- cout << p1.tab[1] << endl;
- cout << p1 << ", " << p2 << '\n';
- point p4;
- cout << p4 << endl;
- p4 = p1 + p2;
- cout << p4;
- }
Advertisement
Add Comment
Please, Sign In to add comment