目录
4、计算三角形,正方形,圆形面积、周长。要求:
(1)设计基类 shape,并定义 area(),cir(两个虚函数。
(2)设计三个派生类(三角形,正方形,圆形)。
(2)在主函数中,利用基类指针,进行派生类成员函数的调用,实现动态联编。
- #include<iostream>
- using namespace std;
- const double PI = 3.14;
- class shape
- {
- public:
- virtual int area() = 0;
- virtual int cir() = 0;
- };
- class sanjiao:public shape
- {
- private:
- int l1;
- int l2;
- int l3;
- public:
- sanjiao(int l, int