Hellko

asfasfawfqweq

May 27th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.21 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class cube{
  5.         friend class a_cube;
  6. private:
  7.         double x,y,z,r;
  8. public:
  9.         cube(double X=1, double Y=1, double Z=1, double R=1){x=X;y=Y;z=Z;r=R;}
  10.         cube (const cube& A){x=A.x;y=A.y;z=A.z;r=A.r;}
  11.         void operator=(const cube& A){x=A.x; y=A.y; z=A.z; r=A.r;}
  12.         friend cube operator-(cube,cube);
  13.         friend cube operator*(cube, double);
  14.         friend cube tranform(double,double,double,double);
  15.         };
  16.  
  17. class a_cube {
  18. private:
  19. cube *x; //указатель на куб
  20. int n;
  21. public:
  22.         a_cube(int);
  23.         a_cube(const a_cube&);
  24.         ~a_cube();
  25.         void set(int,cube);//вставляем куб на позицию
  26.         void operator=(const a_cube&);//оператор присваивания
  27.         cube operator[](int) const;//возвращаем с позиции
  28.         friend a_cube operator-(const a_cube&, const a_cube&);
  29.         friend a_cube operator*(const a_cube&, double);//оператор умножения
  30.         friend a_cube operator*(double, const a_cube&);
  31.         void show();
  32.         void del(int);
  33. };
  34.  
  35. void a_cube::del(int N){
  36.         cube *tmp;
  37.         tmp=new cube[n-1];
  38.         for(int i=0;i<N;i++)
  39.             tmp[i]=x[i];
  40.         for(int i=N+1;i<n;i++)
  41.             tmp[i-1]=x[i];
  42.         delete[]x;
  43.         x=tmp;
  44.         n--;
  45. }
  46.  
  47. a_cube::a_cube(const a_cube& A){//копиконструктор
  48.                 n=A.n;
  49.                 x=new cube [n];
  50.                 for(int i=0;i<n;i++)
  51.                         x[i]=A.x[i];
  52. }
  53.  
  54. void a_cube::operator=(const a_cube& A){//оператор присваивания
  55.                 n=A.n;
  56.                 x=new cube[n];
  57.                 for(int i=0;i<n;i++)
  58.                         x[i]=A.x[i];
  59.         }
  60. cube tranform(double x, double y, double z, double r) {
  61.                 cube tmp;
  62.                 tmp.x=x;
  63.                 tmp.y=y;
  64.                 tmp.z=z;
  65.                 tmp.r=r;
  66.                 return tmp;
  67.         }
  68.  
  69. a_cube::a_cube(int N){//конструктор
  70.         n=N;
  71.         x=new cube[n];
  72. }
  73. a_cube::~a_cube(){//деструктор
  74.         delete[]x;
  75. }
  76. void a_cube::set(int N, cube tmp){
  77.         if(n<N) return;
  78.         x[N]=tmp;
  79. }
  80. cube a_cube::operator[](int N)const{
  81.         return x[N];
  82. }
  83. a_cube operator-(const a_cube& a, const a_cube& b){
  84.         a_cube c(a.n);
  85.         for(int i=0;i<c.n;i++)
  86.                 c.set(i,a[i]-b[i]);
  87.         return c;
  88. }
  89.  
  90. cube operator-(cube a, cube b){
  91.         return tranform(a.x-b.x,a.y-b.y,a.z-b.z,a.r-b.r);
  92. }
  93. cube operator*(cube a, double b){
  94.         return tranform(a.x*b,a.y*b,a.z*b,a.r*b);
  95. }
  96. a_cube operator*(const a_cube& a, double k){
  97.         a_cube c(a.n);
  98.         for(int i=0;i<c.n;i++)
  99.         c.set(i, a[i]*k);
  100.         return c;
  101. }
  102.  
  103. a_cube operator*(double k, const a_cube& a){
  104.         return a*k;
  105. }
  106.  
  107. void a_cube::show(){
  108.         cout<<endl<<"X:"; for(int i=0;i<n;i++) cout<<x[i].x<<"  ";
  109.         cout<<endl<<"Y:"; for(int i=0;i<n;i++) cout<<x[i].y<<"  ";
  110.         cout<<endl<<"Z:"; for(int i=0;i<n;i++) cout<<x[i].z<<"  ";
  111.         cout<<endl<<"R:"; for(int i=0;i<n;i++) cout<<x[i].r<<"  ";
  112.         cout<<endl;
  113. }
  114. int main() {
  115. }
Advertisement
Add Comment
Please, Sign In to add comment