Hello world of objective-C!

Source: Internet
Author: User

// 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.