How can use Multiple Inheritance In C++

#include <iostream>
using namespace std;
class Polygon {
  public:
    double width, height;
    void val(double a, double b)
      { 
                    width=a; 
                    height=b; 
      }
};
class output{
      public:
             void out(double o)
             {
                  cout<<o<<endl;
             }
};               
class Rectangle: public Polygon, public output{
      public:
             double Rect()
             {
                      return height*width;
             }
};
class Triangle: public Polygon, public output{
      public:
             double trig()
             {
                 return height*width*0.5;
             }
};
int main()
{
    Rectangle Rec;
    Triangle Tri;
    Rec.val(5,6);
    Rec.out(Rec.Rect());
    Tri.val(5,6);
    Tri.out(Tri.trig());
    system("pause");
    return 0;
}
    


This is the output:
30
15

0 comments:

Post a Comment