Hellko

Untitled

Apr 3rd, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. class vector {
  4. protected:
  5. double x,y,z; //направляющий вектор
  6. public:
  7. vector() {x=1;y=1;z=1;} //конструктор по умолчанию
  8. vector(double x1, double y1, double z1) {x=x1; y=y1; z=z1;}
  9. void show() {printf("Vector {%lf,%lf,%lf}\n",x,y,z);}
  10. };
  11.  
  12. class sphere {
  13. protected:
  14. double x0,y0,z0;
  15. double r;
  16. public:
  17. sphere() {x0=0; y0=0; z0=0; r=1;}
  18. sphere(double x1, double y1, double z1, double r1) {x0=x1; y0=y1; z0=z1; r=r1;}
  19. void show() {printf("Sphere: {%lf,%lf,%lf} radius=%lf\n",x0,y0,z0,r);}
  20. };
  21.  
  22. class line: public vector, public sphere {
  23. private:
  24. public:
  25. line(): vector(), sphere() {}
  26. //Первые 3 координаты - напр вектор. Вторые 3 координаты - проходит через точку.
  27. line(double Nx, double Ny, double Nz, double x1, double y1, double z1): vector(Nx,Ny,Nz), sphere(x1,y1,z1,0){}
  28. void show() {vector::show(); printf("point: {%lf,%lf,%lf}",x0,y0,z0); printf("\n\n");}
  29. friend line operator+(line x, line y){return line(x.x+y.x, x.y+y.y, x.z+y.z, x.x0+y.x0, x.y0+y.y0, x.z0+y.z0);}
  30. };
  31.  
  32. int main() {
  33. line x, y(2,5,6,1,0,0); //x - {1,1,1,0,0,0}
  34. x.show();
  35. y.show();
  36. line z;
  37. z=x+y;
  38. z.show(); //сумма
  39. }
Advertisement
Add Comment
Please, Sign In to add comment