Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Shape
- {
- public:
- Shape(double w, double h) : width(w), height(h) {}
- double width;
- double height;
- virtual void hello() {cout << "hello from shape!";}
- };
- class SecondShape
- {
- public:
- SecondShape(double w, double h) : width(w), height(h) {}
- double width;
- double height;
- bool other;
- virtual void hello() {cout << "hello from shape!";}
- };
- class Rectangle : public Shape, public SecondShape
- {
- public:
- Rectangle(double w, double h) : Shape(w, h) {}
- double area() {return width * height;}
- double get_width() {return width;}
- double get_height() {return height;}
- };
- class Triangle : public Shape
- {
- public:
- Triangle(double w, double h) : Shape(w, h) {}
- double area() {return width * height / 2;}
- double get_width() {return width;}
- double get_height() {return height;}
- };
- class VerySpecialTriangle : public Triangle
- {
- public:
- VerySpecialTriangle(double w, double h) : Triangle(w, h), special(true) {}
- bool special;
- void display();
- };
- void VerySpecialTriangle::display()
- {
- cout << "Obiekt vst:\n";
- cout << "\twysokosc: " << height << endl;
- cout << "\tszerokosc: " << width << endl;
- cout << "\tpole: " << area() << endl;
- }
- int main()
- {
- Triangle tri(4, 3);
- Rectangle recti(10, 6);
- cout << "Obiekt recti:\n";
- cout << "\twysokosc: " << recti.get_height() << endl;
- cout << "\tszerokosc: " << recti.get_width() << endl;
- cout << "\tpole: " << recti.area() << endl;
- /*cout << "Obiekt tri:\n";
- cout << "\twysokosc: " << tri.get_height() << endl;
- cout << "\tszerokosc: " << tri.get_width() << endl;
- cout << "\tpole: " << tri.area() << endl;*/
- VerySpecialTriangle vst(10, 5);
- cout << "Obiekt vst:\n";
- cout << "\twysokosc: " << vst.get_height() << endl;
- cout << "\tszerokosc: " << vst.get_width() << endl;
- cout << "\tpole: " << vst.area() << endl;
- vst.display();
- Shape* sptr = &vst;
- sptr->hello();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment