i6lan 分享题目的网站
试一试站内搜索 题目类型:问答题

污染物减排中要求减排的主要污染
产生放射性固体废物的单位,应对
到目前为止,大亚湾核电站自商业
"SELEC T Studen
根据《国家安全法》的规定,()

已定义一个Shape抽象类,在此基础上派生出矩形Rectangle和圆形Circle类,二者都有GetPerim()函数计算对象的周长,并编写测试main()函数。



class Shape

{public:

Shape(){}

~Shape(){}

virtual float GetPerim()=0;

}

答案:class Rectangle:public Shape

{public:

Rectangle(float i,float j):L(i),W(j){}

~Rectangle(){}

float GetPerim(){return 2*(L+W);}

private:

float L,W;

};

class Circle:public Shape

{public:

Circle(float r):R(r){}

float GetPerim(){return 3.14*2*R;}

private:

float R;

};

void main()

{Shape * sp;

sp=new Circle(10);

cout<<sp->GetPerim ()<<endl;

sp=new Rectangle(6,4);

cout<<sp->GetPerim()<<endl;

}

上一题 下一题

CopyRight©i6lan.com 关于本站
蜀ICP备2021017061号-1

川公网安备 51010402001278号