#include <iostream> using namespace std; class base { public: virtual void set(); }; class Triangle:public base { public: Triangle(int x=0,int y=0) { height=x; width=y; } void set() { cout<<"三角形面积 "<< height*width/2<<endl; } private: int height,width ; }; class Cicle:public base { public: Cicle(float a=0.0) { radius=a; } void set() { cout<<"圆面积 "<<3.1415*radius*radius<<endl; } private: float radius; }; int main() { Triangle t(4,4); t.set(); Cicle c(10.0); t.set(); return 0; }
添加回答
举报
0/150
提交
取消