Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Shape {
- public:
- void set_values (int a,int b)
- {width = a; height = b;}
- protected:
- int width, height;
- };
- class Rectangle:public Shape {
- public:
- int area ()
- {return width*height;}
- };
- class Triangle: public Shape {
- public:
- int area ()
- {return width*height/2;}
- };
- int main()
- {
- Rectangle rect;
- Triangle trgl;
- rect.set_values (4,5);
- trgl.set_values (6,3);
- cout<<rect.area()<<endl;
- cout<<trgl.area()<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement