题目
/****************** 文件shape.h*************************/
const float PI=3.14159f; // 定义圆周率常量
class Shape // 几何图形抽象类
{
public:
virtual float GetPerimeter()=0; // 纯虚函数,计算周长
virtual float GetAre()=0; // 纯虚函数,计算面积
};
class Rectangle: public Shape // 矩形类
{
public:
Rectangle (float len,float wid):length(len),width(wid){}
~Rectangle (){}
float GetPerimeter() {return 2*(length width);} // 计算矩形周长
float GetAre() {return length*width;} // 计算矩形面积
private:
float length, width; // 矩形的长和宽
};
class Circle: public Shape // 圆类
{
public: // 在下面编写每个成员函数
private:
float rad; // 圆的半径
};
class Square: public Rectangle // 正方形类
{
public:
Square(float len): Rectangle(len,len){}
~Square(){}
};
第1题
A.类Shape是类Point的基类
B.类Circle从类Shape公有继承
C.类Point是类Shape的派生类
D.类Circle是类Shape的派生类
第2题
第3题
class Shape
{public:
Shape(){}
~Shape(){}
virtual float GetPerim()=0;
}
第4题
阅读以下说明和C++代码,填入(n)处。
[说明]
以下C++代码使用虚函数实现了同一基类shape派生出来的Class rectangle、Class triangle、Class circle实现了计算矩形、圆形面积的计算。仔细阅读以下代码,将(n)处语句补充完整。
[代码5-1]
include<iostream.h>
define PI 3.14159
class shape {//基类
protected:
(1);
public:
(2);
(3);
};
[代码5-2]
class rectangle: public shape {
public:
rectangle (int x2,int y2,int r2): (4) {};
double area () {return x*y; };
};
class circle: public shape {
public:
circle (int x3,int y3,int r3):(5){};
double area () {return r*r*PI; };
};
[代码5-3]
void main ()
{
rectangle r (10,20,0);
circle c (0,0,30);
shape (6);
cout<<"长方形面积="<<s1->area () <<endl;
cout<<"圆形面积="<<s2->area () <<endl;
}
[运行结果]
长方形面积=200
圆形面积=2827.43
第5题
A. 类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.“Shape s;”能建立Shape的对象s
第6题
下面是类Shape的定义: class Shape{ public: virtual void Draw()=0; } 下列关于Shape类的描述中,正确的是()。
A.类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.语句“Shape s;”能够建立Shape的一个对象s
第7题
(32 )下面是类 Shape 的定义:
class Shape{
public:
virtual void Draw()=0;
};
下列关于 Shape 类的描述中,正确的是
A )类 Shape 是虚基类
B )类 Shape 是抽象类
C )类 Shape 中的 Draw 函数声明有误
D )语句 “ Shape s; ” 能够建立 Shape 的一个对象 s
第8题
下面是类Shape的定义:
classShape{
public:
virtualvoidDraw()=0;
}
下列关于Shape类的描述中,正确的是()。
A.类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.语句“ShapeS;”能够建立Shape的一个对象S
第9题
A.类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.语句“ShapeS;”能够建立Shape的一个对象S
第10题
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!