//
// 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. Unix: How to Install BerkeleyDB From Source

    http://www.masaokitamura.com/2010/07/23/unix-how-to-install-berkeleydb-from-source/ This documentati ...

  2. PostgreSQL的 initdb 源代码分析之二十一

    继续分析: setup_schema(); 展开: 实质就是创建info_schema. cmd 是: "/home/pgsql/project/bin/postgres" --s ...

  3. event级别设置Resumable Space Allocation

    每日一贴,今天的内容关键字为event级别                           设置Resumable Space Allocation 设置Resumable Space Alloc ...

  4. Codeforces Gym 100733A Shitália 计算几何

    ShitáliaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.acti ...

  5. Codeforces Gym H. Hell on the Markets 贪心

    Problem H. Hell on the MarketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vj ...

  6. android圆角View实现及不同版本这间的兼容(android3.0过后的版本)

    http://blog.csdn.net/lovecluo/article/details/8710174 在做我们自己的APP的时候,为了让APP看起来更加的好看,我们就需要将我们的自己的View做 ...

  7. [Angular 2] Directive intro and exportAs

    First, What is directive, what is the difference between component and directive. For my understandi ...

  8. JAVA线程池简介

    一 简介 线程的使用在java中占有极其重要的地位,在jdk1.4极其之前的jdk版本中,关于线程池的使用是极其简陋的.在jdk1.5之后这一情况有了很大的改观.Jdk1.5之后加入了java.uti ...

  9. mydumper原理2

    使用mydumper备份发生Waiting for table flush,导致所有线程都无法读和写 版本 mydumper 0.9.1OS centos6.6 X86_64mysql 5.6.25- ...

  10. 用count(*)还是count(列名) || Mysql中的count()与sum()区别

    Mysql中的count()与sum()区别   首先创建个表说明问题 CREATE TABLE `result` (   `name` varchar(20) default NULL,   `su ...