close

#import <Foundation/Foundation.h>
#import <stdio.h>

@interface cEmployee : NSObject
{
    NSString *p_strEmploeeName;
    NSInteger p_mSalary;
    NSString *p_strJobPosition;
    NSInteger p_mBonus;
    NSInteger p_mTotalSalary;
}

- (id)initEmployee:(NSString *)strEmploeeName andSalary:(NSInteger)mSalary andJobPosition:(NSString *)strJobPosition andBonus:(NSInteger)mBonus;
- (void)printInfo;
- (void)printBonus;
- (void)printTotalSalary;

@property(nonatomic, readwrite) NSInteger p_mBonus;

@end

@implementation cEmployee

@synthesize p_mBonus; 

    - (id)initEmployee:(NSString *)strEmploeeName andSalary:(NSInteger)mSalary andJobPosition:(NSString *)strJobPosition {
        self = [super init];
        p_strEmploeeName = strEmploeeName;
        p_mSalary = mSalary;
        p_strJobPosition = strJobPosition;
        return self;
    }
    
    - (void)printInfo{
        NSLog(@"Employee Info");
        NSLog(@"Name: %@", p_strEmploeeName);
        NSLog(@"mSalary: %ld", p_mSalary);
        NSLog(@"JobPosition: %@", p_strJobPosition);
        NSLog(@"");
    }
    
    - (void)printBonus{
        NSLog(@"Employee Bonus");
        NSLog(@"Name: %@", p_strEmploeeName);
        NSLog(@"Bonus: %ld", p_mBonus);
        NSLog(@"");
    }
    
    - (void)printTotalSalary{
        NSLog(@"Employee TotalSalary");
        p_mTotalSalary = p_mSalary + p_mBonus;
        NSLog(@"Name: %@", p_strEmploeeName);
        NSLog(@"TotalSalary: %ld", p_mTotalSalary);
        NSLog(@"");
    }    

@end


int main(int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];   
    
    cEmployee *cEmployee1 = [[cEmployee alloc]initEmployee:@"Lei Wei Wei" andSalary:8500 andJobPosition:@"Boss"]; 
    cEmployee1.p_mBonus = 1350;
    
    [cEmployee1 printInfo];
    [cEmployee1 printBonus];
    [cEmployee1 printTotalSalary];

    return 0;
}

Output result: 

2016-10-10 10:05:56.752 a.out[19036] Employee Info
2016-10-10 10:05:56.752 a.out[19036] Name: Lei Wei Wei
2016-10-10 10:05:56.752 a.out[19036] mSalary: 8500
2016-10-10 10:05:56.752 a.out[19036] JobPosition: Boss
2016-10-10 10:05:56.752 a.out[19036] 
2016-10-10 10:05:56.752 a.out[19036] Employee Bonus
2016-10-10 10:05:56.752 a.out[19036] Name: Lei Wei Wei
2016-10-10 10:05:56.752 a.out[19036] Bonus: 1350
2016-10-10 10:05:56.752 a.out[19036] 
2016-10-10 10:05:56.752 a.out[19036] Employee TotalSalary
2016-10-10 10:05:56.753 a.out[19036] Name: Lei Wei Wei
2016-10-10 10:05:56.753 a.out[19036] TotalSalary: 9850
2016-10-10 10:05:56.753 a.out[19036] 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 kk匡 的頭像
    kk匡

    kk匡的日記&學習筆記

    kk匡 發表在 痞客邦 留言(0) 人氣()