Advertisement
Proff_Ust

metal_parallepiped

Nov 29th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Cparallepiped
  4. {
  5. protected:
  6.     float height;
  7.     float length;
  8.     float width;
  9. public:
  10.     Cparallepiped()
  11.     {
  12.         this->height = 0;
  13.         this->length = 0;
  14.         this->width = 0;
  15.     }
  16.  
  17.     Cparallepiped(float newHeight, float newLength, float newWidth)
  18.     {
  19.         this->height = newHeight;
  20.         this->length = newLength;
  21.         this->width = newWidth;
  22.     }
  23.  
  24.     void print()
  25.     {
  26.         cout<<"Данные о металлическом парралепипеде:"<<endl;
  27.         cout<<"Высота: "<<this->height<<" Длина: "<<this->length<<" Ширина: "<<this->width<<endl;
  28.     }
  29.  
  30.  
  31.     ~Cparallepiped(){};
  32. };
  33.  
  34. class Cmetal_parallepiped:Cparallepiped
  35. {
  36. private:
  37.     float density;
  38. public:
  39.     Cmetal_parallepiped()
  40.     {
  41.         this->density = 0;
  42.     }
  43.     Cmetal_parallepiped(float newHeight, float newLength,
  44.                         float newWidth, float newDensity):Cparallepiped(
  45.                                                         newHeight, newLength, newWidth)
  46.     {
  47.         this->density = newDensity;
  48.     }
  49.  
  50.     float weight()
  51.     {
  52.         return this->density*this->height*this->length*this->width;
  53.     }
  54.  
  55.     void print()
  56.     {
  57.         Cparallepiped::print();
  58.         cout<<"Удельный вес: "<<this->density<<endl;
  59.     }
  60.  
  61.     ~Cmetal_parallepiped(){};
  62. };
  63.  
  64. int main()
  65. {
  66.     setlocale(0,"Russian");
  67.     Cmetal_parallepiped * metal_parallepiped = new Cmetal_parallepiped(2,3,4,5);
  68.     metal_parallepiped->print();
  69.     cout<<"Вес параллепипеда: "<<metal_parallepiped->weight();
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement