//
// main.m
// 3.2.1 过程式编程 #import <Foundation/Foundation.h>
typedef enum {
kCircle,
kRectangle,
kOblateSpheroid,
kTriangle
}ShapeType;
//绘制形状时可用的颜色
typedef enum {
kRedColor,
kGreenColor,
kBlueCOlor,
}ShapeColor; typedef struct {
int x,y,width,height;
}ShapeRect; typedef struct {
ShapeType type;
ShapeColor fillColor;
ShapeRect bounds;
}Shape; //声明函数体
NSString *colorName(ShapeColor colorName); void drawCirele(ShapeRect bounds,ShapeColor fillColor); void drawShapes(Shape shapes[], int count); int main(int argc, const char * argv[]) {
Shape shapes[]; ShapeRect rect0 = {,,,};
shapes[].type = kCircle;
shapes[].fillColor = kRedColor;
shapes[].bounds = rect0; ShapeRect rect1 = {,,,};
shapes[].type = kRectangle;
shapes[].fillColor = kGreenColor;
shapes[].bounds = rect1; ShapeRect rect2 = {,,,};
shapes[].type = kOblateSpheroid;
shapes[].fillColor = kBlueCOlor;
shapes[].bounds = rect2; ShapeRect rect3 = {,,,};
shapes[].type = kTriangle;
shapes[].fillColor = kRedColor;
shapes[].bounds = rect3; drawShapes(shapes,); return ;
}
NSString *colorName(ShapeColor colorName){
switch (colorName) {
case kRedColor:
return @"red";
break;
case kBlueCOlor:
return @"blue";
break;
case kGreenColor:
return @"green";
break; default:
break;
}
return @"no clue";
} //此函数仅输出有边框的矩形和传递给它的颜色;
void drawCirele(ShapeRect bounds,ShapeColor fillColor){
NSLog(@"drawing a cirecle at(%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colorName(fillColor));
}
//长方形
void drawRectangle(ShapeRect bounds,ShapeColor fillColor){
NSLog(@"drawing a Rectangle at(%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colorName(fillColor));
}
//椭圆
void drawEgg(ShapeRect bounds,ShapeColor fillColor){
NSLog(@"drawing a Egg at(%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colorName(fillColor));
}
//新增三角形
void drawTriangle(ShapeRect bounds,ShapeColor fillColor){
NSLog(@"drawing a Egg at(%d %d %d %d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colorName(fillColor));
} void drawShapes(Shape shapes[], int count){
int i ;
for (i = ; i<count; i++) {
switch (shapes[i].type) {
case kCircle:
drawCirele(shapes[i].bounds,shapes[i].fillColor);
break;
case kRectangle:
drawRectangle(shapes[i].bounds,shapes[i].fillColor);
break;
case kOblateSpheroid:
drawEgg(shapes[i].bounds,shapes[i].fillColor);
break;
case kTriangle:
drawTriangle(shapes[i].bounds,shapes[i].fillColor);
break;
default:
break;
}
}
}

过程式编程 drawShapes的更多相关文章

  1. GO语言的进阶之路-面向过程式编程

    GO语言的进阶之路-面向过程式编程 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 我们在用Golang写一个小程序的时候,未免会在多个地方调用同一块代码,这个时候如何优化你的代码呢 ...

  2. Objective-C中的面向对象编程

    1.过程式编程实例,画出Shape数组中的图形: // // main.m // hello-obj // // Created by zhouyang on 16/4/4. // Copyright ...

  3. Objective-C 基础教程第三章,面向对象编程基础知

    目录 Objective-C 基础教程第三章,面向对象编程基础知 0x00 前言 0x01 间接(indirection) 0x02 面向对象编程中使用间接 面向过程编程 面向对象编程 0x03 OC ...

  4. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  5. 《C#并发编程经典实例》笔记

    1.前言 2.开宗明义 3.开发原则和要点 (1)并发编程概述 (2)异步编程基础 (3)并行开发的基础 (4)测试技巧 (5)集合 (6)函数式OOP (7)同步 1.前言 最近趁着项目的一段平稳期 ...

  6. IOS响应式编程框架ReactiveCocoa(RAC)使用示例

    ReactiveCocoa是响应式编程(FRP)在iOS中的一个实现框架,它的开源地址为:https://github.com/ReactiveCocoa/ReactiveCocoa# :在网上看了几 ...

  7. Clojure学习笔记(二)——函数式编程

    定义 “函数式编程”是一种编程范式(programming paradigm),即如何编写程序的方法论.主要思想是把运算过程尽量写成一系列嵌套的函数调用. 举例来说,现在有这样一个数学表达式: (1 ...

  8. 【Linux】Shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  9. Scala学习笔记--函数式编程

    一.定义 简单说,"函数式编程"是一种"编程范式"(programming paradigm),也就是如何编写程序的方法论. 它属于"结构化编程&qu ...

随机推荐

  1. Python 3学习笔记2

    模块: 模块是一个包含Python代码的文本文件.使用import可以将模块导入到其他程序中. 每个模块都有自己的命名空间.主Python程序中的代码与一个名为__main__的明明空间关联.将代码放 ...

  2. OAuth 2.0

    国外 OAuth2.0 大全:http://oauth.net/2/ 国内经典:http://www.fising.cn/2011/03/%E4%B8%80%E6%AD%A5%E4%B8%80%E6% ...

  3. contiki-main.c 一 打印观察 <contiki学习之五>

    说明: 本文依赖于 contiki/platform/native/contiki-main.c 文件. 在项目工程目录下的hello-world.c 文件里面,有许多的宏,但没有最关键的main() ...

  4. 【OSG】osgText::Text 研究

    由于需要在3D坐标轴上显示刻度值,所以要用到osgText::Text,这里简单记录一下其常见用法. 一.基本知识 常见设置 设置字体:setFont 设置内容:setText,这里输入参数需要是os ...

  5. 【HMTL】3D标签球

    这是一个3D TAG 在网站展示中是个不错的东东,能让人眼前一亮,值得收藏. 这个是效果: 源码下载: 点 击 下 载

  6. 在Linux(Ubuntu/openSUSE/CentOS)下配置ASP.NET(Apache + Mono)转载+补充

    错误:Network error: Connection refused 解决办法: 执行 $sudo apt-get install openssh-server 安装ssh协议 执行ifconfi ...

  7. 【剑指offer】八皇后问题

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/26614999 剑指offer上解决八皇后问题,没实用传统的递归或非递归回溯法,而是用了非常 ...

  8. php中数组自定义排序

    php中数组自定义排序方法有很多,现在只提usort();不会保留原有键名. unsort调用方法就是unsrot($arr,func); 注意: 如果func是写在当前类中的话,那么调用的方式是 u ...

  9. xtrabackup原理0

  10. string 对象及其操作

    标准库类型string 标准库类型string表示可变长的字符序列,使用string类型必须首先包含string头文件.作为标准库的一部分,string定义在命名空间std中.接下来的示例都假定了已包 ...