中文字幕综合一区,伊人av网,欧美中日韩在线,亚洲国产香蕉视频,黄视频在线免费,天天操天天爱天天爽,狠狠躁天天躁

專業(yè)軟件設計師網(wǎng)站|服務平臺|服務商(加客服微信:cnitpm或QQ:947530340進軟件設計師學霸群)

軟題庫 學習課程
當前位置:信管網(wǎng) >> 軟件設計師 >> 每日一練 >> 文章內(nèi)容
軟件設計師案例分析每日一練試題(2024/3/21)

軟件設計師案例分析當天每日一練試題地址:www.jazzmuze.com/exam/ExamDayAL.aspx?t1=4

往期軟件設計師每日一練試題匯總:www.jazzmuze.com/class/27/e4_1.html

軟件設計師案例分析每日一練試題(2024/3/21)在線測試:www.jazzmuze.com/exam/ExamDayAL.aspx?t1=4&day=2024/3/21

點擊查看:更多軟件設計師習題與指導

軟件設計師案例分析每日一練試題內(nèi)容(2024/3/21)

試題五
閱讀以下說明和C代碼,將應填入  (n)  處的字句寫在的對應欄內(nèi)。
【說明】
在一個簡化的繪圖程序中,支持的圖形種類有點(point)和圓(circle),在設計過程中采用面向?qū)ο笏枷?,認為所有的點和圓都是一種圖形(shape),并定義了類型shape t、 point t和circle t分別表示基本圖形、點和圓,并且點和圓具有基本圖形的所有特征。
【C代碼】
typedef enum { point,circle } shape type;   /* 程序中的兩種圖形:點和圓 */
typedef struct {             /* 基本的圖形類型 */
shape_type  type;        /* 圖形中類標識:點或者圓*/
void (*destroy) ();       /* 銷毀圖形操作的函數(shù)指針*/
void (*draw) ();          /* 繪制圖形操作的函數(shù)指針*/
} 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)  (/* 創(chuàng)建點對象,并設置其屬性*/
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)  {     /*創(chuàng)建一個圓,并設置其屬性*/
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, "')  {    /* 創(chuàng)建某一種具體的圖形*/
va_list   ap;                      /*可變參數(shù)列表*/
shape_t4  p_shape = NULL;
(4)   (ap, st);
if( st == point )   p shape = createPoint(&ap);   /* 創(chuàng)建點對象*/
if( st == circle )  p shape = createCircle(&ap);   /*創(chuàng)建圓對象*/
va_end (ap);
return p_shape;
}
int main( )  {
int i;                  /* 循環(huán)控制變量,用于循環(huán)計數(shù)*/
shape_t* shapes[2];     /* 圖形指針數(shù)組,存儲圖形的地址*/
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");  } /*
縱制數(shù)組中圖形*/
for( i = 1; i >= 0; i-- )  shapes[i]->destroy(shapes[i]);   /* 銷毀
數(shù)組中圖形*/
return 0;
}
【運行結果】
P(2,3)
(5)
Circle destoryed !
Point destoryed !

信管網(wǎng)試題答案與解析:www.jazzmuze.com/st/2456118617.html

信管網(wǎng)考友試題答案分享:

信管網(wǎng)試題答案與解析:www.jazzmuze.com/st/2456118617.html

信管網(wǎng)訂閱號

信管網(wǎng)視頻號

信管網(wǎng)抖音號

溫馨提示:因考試政策、內(nèi)容不斷變化與調(diào)整,信管網(wǎng)網(wǎng)站提供的以上信息僅供參考,如有異議,請以權威部門公布的內(nèi)容為準!

信管網(wǎng)致力于為廣大信管從業(yè)人員、愛好者、大學生提供專業(yè)、高質(zhì)量的課程和服務,解決其考試證書、技能提升和就業(yè)的需求。

信管網(wǎng)軟考課程由信管網(wǎng)依托10年專業(yè)軟考教研傾力打造,教材和資料參編作者和資深講師坐鎮(zhèn),通過深研歷年考試出題規(guī)律與考試大綱,深挖核心知識與高頻考點,為學員考試保駕護航。面授、直播&錄播,多種班型靈活學習,滿足不同學員考證需求,降低課程學習難度,使學習效果事半功倍。

相關內(nèi)容

發(fā)表評論  查看完整評論  

推薦文章

精選

課程

提問

評論

收藏