انجمن ویکی قلم‌های فارسی
ورود / عضویت

شروع oop Objective C Programming

محلی برای نرم افزارهای سایت ساز و مباحث مربوط به برنامه‌نویسی چون Objective-C ،Cocoa و غیره

شروع oop Objective C Programming

پستتوسط pouyan_objc » 27 آوریل 2010, 20:32

امید وارم در ‍‍‍‍پیشرفت کرده باشید
this is our first O,really Object Oriented Programming(oop program :
hope to enjoy
!) 
کد: انتخاب همهٔ
#import <Foundation/Foundation.h>

// Interface Section Starts Here

@interface BankAccount: NSObject
{
        double accountBalance;
        long accountNumber;
}
-(void) setAccount: (long) y andBalance: (double) x;
-(double) getAccountBalance;
-(long) getAccountNumber;
-(void) setAccountBalance: (double) x;
-(void) setAccountNumber: (long) y;
-(void) displayAccountInfo;
@end


// Implementation Section Starts Here

@implementation BankAccount

-(void) setAccount: (long) y andBalance: (double) x;
{
        accountBalance = x;
        accountNumber = y;
}

-(void) setAccountBalance: (double) x
{
        accountBalance = x;
}

-(double) getAccountBalance
{
        return accountBalance;
}

-(void) setAccountNumber: (long) y
{
        accountNumber = y;
}

-(long) getAccountNumber
{
        return accountNumber;
}


-(void) displayAccountInfo
{
        NSLog (@"Account Number %i has a balance of %f", accountNumber, accountBalance);
}
@end

// Program Section Starts Here

int main (int argc, const char * argv[])
{
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        BankAccount *account1;

        account1 = [BankAccount alloc];

        account1 = [account1 init];

        [account1 setAccountBalance: 1500.53];
        [account1 setAccountNumber: 34543212];

        [account1 displayAccountInfo];

        [account1 setAccount: 4543455 andBalance: 3010.10];

        NSLog(@"Number = %i, Balance = %f", [account1 getAccountNumber], [account1 getAccountBalance]);

        [pool drain];

        return 0;


}


description :
Declaring an Objective-C Class Interface
کد: انتخاب همهٔ
@interface NewClassName: ParentClass {
ClassMembers;
}

ClassMethods;
@end


Declaring an Objective-C Class Implementation
کد: انتخاب همهٔ
@implementation NewClassName
ClassMethods
@end


any problem mail me at :
kalakbarghi@gmail.com
kalakbarghi@gmail.com
MacBook Pro MB/LA991
iPod touch 8 GIG
نماد کاربر
pouyan_objc
 
پست‌ها : 26
تاریخ عضویت: 25 آوریل 2010, 20:16
محل سکونت: Tehran


بازگشت به برنامه‌نویسی


کاربران حاضر در این انجمن: بدون کاربران آنلاین و 4 مهمان