軟件設(shè)計(jì)師案例分析當(dāng)天每日一練試題地址:m.xiexiliangjiufa.com/exam/ExamDayAL.aspx?t1=4
往期軟件設(shè)計(jì)師每日一練試題匯總:m.xiexiliangjiufa.com/class/27/e4_1.html
軟件設(shè)計(jì)師案例分析每日一練試題(2025/4/25)在線測(cè)試:m.xiexiliangjiufa.com/exam/ExamDayAL.aspx?t1=4&day=2025/4/25
點(diǎn)擊查看:更多軟件設(shè)計(jì)師習(xí)題與指導(dǎo)
軟件設(shè)計(jì)師案例分析每日一練試題內(nèi)容(2025/4/25)
試題五
閱讀以下說明和C代碼,將應(yīng)填入 (n) 處的字句寫在的對(duì)應(yīng)欄內(nèi)。
【說明】
在一個(gè)簡(jiǎn)化的繪圖程序中,支持的圖形種類有點(diǎn)(point)和圓(circle),在設(shè)計(jì)過程中采用面向?qū)ο笏枷?,認(rèn)為所有的點(diǎn)和圓都是一種圖形(shape),并定義了類型shape t、 point t和circle t分別表示基本圖形、點(diǎn)和圓,并且點(diǎn)和圓具有基本圖形的所有特征。
【C代碼】
typedef enum { point,circle } shape type; /* 程序中的兩種圖形:點(diǎn)和圓 */
typedef struct { /* 基本的圖形類型 */
shape_type type; /* 圖形中類標(biāo)識(shí):點(diǎn)或者圓*/
void (*destroy) (); /* 銷毀圖形操作的函數(shù)指針*/
void (*draw) (); /* 繪制圖形操作的函數(shù)指針*/
} shape_t;
typedef struct { shape_t common; int x; iht y; } point_t; /* 定義點(diǎn)類
型, x, y為點(diǎn)坐標(biāo)*/
void destroyPoint (point_t* this) { free (this); printf ("Point destoryed!
\n"); } ) /* 銷毀點(diǎn)對(duì)象*/
void drawPoint(point_t* this) { printf("P(%d,%d)", this->x, this->y); }
/* 繪制點(diǎn)對(duì)象*/
shape_t* createPoint (va_list* ap) (/* 創(chuàng)建點(diǎn)對(duì)象,并設(shè)置其屬性*/
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); /* 設(shè)置點(diǎn)的橫坐標(biāo)*/
p_point->y = va_arg(*ap, int); /* 設(shè)置點(diǎn)的縱坐標(biāo)*/
return (shape_t*)p_ooint; /*返回點(diǎn)對(duì)象指針*/
}
typedef struct { /*定義圓類型*/
shape_t common;
point_t 4center; /*圓心點(diǎn)*/
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) { /*創(chuàng)建一個(gè)圓,并設(shè)置其屬性*/
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); /* 設(shè)置圓心*/
p_circle->radius = va_arg(*ap, int); /* 設(shè)置圓半徑*/
return p_circle;
}
shape_t* createShape(shape_type st, "') { /* 創(chuàng)建某一種具體的圖形*/
va_list ap; /*可變參數(shù)列表*/
shape_t4 p_shape = NULL;
(4) (ap, st);
if( st == point ) p shape = createPoint(&ap); /* 創(chuàng)建點(diǎn)對(duì)象*/
if( st == circle ) p shape = createCircle(&ap); /*創(chuàng)建圓對(duì)象*/
va_end (ap);
return p_shape;
}
int main( ) {
int i; /* 循環(huán)控制變量,用于循環(huán)計(jì)數(shù)*/
shape_t* shapes[2]; /* 圖形指針數(shù)組,存儲(chǔ)圖形的地址*/
shapes[0] = createShape( point, 2, 3); /* 橫坐標(biāo)為2,比值坐標(biāo)為3*/
shapes[ii = createShape( circle, 20, 40, 10); /* 圓心坐標(biāo)(20,40),
半徑為 10*/
for(i=0 i<2; i++) { shapes[i]->draw(shapes[i]); printf("\n"); } /*
縱制數(shù)組中圖形*/
for( i = 1; i >= 0; i-- ) shapes[i]->destroy(shapes[i]); /* 銷毀
數(shù)組中圖形*/
return 0;
}
【運(yùn)行結(jié)果】
P(2,3)
(5)
Circle destoryed !
Point destoryed !
信管網(wǎng)考友試題答案分享:
信管網(wǎng)試題答案與解析:m.xiexiliangjiufa.com/exam/ExamDayAL.aspx?t1=4&day=2025/4/25信管網(wǎng)訂閱號(hào)
信管網(wǎng)視頻號(hào)
信管網(wǎng)抖音號(hào)
溫馨提示:因考試政策、內(nèi)容不斷變化與調(diào)整,信管網(wǎng)網(wǎng)站提供的以上信息僅供參考,如有異議,請(qǐng)以權(quán)威部門公布的內(nèi)容為準(zhǔn)!
信管網(wǎng)致力于為廣大信管從業(yè)人員、愛好者、大學(xué)生提供專業(yè)、高質(zhì)量的課程和服務(wù),解決其考試證書、技能提升和就業(yè)的需求。
信管網(wǎng)軟考課程由信管網(wǎng)依托10年專業(yè)軟考教研傾力打造,教材和資料參編作者和資深講師坐鎮(zhèn),通過深研歷年考試出題規(guī)律與考試大綱,深挖核心知識(shí)與高頻考點(diǎn),為學(xué)員考試保駕護(hù)航。面授、直播&錄播,多種班型靈活學(xué)習(xí),滿足不同學(xué)員考證需求,降低課程學(xué)習(xí)難度,使學(xué)習(xí)效果事半功倍。
發(fā)表評(píng)論 查看完整評(píng)論 | |