zoukankan      html  css  js  c++  java
  • OC1_银行账户类

    //
    //  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;
    }
  • 相关阅读:
    普通文本(.txt)篇章排版样式参考 [文档说明][日志]
    C++基础练习案例
    Markdown 编写技巧汇总(二)
    Markdown 编写技巧汇总(一)
    有关C++程序设计基础的各种考题解答参考汇总
    有关算法与数据结构的考题解答参考汇总 [C++] [链表] · 第三篇
    有关算法与数据结构的考题解答参考汇总 [C++] [链表] · 第二篇
    有关算法与数据结构的考题解答参考汇总 [C++] [链表]
    DOS批处理小案例应用分享
    基于Processing图像序列处理保存导出的流程梳理
  • 原文地址:https://www.cnblogs.com/0515offer/p/4570076.html
Copyright © 2011-2022 走看看