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 }
  • 相关阅读:
    Codeforces Round #452 F. Letters Removing
    bzoj 1492: [NOI2007]货币兑换Cash
    bzoj 4016: [FJOI2014]最短路径树问题
    bzoj 2109: [Noi2010]Plane 航空管制
    bzoj 1058: [ZJOI2007]报表统计
    bzoj 1016: [JSOI2008]最小生成树计数
    bzoj 1013: [JSOI2008]球形空间产生器sphere
    bzoj 1758: [Wc2010]重建计划
    bzoj 2337: [HNOI2011]XOR和路径
    一本通1668取石子
  • 原文地址:https://www.cnblogs.com/hellovoidworld/p/4119311.html
Copyright © 2011-2022 走看看