C语言的弊端

#import <Foundation/Foundation.h>
typedef enum{
    Kcircle,
    KRectangle,
    KOblateSpherold
}ShapeType;
typedef enum{
    KredColor,
    KGreenColor,
    KBlueColor
}ShapeColor;
typedef struct{
    int x,y,width,height;
}ShapeRect;
typedef struct {
    ShapeType type;
    ShapeColor fillColor;
    ShapeRect bounds;
}Shape;
char *getcolor(ShapeColor colorname){
    switch (colorname) {
        case KredColor:
            return "red";
            break;
        case KGreenColor:
            return "green";
            break;
        case KBlueColor:
            return "blue";
            break;
        default:
            break;
    }
}
void DrawCircle(ShapeRect bounds,
                ShapeColor fillColor)
{
      printf("drawing a circle at (%d %d %d %d) in %s\n",bounds.x,bounds.y,bounds.width,bounds.height,  getcolor(fillColor));
}
void DrawRectang(ShapeRect bounds,
                 ShapeColor fillColor)
{
     printf("drawing a rectang at (%d %d %d %d) in %s\n",bounds.x,bounds.y,bounds.width,bounds.height,  getcolor(fillColor));
}
void DrawEgg(ShapeRect bounds,
             ShapeColor fillColor)
{
    
    printf("drawing a egg at (%d %d %d %d) in %s\n",bounds.x,bounds.y,bounds.width,bounds.height,  getcolor(fillColor));
}
void drawshapes(Shape shapes[],int count)
{
    int i;
    for(i=0;i<count;i++){
        switch (shapes[i].type) {
            case Kcircle:
                DrawCircle(shapes[i].bounds,shapes[i].fillColor);
                break;
            case KRectangle:
                DrawRectang(shapes[i].bounds,shapes[i].fillColor);
                break;
            case KOblateSpherold:
                DrawEgg(shapes[i].bounds,shapes[i].fillColor);
                break;
        }
    }
}
int main(int argc, const char * argv[])
{

    Shape shapes[3];
    ShapeRect rect0 = {0,0,10,30};
    shapes[0].type=Kcircle;
    shapes[0].fillColor=KredColor;
    shapes[0].bounds=rect0;
    ShapeRect rect1 = {30,40,50,60};
    shapes[1].type=KRectangle;
    shapes[1].fillColor=KGreenColor;
    shapes[1].bounds=rect1;
    ShapeRect rect2 = {15,18,37,29};
    shapes[2].type=KOblateSpherold;
    shapes[2].fillColor=KBlueColor;
    shapes[2].bounds=rect2;
    drawshapes(shapes, 3);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值