// Main. M // helloworld // created by Jimmy. yang on 11-1-24. // copy 2011 _ mycompanyname __. all rights reserved. # import <Foundation/Foundation. h> // define the ry type enumeration typedef Enum {kcircle, krectangle, koblatesshperoid} shapetype; // define the ry color enumeration typedef Enum {kredcolor, kgreencolor, kbluecolor} shapecolor; // defines the "ry rectangular area" structure typedef struct {int X, Y, width, height;} shaperect; // define the ry structure typedef struct {shapetype type; shapecolor fillcolor; shaperect bounds;} shape; // return the nsstring * colorname (shapecolor colorname) of the enumerated color) {Switch (colorname) {Case kredcolor: Return @ "red"; break; Case kgreencolor: Return @ "green"; break; Case kbluecolor: Return @ "blue"; break; default: Return @ "no clue"; break ;}// colorname // draw the void drawcircle (shaperect bounds, shapecolor fillcolor) {nslog (@ "drawing a circle at (% d, % d) in % @", bounds. x, bounds. y, bounds. width, bounds. height, colorname (fillcolor);} // drawcircle // draw a rectangle 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 // draw an oval 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 // draw the geometric shape 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 // masterProgram Entry 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 );}
Running result of the console window:
13:49:05. 978 helloworld [734: a0f] drawing a circle at (,) in red
13:49:06. 016 helloworld [734: a0f] drawing a rectangle at (, 50, 60) in green
13:49:06. 018 helloworld [734: a0f] drawing an egg at (,) in blue