Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Cparallepiped
- {
- protected:
- float height;
- float length;
- float width;
- public:
- Cparallepiped()
- {
- this->height = 0;
- this->length = 0;
- this->width = 0;
- }
- Cparallepiped(float newHeight, float newLength, float newWidth)
- {
- this->height = newHeight;
- this->length = newLength;
- this->width = newWidth;
- }
- void print()
- {
- cout<<"Данные о металлическом парралепипеде:"<<endl;
- cout<<"Высота: "<<this->height<<" Длина: "<<this->length<<" Ширина: "<<this->width<<endl;
- }
- ~Cparallepiped(){};
- };
- class Cmetal_parallepiped:Cparallepiped
- {
- private:
- float density;
- public:
- Cmetal_parallepiped()
- {
- this->density = 0;
- }
- Cmetal_parallepiped(float newHeight, float newLength,
- float newWidth, float newDensity):Cparallepiped(
- newHeight, newLength, newWidth)
- {
- this->density = newDensity;
- }
- float weight()
- {
- return this->density*this->height*this->length*this->width;
- }
- void print()
- {
- Cparallepiped::print();
- cout<<"Удельный вес: "<<this->density<<endl;
- }
- ~Cmetal_parallepiped(){};
- };
- int main()
- {
- setlocale(0,"Russian");
- Cmetal_parallepiped * metal_parallepiped = new Cmetal_parallepiped(2,3,4,5);
- metal_parallepiped->print();
- cout<<"Вес параллепипеда: "<<metal_parallepiped->weight();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement