OC1

it2024-10-25  16

// // BankAccount.h // OC1_银行账户类 // // Created by zhangxueming on 15/6/10. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> @interface BankAccount : NSObject { NSString *_account; NSString *_password; float _money; int _year; } //构造方法 - (id)initWithAccount:(NSString *)account andPassword:(NSString *)password; //setter方法 - (void)setAccount:(NSString *)aAccount; - (void)setPassword:(NSString *)aPassword; - (void)setYear:(int)aYear; - (void)setAccount:(NSString *)aAccount andPassword:(NSString *)aPassword; //getter方法 - (NSString *)account; - (NSString *)password; - (float)money; - (int)year; //存款 - (float)saveMoney:(float)aMoney; //取款 - (float)getMoney:(float)aMoney; @end // // BankAccount.m // OC1_银行账户类 // // Created by zhangxueming on 15/6/10. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import "BankAccount.h" @implementation BankAccount //构造方法 - (id)initWithAccount:(NSString *)account andPassword:(NSString *)password { if (self = [super init]) { _account = account; _password = password; } return self; } //setter方法 - (void)setAccount:(NSString *)aAccount { _account = aAccount; } - (void)setPassword:(NSString *)aPassword { _password = aPassword; } - (void)setYear:(int)aYear { _year = aYear; } - (void)setAccount:(NSString *)aAccount andPassword:(NSString *)aPassword { _account = aAccount; _password = aPassword; } //getter方法 - (NSString *)account { return _account; } - (NSString *)password { return _password; } - (float)money { return _money; } - (int)year { return _year; } //存款 - (float)saveMoney:(float)aMoney { return _money+=aMoney; } //取款 - (float)getMoney:(float)aMoney { return _money-=aMoney; } @end // // main.m // OC1_银行账户类 // // Created by zhangxueming on 15/6/10. // Copyright (c) 2015年 zhangxueming. All rights reserved. // #import <Foundation/Foundation.h> #import "BankAccount.h" int main(int argc, const char * argv[]) { @autoreleasepool { BankAccount *bankAccount = [[BankAccount alloc] init]; [bankAccount setAccount:@"13245678" andPassword:@"666666"]; NSLog(@"account = %@ password = %@", [bankAccount account],[bankAccount password]); NSLog(@"money = %.2f", [bankAccount saveMoney:100001001]); NSLog(@"money = %.2f",[bankAccount getMoney:5000]); } return 0; }

 

转载于:https://www.cnblogs.com/0515offer/p/4570076.html

相关资源:数据结构—成绩单生成器
最新回复(0)