zoukankan      html  css  js  c++  java
  • [Objective-c 基础

    1 #import <Foundation/Foundation.h>
      2 
      3 typedef enum {GenderMan, GenderFemale} Gender;
      4 
      5 typedef enum {ColorRed, ColorBlue, ColorGreen} Color;
      6 
      7 typedef struct
      8 {
      9     int year;
     10     int month;
     11     int day;
     12 } Date;
     13 
     14 
     15 @interface Dog : NSObject
     16 {
     17 @public
     18     float weight;
     19     Color color;
     20 }
     21 - (void) eat;
     22 - (void) run;
     23 
     24 @end
     25 
     26 
     27 @interface Student : NSObject
     28 {
     29     @public
     30     char *name;
     31     Gender gender;
     32     Date birthday;
     33     double weight;
     34     Color favariteColor;
     35     Dog *dog;
     36 }
     37 
     38 - (void) eat;
     39 - (void) run;
     40 - (void) walkDog;
     41 - (void) feedDog;
     42 - (void) print;
     43 
     44 @end
     45 
     46 @implementation Student
     47 - (void) eat
     48 {
     49     weight++;
     50     NSLog(@"吃吃吃,体重增加了1KG, 现在体重是%f", weight);
     51 }
     52 
     53 - (void) run
     54 {
     55     weight--;
     56     NSLog(@"跑跑跑,体重减去了1KG,现在体重是%f", weight);
     57 }
     58 
     59 - (void) print
     60 {
     61     NSLog(@"这个学生的资料-》姓名:%s, 性别:%d, 生日:%d-%d-%d, 体重:%f, 喜爱的颜色:%d", name, gender, birthday.year, birthday.month, birthday.day, weight, favariteColor);
     62 }
     63 
     64 - (void) walkDog
     65 {
     66     [dog run];
     67 }
     68 
     69 - (void) feedDog
     70 {
     71     [dog eat];
     72 }
     73 @end
     74 
     75 
     76 @implementation Dog
     77 - (void) eat
     78 {
     79     NSLog(@"喂狗啦!!!");
     80     weight++;
     81     NSLog(@"狗狗吃吃吃,体重增加了1KG, 现在体重是%f", weight);
     82 }
     83 
     84 - (void) run
     85 {
     86     NSLog(@"遛狗啦!!!!");
     87     weight--;
     88     NSLog(@"狗狗跑跑跑,体重减去了1KG,现在体重是%f", weight);
     89 }
     90 @end
     91 
     92 int main()
     93 {
     94     Student *stu = [Student new];
     95     stu->name = "Jack";
     96     stu->gender = GenderMan;
     97     Date d = {1989, 8, 10};
     98     stu->birthday = d;
     99     stu->weight = 50;
    100     stu->favariteColor = ColorRed;
    101    
    102     Dog *dog = [Dog new];
    103     stu->dog = dog;
    104    
    105     [stu eat];
    106     [stu feedDog];
    107     [stu print];
    108     [stu walkDog];
    109     [stu feedDog];
    110    
    111     return 0;
    112 }
    复制代码

     

    如果一件事情你觉得难的完不成,你可以把它分为若干步,并不断寻找合适的方法。最后你发现你会是个超人。不要给自己找麻烦,但遇到麻烦绝不怕,更不要退缩。 电工查找电路不通点的最快方法是:分段诊断排除,快速定位。你有什么启示吗? 求知若饥,虚心若愚。 当你对一个事情掌控不足的时候,你需要做的就是“梳理”,并制定相应的规章制度,并使资源各司其职。
  • 相关阅读:
    [置顶] android ListView包含Checkbox滑动时状态改变
    Xamarin Android Gestures详解
    尝试在条件“$(_DeviceSdkVersion) >= 21”中对计算结果为“”而不是数字的“$(_DeviceSdkVersion)
    Xamarin Android自定义文本框
    C#四种深拷贝方法(转载)
    设置pictureBox的边框颜色(转载)
    C# 在运行中拖拽,改变控件大小位置类(转载)
    Ocelot + Consul的demo(二)集群部署
    Objective-C 简介
    计算机网络—概述
  • 原文地址:https://www.cnblogs.com/wvqusrtg/p/4501371.html
Copyright © 2011-2022 走看看