//main
include<iostrea
m> include
"bai1.h" using
namespace std;
int main() {
Shape* shape;
Rectangle rec(10, 7);
Triangle tri(10, 5);
// store the address of
Rectangle shape = firec;
// call rectangle area.
cout << shape->area() << endl;
// store the address of
Triangle shape = fitri;
// call triangle area.
cout << shape->area() << endl;
return 0;
}
//cpp
include"bai1.h"
include<iostrea
m>
using namespace std;
Shape::Shape(int a, int b) {
width = a;
height = b;
}
int Shape::area() {
cout << "flarent class area :" <<
endl; return 0;
}
int Rectangle::area() {
cout << "Rectangle class area :" <<
endl; return (width * height);
}
Triangle::Triangle(int a, int b) : Shape(a, b)
{} int Triangle :: area()
{
cout << "Triangle class area :" <<
endl; return (width * height / 2);
}
//h
pragma
once ifndef
S AflE
define S AflE
class Shape
{ protected:
int width,
height; public:
Shape(int a = 0, int b = 0);
virtual int area();
};
class Rectangle : public Shape {
public:
Rectangle(int a = 0, int b =
0); int area() override;
};
class Triangle : public Shape {
public:
Triangle(int a = 0, int b =
0); int area() override;
};
endif