专业软件设计师网站|培训机构|服务商(加客服微信:cnitpm或QQ:800184589进软件设计师学霸群)

软题库 培训课程
当前位置:信管网 >> 软件设计师 >> 案例分析 >> 文章内容
软件设计师下午真题及答案17
来源:信管网 2021年08月20日 【所有评论 分享到微信

为帮助广大软考中级软件设计师考生更好备考,信管网特整理汇总了软件设计师部分下午真题、答案及解析供考生查阅,并提供免费在线模拟答题、历年真题免费下载等服务,了解软件设计师更多备考信息请关注信管网。

相关推荐:

点击查看/下载:软件设计师历年真题汇总

点击查看:软件设计师在线培训课程免费试听课程

免费练习:软件设计师考试题库(模拟试题、章节练习、每日一练)

阅读以下说明和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; /*可变参数列表*/

shape_t4 p_shape = null;

(4) (ap, st);

if( st == point ) p shape = createpoint(&ap); /* 创建点对象*/

if( st == circle ) p shape = createcircle(&ap); /*创建圆对象*/

va_end (ap);

return p_shape;

}

int main( ) {

int i; /* 循环控制变量,用于循环计数*/

shape_t* shapes[2]; /* 图形指针数组,存储图形的地址*/

shapes[0] = createshape( point, 2, 3); /* 横坐标为2,比值坐标为3*/

shapes[ii = createshape( circle, 20, 40, 10); /* 圆心坐标(20,40),

半径为 10*/

for(i=0 i<2; i++) { shapes[i]->draw(shapes[i]); printf("\n"); } /*

纵制数组中图形*/

for( i = 1; i >= 0; i-- ) shapes[i]->destroy(shapes[i]); /* 销毁

数组中图形*/

return 0;

}

【运行结果】

p(2,3)

(5)

circle destoryed !

point destoryed !

查看答案与解析:www.cnitpm.com/st/2456118617.html

扫码关注公众号

温馨提示:因考试政策、内容不断变化与调整,信管网网站提供的以上信息仅供参考,如有异议,请以权威部门公布的内容为准!

信管网致力于为广大信管从业人员、爱好者、大学生提供专业、高质量的课程和服务,解决其考试证书、技能提升和就业的需求。

信管网软考课程由信管网依托10年专业软考教研倾力打造,官方教材参编作者和资深讲师坐镇,通过深研历年考试出题规律与考试大纲,深挖核心知识与高频考点,为学员考试保驾护航。面授、直播&录播,多种班型灵活学习,满足不同学员考证需求,降低课程学习难度,使学习效果事半功倍。

相关内容

发表评论  查看完整评论  

推荐文章