/*
Multiple Inheritance
Base Class: Polygon Output
Derived Class Polygon,Output->Rectangle Polygon,Output->Triangle
*/
#include<iostream>
using namespace std;
class Polygon
{
protected:
float width,height;
public:
void read(int a,int b)
{
width=a;
height=b;
}
};
class Output
{
public:
void output(int a)
{
cout<<"\n\n Area: "<<a;
}
};
class Rectangle :public Polygon,public Output
{
public:
float area()
{
float a;
a=width*height;
return a;
}
};
class Triangle :public Polygon,public Output
{
public:
float area()
{
float a1;
a1=0.5*(width*height);
return a1;
}
};
int main()
{
Rectangle R;
Triangle T;
T.read(10,20);
cout<<"\n\n Triangle: ";
T.output(T.area());
R.read(10,20);
cout<<"\n\n Rectangle: ";
R.output(R.area());
return 0;
}
Multiple Inheritance
Base Class: Polygon Output
Derived Class Polygon,Output->Rectangle Polygon,Output->Triangle
*/
#include<iostream>
using namespace std;
class Polygon
{
protected:
float width,height;
public:
void read(int a,int b)
{
width=a;
height=b;
}
};
class Output
{
public:
void output(int a)
{
cout<<"\n\n Area: "<<a;
}
};
class Rectangle :public Polygon,public Output
{
public:
float area()
{
float a;
a=width*height;
return a;
}
};
class Triangle :public Polygon,public Output
{
public:
float area()
{
float a1;
a1=0.5*(width*height);
return a1;
}
};
int main()
{
Rectangle R;
Triangle T;
T.read(10,20);
cout<<"\n\n Triangle: ";
T.output(T.area());
R.read(10,20);
cout<<"\n\n Rectangle: ";
R.output(R.area());
return 0;
}