All pastes #426123 Raw Edit

Mine

public text v1 · immutable
·published 2007-04-05 22:26 UTC
rendered paste body
-- Employee.h
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>

@interface Employee: NSObject
{
@private
    NSString*	d_lastName_p;
    NSString*	d_firstName_p;
    NSString*	d_position_p;
    float	d_salary;
}

- (id) init;
- (void) dealloc;
+ (id) initWithFirstName:(char*)_first LastName:(char*)_last Position:(char*)_pos Salary:(float)_salary;
- (NSString*) getLastName;
- (NSString*) getFirstName;
- (void) printRecord;

@end

--- employee.m

#import <Foundation/Foundation.h>
#import <Foundation/NSAutoReleasePool.h>
#import "Employee.h"

@implementation Employee


- (id) init
{
	self = [super init];
	return self;
}


- (void) dealloc
{
	[super dealloc];
}


+ (id) initWithFirstName:(char*)_first LastName:(char*)_last Position:(char*)_pos Salary:(float)_salary
{
	Employee* emp = [[Employee alloc] init];
	
	[emp->d_firstName_p release]; emp->d_firstName_p = [NSString stringWithUTF8String: _first];
	[emp->d_lastName_p release]; emp->d_lastName_p = [NSString stringWithUTF8String: _last];
	[emp->d_position_p release]; emp->d_position_p = [NSString stringWithUTF8String: _pos];
	emp->d_salary = _salary;
	
	return emp;
}


- (NSString*) getLastName
{
	return d_lastName_p;
}


- (NSString*) getFirstName
{
	return d_firstName_p;
}


- (void) printRecord
{
	printf("%s:%s:%s:%.2f\n",
		[d_lastName_p cString],
		[d_firstName_p cString],
		[d_position_p cString],
		d_salary);
}

@end


int
main(int argc, char** argv)
{
	NSAutoreleasePool* pool=[[NSAutoreleasePool alloc] init];

	Employee*	emp1 = [Employee init];
	Employee*	emp2 = [Employee initWithFirstName:"John" LastName:"Johnson" Position:"Cashier" Salary:100.00];
	
	printf("Employee 1\n----------\n");
	printf("%s %s\n", [[emp1 getFirstName] cString], [[emp1 getLastName] cString]);
	[emp1 printRecord];

	printf("Employee 2\n----------\n");
	printf("%s %s\n", [[emp2 getFirstName] cString], [[emp2 getLastName] cString]);
	[emp2 printRecord];
	
	[emp1 release];
	[emp2 release];
	
	return 0;
}