• objectiveC 的Hello World!


    //  main.m
    //  HelloWorld
    //  Created by jimmy.yang on 11-1-24.
    //  Copyright 2011 __MyCompanyName__. All rights reserved.
    
    #import <Foundation/Foundation.h>
    
    //定义“几何形状类型”枚举
    typedef enum{
    	kCircle,
    	kRectangle,
    	kOblatesShperoid	
    } 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){
    	switch (colorName) {
    		case kRedColor:
    			return @"red";
    			break;
    		case kGreenColor:
    			return @"green";
    			break;	
    		case kBlueColor:
    			return @"blue";
    			break;	
    		default:
    			return @"no clue";
    			break;
    	}
    }//colorName
    
    //画圆
    void drawCircle(ShapeRect bounds,ShapeColor fillColor){
    	NSLog(@"drawing a circle at (%d,%d,%d,%d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colorName(fillColor));
    }//drawCircle
    
    //画矩形
    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));
    }//drawRectangle
    
    //画椭圆形
    void drawEgg(ShapeRect bounds,ShapeColor fillColor){
    	NSLog(@"drawing an egg at (%d,%d,%d,%d) in %@",bounds.x,bounds.y,bounds.width,bounds.height,colorName(fillColor));
    }//drawEgg
    
    //画几何形状
    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:
    				drawRectangle(shapes[i].bounds,shapes[i].fillColor);
    				break;
    			case kOblatesShperoid:
    				drawEgg(shapes[i].bounds,shapes[i].fillColor);
    				break;
    			default:
    				break;
    		}
    	}
    }//drawShapes
    
    
    //主程序入口
    int main(int argc, 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,39};
    	shapes[2].type = kOblatesShperoid;
    	shapes[2].fillColor = kBlueColor;
    	shapes[2].bounds = rect2;	
    	
    	drawShapes(shapes, 3);
    	
    	return (0);
    }
    

    Console窗口的运行结果:

    2011-01-25 13:49:05.978 HelloWorld[734:a0f] drawing a circle at (0,0,10,30) in red
    2011-01-25 13:49:06.016 HelloWorld[734:a0f] drawing a rectangle at (30,40,50,60) in green
    2011-01-25 13:49:06.018 HelloWorld[734:a0f] drawing an egg at (15,18,37,39) in blue

    作者:菩提树下的杨过
    出处:http://yjmyzz.cnblogs.com
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    毕业设计预习:SM3密码杂凑算法基础学习
    毕业设计预习:maxplus2入门教程
    毕业设计预习:VHDL入门知识学习(一) VHDL程序基本结构
    网络对抗课题4.3.1 SQL注入原理与实践
    20135319zl内核模块编译报告
    20135319zl字符集报告
    20135319zl elf文件报告
    20135319zl软件破解报告
    linux内核分析综合总结
    Linux内核分析期中总结
  • 原文地址:https://www.cnblogs.com/yjmyzz/p/1944536.html
Copyright © 2020-2023  润新知