Design and implementation of the bus card system for iOS development

Source: Internet
Author: User
Tags ticket

  main.m//  bus-bus/*    bus one card recharge system. There are two functional options. The first type of coin or paper money to    choose to buy tickets, another one card recharge, the value is 20, 50. */#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];//here assigns the value to be 100, causes the program error    //[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{* *    Bus card number    */NSString * _ Numberofcard;        /** Bus Card Storage amount */    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{    /** to record total sales *    / int Countofmoney;        Kindofmoney _money;        } @property int countofmoney;/** print ticket */-(void) sellticket;/** recharge */+ (int) Recharge: (Kindofmoney) kindofmoney;-(int) Recordcounofmony; @end

#import "ChargeMachine.h" @implementation chargemachine@synthesize Countofmoney = _countofmoney;/** print ticket */-(void) sellticket{NSLog (@ "sell a ticket"); /** Recharge */-(void) recharge{NSLog (@ "recharge successfully");}    -(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 (@ "The amount you recharge is $20");        Break            Case kindofmoney50:moneykind = 50;            NSLog (@ "The amount you recharge is $50");            Countofmoney + = money;        Break            Case kindofmoney100:moneykind = 100;            NSLog (@ "The amount you recharge is $100");            Countofmoney + = money;        Break            Case Kindofmoneycoinmoney2:moneykind = 2;            NSLog (@ "You are voting for a coin");            [Machine Sellticket]; BrEak            Case Kindofmoneypapermoney2:moneykind = 2;            NSLog (@ "You are voting for banknotes");            [Machine Sellticket];        Break    Default:break; } return moneykind;}        -(NSString *) description{//After multiple calls how to save the value of a variable?    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{    /** is used to store the variable value of 20 */    KindOfMoney20,        /** Used to store the variable value of 50 */    KindOfMoney50,        /** used to store the variable value of 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


Design and implementation of the bus card system for iOS development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.