close

/*
cFullTimeStaff繼承cEmployee。
cFullTimeStaff和cEmployee各自有interface。
cFullTimeStaff多了p_mEmployeeWelfare、全职員工褔利。和printWelfare、列印全职員工褔利功能。
*/

#import <Foundation/Foundation.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;
- (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 
    {
        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


@interface cFullTimeStaff : cEmployee
{
    NSInteger p_mEmployeeWelfare;
}
- (id)initFullTimeStaff:(NSString *)strEmploeeName andWelfare:(NSInteger)mEmployeeWelfare;
- (void) printWelfare;


@property(nonatomic, readwrite) NSInteger p_mEmployeeWelfare;
@end


@implementation cFullTimeStaff

    @synthesize p_mEmployeeWelfare; 

    - (id)initFullTimeStaff:(NSString *)strEmploeeName andWelfare:(NSInteger)mEmployeeWelfare
    {
        p_strEmploeeName = strEmploeeName;
        p_mEmployeeWelfare = mEmployeeWelfare;
        return self;
    }
    
    - (void)printWelfare {
        NSLog(@"Employee Welfare");
        NSLog(@"Name: %@", p_strEmploeeName);
        NSLog(@"Welfare: %ld", p_mEmployeeWelfare);
    }
@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];

    
    cFullTimeStaff *cFullTimeStaff1 = [[cFullTimeStaff alloc]initFullTimeStaff:@"Jian Yun Tian" andWelfare: 4300]; 
    [cFullTimeStaff1 printWelfare];        

    return 0;
}

 

Output result: 

2016-10-10 11:54:26.615 a.out[15172] Employee Info
2016-10-10 11:54:26.616 a.out[15172] Name: Lei Wei Wei
2016-10-10 11:54:26.616 a.out[15172] mSalary: 8500
2016-10-10 11:54:26.616 a.out[15172] JobPosition: Boss
2016-10-10 11:54:26.616 a.out[15172] 
2016-10-10 11:54:26.616 a.out[15172] Employee Bonus
2016-10-10 11:54:26.616 a.out[15172] Name: Lei Wei Wei
2016-10-10 11:54:26.616 a.out[15172] Bonus: 1350
2016-10-10 11:54:26.616 a.out[15172] 
2016-10-10 11:54:26.616 a.out[15172] Employee TotalSalary
2016-10-10 11:54:26.616 a.out[15172] Name: Lei Wei Wei
2016-10-10 11:54:26.616 a.out[15172] TotalSalary: 9850
2016-10-10 11:54:26.616 a.out[15172] 
2016-10-10 11:54:26.616 a.out[15172] Employee Welfare
2016-10-10 11:54:26.616 a.out[15172] Name: Jian Yun Tian
2016-10-10 11:54:26.616 a.out[15172] Welfare: 4300

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

    kk匡的日記&學習筆記

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