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 }
  • 相关阅读:
    tfs2012服务器搭建报表、门户、TFS权限设置
    遥望星空FTP文件同步工具(附源码)1.0 发布
    TortoiseGit连接gitlab,一直要求输入密码
    static、const、readonly与static readonly的区别与联系
    sql server对并发的处理乐观锁和悲观锁
    asp.net控件开发基础系列
    Sonne的健身日志(15)16周腹肌计划第四周感受
    上海新闻!
    Sonne的健身日志(9)16周腹肌计划第一周(2012.3.92012.3.15)
    Sonne的健身日志(5)
  • 原文地址:https://www.cnblogs.com/hellovoidworld/p/4119311.html
Copyright © 2011-2022 走看看