Beijing Wireless Interconnection Scholarship Article series two--47 flood dream Circle

Source: Internet
Author: User


Xcode-------MAIN.M:

#import <Foundation/Foundation.h>

#import "Person.h"

#import "Dog.h"


int Main (int argc, const Char * argv[]) {

@autoreleasepool {

//dog *dog = [[Dog alloc]initwithname:@ " two ha " withcolor:@ "Red"];

person *pp = [[person alloc]initwithname:@ " Xiao Ming " /c7>];

int time;

NSLog (@ " Please enter time:");

scanf ("%d", &time);

[pp Walkdog: Time];

}

return 0;

}

Xcode-------Person.h:

#import <Foundation/Foundation.h>

#import "Dog.h"

@interface Person: NSObject

{

nsstring *_name;

Dog *_dog;

}

-(ID) initwithname: (nsstring *) name;

-(void) Walkdog: (int) time;


@end



Xcode-------PERSON.M:

#import "Person.h"

#import "Dog.h"


@implementation Person



-(ID) initwithname: (nsstring *) name{

self = [super init];

if ( Self! = Nil) {

_name = name;

_dog = [[dog alloc]initwithname:@ " little white " withcolor:@ " white "];

}

return self;

}


-(void) Walkdog: (int) time{

if (Time = = 9) {

[_dog run];

}

Else if (Time = = 10) {

[_dog pickupball];


}

Else if (Time = = 11) {

[_dog bark];

}

Else {

[_dog sleep];

}

}

@end



Xcode-------Dog.h:

#import <Foundation/Foundation.h>


@interface Dog: nsobject

{

nsstring *_name;

nsstring *_color;

}


// Custom initialization method

-(ID) initwithname: (nsstring *) name Withcolor: (nsstring *) color;


-(void) run;

-(void) Pickupball;

-(void) bark;

-(void) sleep;

@end



Xcode--------DOG.M:

#import "Dog.h"


@implementation Dog


-(ID) initwithname: (nsstring *) name Withcolor: (nsstring *) color{

if ( Self! = Nil) {

self = [super init];

_name = name;

_color = color;

}

return self;

}


-(void) run{

NSLog(@ " run, Little white!") ");

}

-(void) pickupball{

NSLog(@ " dash to pick the ball ~");

}

-(void) bark{

NSLog (@ " no !" ");

}

-(void) sleep{

NSLog(@ "zzz~zz~");

}


@end


Beijing Wireless Interconnection Scholarship Article series two--47 flood dream Circle

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.