网友您好, 请在下方输入框内输入要搜索的题目:
题目内容
(请给出正确答案)
publicclassMycircle{publicdoubleradius;publicdoublediameter;publicvoidsetRadius(doubleradius)this.radius=radius;this.diameter=radius*2;}publicdoublegetRadius(){returnradius;}Whichstatementistrue?()
A.TheMycircleclassisfullyencapsulated.
B.ThediameterofagivenMyCircleisguaranteedtobetwiceitsradius.
C.Lines6and7shouldbeinasynchronizedblocktoensureencapsulation.
D.TheradiusofaMyCircleobjectcanbesetwithoutaffectingitsdiameter.
参考答案
更多 “ publicclassMycircle{publicdoubleradius;publicdoublediameter;publicvoidsetRadius(doubleradius)this.radius=radius;this.diameter=radius*2;}publicdoublegetRadius(){returnradius;}Whichstatementistrue?() A.TheMycircleclassisfullyencapsulated.B.ThediameterofagivenMyCircleisguaranteedtobetwiceitsradius.C.Lines6and7shouldbeinasynchronizedblocktoensureencapsulation.D.TheradiusofaMyCircleobjectcanbesetwithoutaffectingitsdiameter. ” 相关考题
考题
( 13 )补充完整下面的类定义:const double PI=3 .14;class Circle{ // 圆形物体的抽象基类protected:double r; // 半径public:Circle ( double radius=0 ) : r ( radius ) {}【 13 】 ; // 计算圆形物体表面积的纯虚函数声明};class Cylinder:public Circle { // 圆柱体类double h; // 高度public:Cylindr ( double radius=0, doubli height=0 ) :Circle ( radius ) , h ( height ) {}Virtual double Area () { // 计算圆柱体的表面积return 2*PI*r* ( r+h ) ;}};
考题
C++代码的错误在哪
#includeiostreamviod mian(){ const double pi=3.1415926; double radius; double areas; cout"input radius:"endl; cinradius; areas=pi*radius*radius; cout"the areas"radius"is"areas"\n"endl;}哪里有错啊,高手指教???
考题
阅读以下说明和C++程序,将应填入(n)处的字句写在对应栏内。【说明】以下程序的功能是计算正方体、球体和圆柱体的表面积和体积并输出。程序由4个类组成:类cube、sphere和cylinder分别表示正方体、球体和圆柱体;抽象类 container为抽象类,提供了两个纯虚拟函数surface_area()和volum(),作为通用接口。【C++程序】include<iostream.h>define pi 3.1416class container{protected:double radius;public:container(double radius) {container::radius=radius;}virtual double surface_area()=0;virtual double velum()=0;};class cube:(1){ //定义正方体类public:cube(double radius):container(radius){};double surface_area () {return 6 * radius * radius;}double volum() {return radius * radius * radius;}};class sphere:(2){ //定义球体类public:sphere(double radius): container(radius){};double surface_area() { return (3);}double volum() {return pi * radius * radius * radius * 4/3;}};class cylinder:(4){ //定义圆柱体类double height;public:cylinder(double radius,double height):container(radius){container::height=height;}double surface_are a () { return 2 * pi * radius * (height+radius); }double volum () {return (5);}};void main(){container * p;cube obj1 (5);sphere obj2(5);cylinder obj3(5,5);p=obj1;cout<<“正方体表面积”(<<p->surface_area()<<end1;cont<<“正方体体积”<<p->volume()<<end1;p=obj2;cout<<“球体表面积”<<p->surface_area()<<end1;cout<<“球体体积”<<p->volume()<<end1;p=obj3;cout<<“球体表面积”<<p->surface_area()<<end1;cout<<“球体体积”<<p->volume()<<end1;}
考题
Interrupts are an important part of embeddedsystems. Consequently, many compiler vendorsoffer an extension to standard C to support interrupts.Typically, the keyword is __interrupt. The followingcode uses __interrupt to define an interrupt serviceroutine (ISR). Point out problems in the code.__interrupt double compute_area (double radius){double area = PI * radius * radius;printf("\nArea = %f", area);return area;}
考题
请把下面程序补充完整,正确答案是( )。 main( ) { float radius,length,area,volume; printf("Input a radius:"); Scanf("%f",radius); length=2.0*PI*radius; /*引用无参宏求周长*/area=PI*radius*redius; /*引用无参宏求而积*/ volume=PI*radius*radius*radius*3/4; /*引用无参宏求体积*/ printf("length=%.2f,area=%.2f,volume=%.2f\n",length,area,volume); }A.PI=3.1415926B.Const PI=3.14159C.#define PI3.1415926D.Float PI=3.14159
考题
阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
【说明】
以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。
【Java代码】
interface?DrawCircle?{? //绘制圆形 public(1) ;}class?RedCircle?implements?DrawCircle?{? ?//绘制红色圆形???????public?void?drawCircle(int?radius,intx,?int?y)??{????????????System.out.println("Drawing?Circle[red,radius:"?+?radius?+",x:"?+?x?+?",y:"?+y+?"]");???????}}class?GreenCircle?implements?DrawCircle?{????//绘制绿色圆形??????public?void?drawCircle(int?radius,?int?x,int?y)?{???????????System.out.println("Drawing?Circle[green,radius:"?+radius+",x:?"?+x+?",y:?"?+y+?"]");??????}}abstract?class?Shape?{????//形状? protected? ? (2)???;? ? public?Shape(DrawCircle?drawCircle)?{? ?this.drawCircle=?drawCircle;? ? ? public?abstract?void?draw();}class?Circle?extends?Shape?{? //圆形? ?private?int?x,y,radius;? public?Circle(int?x,int?y,intradius,DrawCircle?drawCircle)?{? ?(3)???;? this.x?=?x;? ? ? this.y?=?y;? ?this.radius?=radius;? }? ? ?public?void?draw()?{? ? drawCircle.? ?(4)? ?;? ? ? }}public?class?DrawCircleMain?{? public?static?void?main(String[]?args)?{? Shape?redCircle=new?Circle(?100,100,10,? (5) );//绘制红色圆形? Shape?greenCircle=new?Circle(200,200,10,(6) );//绘制绿色圆形? ?redCircle.draw(); greenCircle.draw();? ?}}
考题
5、下面的代码使用__interrupt关键字定义了一个中断服务子程序(ISR),请找出这段代码的错误之处。 __interrupt double compute_area(double radius) { double area=PI*radius*radius; printf("nArea=%f",area); return area; }
考题
172、已知Circle类定义如下所示,则下列说法正确的是()。 class Circle { public: double m_x,m_y; double m_radius; void setCenter(double x,double y) { m_x=x; m_y=y; } void setRadius(double radius) { m_radius=radius; } double getArea() { return 3.14 * m_radius * m_radius; } };A.m_x、m_y和m_radius都是Circle类的成员变量B.setCenter、setRadius和getArea都是Circle类的成员函数C.类定义体后面的分号可以省略D.将double m_radius;改为double m_radius=1;,则表示m_radius成员变量的初值为1
考题
6、下列哪个选项是判断半径是不是正的,并求出圆的面积?A.if radius != 0: print(radius * radius * 3.14159)B.if radius >= 0: print(radius * radius * 3.14159)C.if radius < 0: print(radius * radius * 3.14159)D.if radius <= 0: print(radius * radius * 3.14159)
热门标签
最新试卷