A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

这是一朵某某的花,有某某个花瓣,一年几个季度开花,是多少年生的植物

主函数
#import <UIKit/UIKit.h>

#import "ZYAppDelegate.h"
#import "Flower.h"

int main(int argc, char * argv[])
{
    Flower * meiHua = [Flower alloc];
    [ meiHua setAge:2];
    [ meiHua setNum:5];
    [ meiHua setColor: @"红色"];
    [ meiHua setSeason:@"一次"];

    Flower * juHua = [Flower alloc];
    [ juHua setAge:1];
    [ juHua setNum:120];
    [ juHua setColor:@"黄色"];
    [ juHua setSeason:@"十二次"];
    Flower * kele =[Flower alloc];
    [kele setAge:3];
    [kele setNum:6];
    [kele setColor:@"五彩"];
    [kele setSeason:@"常年不败"];

    [kele setAge: 3:6 :@"五彩" :@"常年不败"];
    [meiHua setAge: 2:5 :@"红色" :@"一次"];
    [juHua setAge: 1:120 :@"黄色" :@"十二次"];
    Flower *a=[Flower alloc];
    [a setAge: 4];
    Flower *b=[Flower alloc];
    [b setAge: 120];
    int meihua =[a getAge];
    int juhua =[b getAge];
    if ( meihua < juhua) {
        NSLog(@"梅花的花瓣比菊花的少");

    }else
    {
        NSLog(@"菊花的花瓣比梅花的少");
    }

}


.h文件
#import <Foundation/Foundation.h>

@interface Flower : NSObject

{
    NSString *color;
    NSString *season;
    int age;
    int num;

}
-(void)setAge:(int)aAge;
-(int)getAge;
-(void)setNum:(int)aNum;
-(int)getNum;
-(void)setColor:(NSString*)aColor;
-(NSString*)getColor;
-(void)setSeason:(NSString*)aSeason;
-(NSString*)getSeason;


-(void)setAge:(int)aAge :(int)aNum :(NSString*)aColor :(NSString*)aSeason;
-(void)getAge:(int)aAge :(int)aNum :(NSString*)aColor :
(NSString*)aSeason;




.m文件
#import "Flower.h"

@implementation Flower
-(void)setAge:(int)aAge
{
    age=aAge;
    NSLog(@"这是%d年生的植物",age);
}
-(int)getAge
{

    return age;
}
-(void)setNum:(int)aNum
{
    num=aNum;
    NSLog(@"有%d个花瓣",num);
}
-(int)getNum
{
    return num;
}
-(void)setColor:(NSString *)aColor
{
    color=aColor;
    NSLog(@"这是%@的花",color);
}
-(NSString*)getColor
{
    return color;
}
-(void)setSeason:(NSString *)aSeason{
    season=aSeason;
    NSLog(@"这是一年开%@的花",season);

}
-(NSString*)getSeason
{
    return season;
}
-(void)setAge:(int)aAge :(int)aNum  :(NSString*)aColor  :(NSString*)aSeason
{
    age=aAge;
    num=aNum;
    color=aColor;
    season=aSeason;
    NSLog(@"这是一朵%@的花,有%d花瓣,一年%@开花,%d年生的植物",color,num,season,age);
}
-(void)getFlower
{
    NSLog(@"这是一朵%@的花,有%d花瓣,一年%@开花,%d年生的植物",color,num,season,age);
}
@end


2 个回复

倒序浏览
我也是新人,希望大家多多交流。慢慢成长为大牛。
回复 使用道具 举报
谢谢分享
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马