Advertisement
M_A_Tabarani

Some School stuff (13)

Nov 3rd, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Shape {
  6.  
  7.     public:
  8.         void set_values (int a,int b)
  9.         {width = a; height = b;}
  10.  
  11.     protected:
  12.         int width, height;
  13. };
  14.  
  15. class Rectangle:public Shape {
  16. public:
  17.     int area ()
  18.         {return width*height;}
  19. };
  20.  
  21. class Triangle: public Shape {
  22. public:
  23.     int area ()
  24.     {return width*height/2;}
  25. };
  26.  
  27. int main()
  28. {
  29.     Rectangle rect;
  30.     Triangle trgl;
  31.     rect.set_values (4,5);
  32.     trgl.set_values (6,3);
  33.     cout<<rect.area()<<endl;
  34.     cout<<trgl.area()<<endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement