#import <Foundation/Foundation.h>
#import "alipay.h"
#import "ICBC.h"
#import "CBC.h"
/**
* 扣款
*/
int pay(alipay* c){
return [c koukuan];
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
alipay* icbc = [ICBC new];
alipay* cbc = [CBC new];
icbc->_balance = 10000;
cbc->_balance = 5000;
FILE* p1 = fopen("/Users/aionyiruma/Desktop/alipay.txt", "r");
if (p1) {
fread(&icbc->_balance, sizeof(int), 1, p1);
fread(&cbc->_balance, sizeof(int), 1, p1);
fclose(p1);
}
while (1) {
NSLog(@"********欢迎来到支付宝转账系统********");
NSLog(@" 您目前的ICBC账户余额为:%d",icbc->_balance);
NSLog(@" 您目前的 CBC账户余额为:%d",cbc->_balance);
NSLog(@"请您输入您的操作1代表转账,2代表存款 3代表退出");
int cunkuan;
scanf("%d",&cunkuan);
switch (cunkuan) {
//转账
case 1:{
NSLog(@" 请输入您要转账的金额");
int fee ;
scanf("%d",&fee);
NSLog(@" 请您输入付款银行,0代表ICBC,1代表CBC");
int bank;
scanf("%d",&bank);
switch (bank) {
case 0:
icbc->_pay = fee;
icbc->_balance = pay(icbc);
break;
case 1:
cbc->_pay = fee;
cbc->_balance = pay(cbc);
break;
default:
NSLog(@" 输入有误请重新输入,请重新输入");
break;
}
FILE* p2= fopen("/Users/aionyiruma/Desktop/alipay.txt", "w");
if (p2) {
fwrite(&icbc->_balance, sizeof(int), 1, p2);
fwrite(&cbc->_balance, sizeof(int), 1, p2);
fclose(p2);
}
break;
}
//存款
case 2:{
NSLog(@" 请您输入存款银行,0代表ICBC,1代表CBC");
int bank2;
scanf("%d",&bank2);
int money;
NSLog(@" 请输入您要存款的金额");
scanf("%d",&money);
switch (bank2) {
case 0:
icbc->_balance += money;
NSLog(@" 存款成功,余额为%d元",icbc->_balance);
break;
case 1:
cbc->_balance += money;
NSLog(@" 存款成功,余额为%d",cbc->_balance);
break;
default:
NSLog(@" 输入有误,请重新输入");
break;
}
FILE* p2= fopen("/Users/aionyiruma/Desktop/alipay.txt", "w");
if (p2) {
fwrite(&icbc->_balance, sizeof(int), 1, p2);
fwrite(&cbc->_balance, sizeof(int), 1, p2);
fclose(p2);
}
break;
}
//退出
case 3:return 0;
}
}
}
}
#import <Foundation/Foundation.h>
@interface alipay : NSObject{
@public
int _balance;
int _pay;
}
-(int)koukuan;
@end
#import "alipay.h"
@implementation alipay
-(int)koukuan{
return 0;
}
@end
#import "alipay.h"
@interface ICBC : alipay
@end
#import "ICBC.h"
@implementation ICBC
-(int)koukuan{
if (_balance > _pay) {
NSLog(@"支付成功! ICBC银行账户余额%d元,成功扣款%d元,剩余%d元",_balance,_pay,_balance-_pay);
return _balance - _pay;
}else{
NSLog(@"@支付失败,余额不足");
return _balance;
}
}
@end
#import "alipay.h"
@interface CBC : alipay
@end
#import "CBC.h"
@implementation CBC
-(int)koukuan{
if (_balance > _pay) {
NSLog(@"支付成功!CBC银行账户余额%d元,成功扣款%d元,剩余%d元",_balance,_pay,_balance-_pay);
return _balance - _pay;
}else{
NSLog(@"@支付失败,余额不足");
return _balance;
}
}
@end