编写一个圆类Circle,该类拥有()
第1题:
要求:
(1)定义点类CPoint;
(2)定义圆类CCircle继承自类CPoint,类中属性包括:圆心,半径,类中方法包括:求周长perimeter()、求面积area();
(3) 定义主类CCircleDemo,利用类CCircle输出一个圆的圆心,半径,周长和面积
答案:如下
解析:
public class CPoint{
private float radius;
public CCircle(){
this.radius=5.0f;
}
public CCircleDemo(float radius){
this.radius=radius;
}
public void Area(){
System.out.println("半径为"+this.radius+"面积是:"+(3.14*radius*radius));
}
public void perimeter(){
System.out.println("半径为"+this.radius+"周长是:"+(3.14*2*radius));
}
public static void main(String arg[]){
CCircle c1=new CCircle();
c1.Area();
c1.perimeter();
CCircle c2=new CCirclet(9.0f);
c2.Area();
c2.perimeter();
}
}
第2题:
CIRCLE命令中的“T”选项指的画圆方式是()。
A.相切,相切,相切
B.相切,相切,半径
C.三点决定一个圆
D.两点决定一个圆
第3题:
下列程序中,先声明一个圆类circle和一个桌子类table,另外声明一个圆桌类roundtable,它是由 circle和table两个类派生的,要求声明一个圆桌类对象,并输出圆桌的高度,面积和颜色。请填空完成程序
include<iostream.h>
include<string.h>
class circle{
double radius;
public:
circle(double r){radius=r;}
double get_area(){return 3.416*radius*radius;}
};
class table{
double height;
public:
table(double h)<height=h;}
double get_height(){return height;}
};
class roundtable:public table,public circle{
char *color;
public:
roundtable(double h,double r,char c[]): 【 】 {
color=new char[strlen(c) +1];
【 】;
};
char*get_color(){return color;}
}:
void main(){
roundtable rt(0.8,1.0,“白色”);
cout<<"圆桌的高:"<<rt. get_height()<<end1;
cout<<"圆桌面积:"<<rt.get_area()<<end1;
cout<<"圆桌颜色:"<<n.get color()<<end1;
}
第4题:
如果一个派生类只有一个直接基类,则该类的继承方式称为【 】继承;如果一个派生类同时有多个直接基类,则该类的继承方式称为【 】继承。
第5题:
关于抽象类和具体类,下列说法不正确的是()
第6题:
在java中一个类被声明为final类型,表示的意思是()
第7题:
定义一个类名为“MyClass.java”的类,并且该类可被一个工程中的所有类访问,那么该类的正确声明应为()
第8题:
画一个圆与三个对象相切,应使用Circle中哪一个选项()
第9题:
关于圆和椭圆的绘制说法正确的是()
第10题:
用CIRCLE命令画圆时,圆的半径输入0,则会绘制出一个点
第11题:
对
错
第12题:
this指针必须显式说明
定义一个类后,this指针就指向该类
成员函数拥有this指针
静态成员函数拥有this指针
第13题:
A.A
B.B
C.C
D.D
第14题:
阅读以下说明和C代码,将应填入(n)处的字句写在的对应栏内。
【说明】
在一个简化的绘图程序中,支持的图形种类有点(point)和圆(circle),在设计过程中采用面向对象思想,认为所有的点和圆都是一种图形(shape),并定义了类型shape t、 point t和circle t分别表示基本图形、点和圆,并且点和圆具有基本图形的所有特征。
【C代码】
typedef enum { point,circle } shape type; /* 程序中的两种图形:点和圆 */
typedef struct { /* 基本的图形类型 */
shape_type type; /* 图形中类标识:点或者圆*/
void (*destroy) (); /* 销毁图形操作的函数指针*/
void (*draw) (); /* 绘制图形操作的函数指针*/
} shape_t;
typedef struct { shape_t common; int x; iht y; } point_t; /* 定义点类
型, x, y为点坐标*/
void destroyPoint (point_t* this) { free (this); printf ("Point destoryed!
\n"); } ) /* 销毁点对象*/
void drawPoint(point_t* this) { printf("P(%d,%d)", this->x, this->y); }
/* 绘制点对象*/
shape_t* createPoint (va_list* ap) (/* 创建点对象,并设置其属性*/
point_t* p_point;
if ( (p_point= (point_t*)malloc (sizeof (point_t)) ) ==NULL) returnNULL;
p_point->common, type = point; p_point->common, destroy = destroyPoint;
p_point->common.draw = drawPoint;
p_point->x = va_arg(*ap, int); /* 设置点的横坐标*/
p_point->y = va_arg(*ap, int); /* 设置点的纵坐标*/
return (shape_t*)p_ooint; /*返回点对象指针*/
}
typedef struct { /*定义圆类型*/
shape_t common;
point_t 4center; /*圆心点*/
int radius; /*圆半径*/
} circle_t;
void destroyCircle(circle_t* this){
free((1)); free(this); printf("Circle destoryed!\n");
}
void drawCircle(circle_t* this) {
print f ("C (");
(2).draw(this->center); /*绘制圆心*/
printf(",%d) ", this->radius);
}
shape_t* createCircle(va_list4 ap) { /*创建一个圆,并设置其属性*/
circle_t4 p circle;
if ((p_circle = (circle_t4)malloc (sizeof (circle_t)) ) ==NULL ) return NULL;
p_circle->common.type = circle; p_circle->common.destroy = destroy
Circle;
p_circle->common.draw = drawCircle;
(3) = createPoint(ap); /* 设置圆心*/
p_circle->radius = va_arg(*ap, int); /* 设置圆半径*/
return p_circle;
}
shape_t* createShape(shape_type st, "') { /* 创建某一种具体的图形*/
va_list ap; /*可变参数列表*/
&nbs
第15题:
运行以下程序后,输出的图形是( )。 Forr=O To 150 Circle(320,240),r Fori=1 To 1000 Nexti Nextr
A.一个固定的空心圆
B.一个半径逐渐变大的空心圆
C.一个固定的实心圆
D.一个半径逐渐变大的实心圆
第16题:
此题为判断题(对,错)。
第17题:
CIRCLE命令中的“T”选项指的画圆方式是()。
第18题:
定义一个类名为MyClass的类,并且该类可被所有类访问,那么该类的正确声明应为()
第19题:
无序列表的属性值circle表示()。
第20题:
关于this指针的说法正确的是()
第21题:
CIRCLE是什么绘制命令()。
第22题:
Rectangle类和Circle类都有名为area的属性,这两个属性一定是相同的属性
Rectangle类和Circle类都有名为getArea的操作,这两个操作一定是相同的操作
Rectangle中名为length的属性和Circle类中名为radius的属性,这两个属性一定是不同的属性
Shape类有一个属性,Circle类有两个属性,Rectangle类有三个属性
第23题:
相切,相切,相切
相切,相切,半径
三点决定一个圆
两点决定一个圆