一个小C++问题

[复制链接]
查看11 | 回复1 | 2009-6-14 17:45:52 | 显示全部楼层 |阅读模式
生成一个Object抽象类,在其中声明double CalArea()为纯虚函数,从Object派生出:
Rect类(其中包含成员变量Point topleft,Point bottomright。其中Point为其子对象)、
Circle类(其中包含成员变量Point cc,double radius ),实现如下功能:
void main() { Object *obj[2]; obj[0]=new Rect(Point(0,0),Point(100,200)); obj[1]=new Circle(Point(100,200),100.0); int i; for (i=0;icalarea()<<endl; } }

回复

使用道具 举报

千问 | 2009-6-14 17:45:52 | 显示全部楼层
#include using namespace std;class Object{public: Object(){} virtual double calarea()=0;};class Point{public: Point(){}; Point(double x,double y):x(x),y(y){} double getX(){return x;} double getY(){return y;}private: double x; double y;};class Rect:public Object{public: Rect()...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行