下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
//// main.m// Bus-公交/* 公交一卡通充值系统,有两种功能选择,第一种投入硬币或者纸币 选择购票,第二种一卡通充值,充值面额是20,50,100 */#import <Foundation/Foundation.h>#import "Card.h"#import "ChargeMachine.h"#import "Money.h"int main(int argc,const char * argv[]){ ChargeMachine * machine = [[ChargeMachine alloc]init]; //[machine sellTicket]; //[ChargeMachine recharge:KindOfMoney100];//这里赋值的时候赋值成为100,导致程序出错 //[ChargeMachine recharge:KindOfMoney20]; [ChargeMachine recharge:KindOfMoney50]; [ChargeMachine recharge:KindOfMoneyCoinMoney2]; //[machine recharge:KindOfMoneyCoinMoney2]; NSLog(@"%@",machine); return 0;}
#import <Foundation/Foundation.h>#import "Money.h"@interface Card : NSObject{ /*公交卡卡编号*/ Nsstring * _numberOfCard; /**公交卡存放金额*/ int MoneyOfCard; }@property Nsstring * numberOfCard;@property int MoneyOfCard;@end
#import "Card.h"@implementation Card@synthesize numberOfCard = _numberOfCard ;@synthesize MoneyOfCard = _MoneyOfCard;@end
#import <Foundation/Foundation.h>#import "Money.h"@interface ChargeMachine : NSObject{ /**用来记录销售总量*/ int countOfMoney; KindOfMoney _money; }@property int countOfMoney;/**打印票据*/-(voID)sellTicket;/**充值*/+(int)recharge:(KindOfMoney)kindOfMoney;-(int)recordcounOfMony;@end
#import "ChargeMachine.h"@implementation ChargeMachine@synthesize countOfMoney = _countOfMoney;/**打印票据*/-(voID)sellTicket{ NSLog(@"卖出一张车票");}/**充值*/-(voID)recharge{ NSLog(@"充值成功");}-(int)recordcounOfMony{ _countOfMoney += _money; return _countOfMoney;}+(int)recharge:(KindOfMoney)kindOfMoney{ ChargeMachine * machine = [[ChargeMachine alloc]init]; int moneyKind = 0; //int countOfMoney = 0; switch (kindOfMoney) { case KindOfMoney20: moneyKind = 20; //countOfMoney += money; NSLog(@"您充值的金额是20元"); break; case KindOfMoney50: moneyKind = 50; NSLog(@"您充值的金额是50元"); //countOfMoney += money; break; case KindOfMoney100: moneyKind = 100; NSLog(@"您充值的金额是100元"); //countOfMoney += money; break; case KindOfMoneyCoinMoney2: moneyKind = 2; NSLog(@"您投的是硬币"); [machine sellTicket]; break; case KindOfMoneyPaperMoney2: moneyKind = 2; NSLog(@"您投的是纸币"); [machine sellTicket]; break; default: break; } return moneyKind;}-(Nsstring *)description{ //经过多次调用怎样保存一个变量的值? //ChargeMachine * machine = [[ChargeMachine alloc]init]; //int moneyKind = [ChargeMachine recharge:_money]; //int countOf_Money = [ChargeMachine recharge:_money]; return [Nsstring stringWithFormat:@"%d",_money];}@end
#import <Foundation/Foundation.h>enum KindOfMoney{ /**用来存储充值面额为20的变量*/ KindOfMoney20,/**用来存储充值面额为50的变量*/ KindOfMoney50,/**用来存储充值面额为100的变量*/ KindOfMoney100,KindOfMoneyCoinMoney2,KindOfMoneyPaperMoney2};typedef enum KindOfMoney KindOfMoney;@interface Money : NSObject{ KindOfMoney _kindOfMoney;}-(Money*)initWithKindOfMoney:(KindOfMoney)kindOfMoney;typedef enum KindOfMoney KindOfMoney;@end
#import "Money.h"@implementation Money{ }-(Money*)initWithKindOfMoney:(KindOfMoney)kindOfMoney{ self = [super init]; if (self!=nil) { _kindOfMoney = kindOfMoney; } return self;}@end
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的ios开发之公交卡系统的设计与实现全部内容,希望文章能够帮你解决ios开发之公交卡系统的设计与实现所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)