阅读以下说明和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 = destroyCircle;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

阅读以下说明和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


相关考题:

阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。【说明】已知头指针分别为La和lb的有序单链表,其数据元素都是按值非递减排列。现要归并La和Lb得到单链表Lc,使得Lc中的元素按值非递减排列。程序流程图如下所示:

阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序为求行列式X(5,5)的值S。【Visual Basic代码】Private Function col ( byval x ( 5,5 ) as integer ) as longdim fesult as longdim temp as longdim I as integerdim j as integerdim k as imegerresult = 0for I = to 5(1)for j = 1 to 5if I+j>6 thenk= ( 1+j ) mod 5elsek=1endiftemp=temp*x ( k,j )(2)result=(3)(4)(5)End function

阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。[说明]设学生某次考试的成绩按学号顺序逐行存放于某文件中,文件以单行句点“.”为结束符。下面的流程图读取该文件,统计出全部成绩中的最高分max和最低分min。

阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回答相应问题。比较下面两段程序的优缺点。①for (i=0; i<N; i++ ){if (condition)//DoSomething…else//DoOtherthing…}②if (condition) {for (i =0; i<N; i++ )//DoSomething}else {for (i=0; i <N; i++ )//DoOtherthing…}

阅读以下说明和流程图,将应填入(n)处的字句写在对应栏内。[说明]下面的流程图用于计算一个英文句子中最长单词的长度(即单词中字母个数)MAX。假设该英文句子中只含字母、空格和句点“.”,其中句点表示结尾,空格之间连续的字母串称为单词。[流程图]

●试题二阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】该程序运行后,输出下面的数字金字塔【程序】includestdio.hmain (){char max,next;int i;for(max=′1′;max=′9′;max++){for(i=1;i=20- (1) ;++i)printf(" ");for(next= (2) ;next= (3) ;next++)printf("%c",next);for(next= (4) ;next= (5) ;next--)printf("%c",next);printf("\n");}}

试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】 某文件管理系统中定义了类OfficeDoc和DocExplorer,当类OfficeDoc发生变化时,类DocExplorer的所有对象都要更新其自身的状态,现采用观察者(Observer)设计模式来实现该需求,所设计的类图如图6-1所示。

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。【说明】某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。