Listings, my first go at this language apart from Cocoa. Interested to note other peoples experience as PC rather than MAC users.
-----------------------------------------------------------
*(Integer.h)
#import
@interface Integer: Object{int integer;
}
-(int) integer;-(id) integer: (int) -integer;
@end
*(Integer.m)
#import "Integer.h"
@implementation Integer
-(int) integer
{
return integer;
}
-(id) integer:(int) integer{
integer
=_integer;return self;
}
@end
*(arithmetic.h)
#import "Integer.h"
@interface Integer
(arithmetic)
-(id) add:(Integer *) addend;
-(id) sub:(Integer *) subtrahend;
@end
*(arithmetic.m)
#import "arithmetic.h"
@implementation Integer (Arithmetic)
- (id) add: (Integer *) addend{
return [self integer: [self integer]
+ [addend integer]];
} - (id) sub: (Integer *) subtrahend{
return [self integer: [self integer] - [subtrahend
integer]];
}@end
*(display.h)
#import "Integer.h"
@interface
Integer (Display)
- (id)
showstars;
- (id) showint;
@end
*(display.m)
#import "Display.h"
@implementation Integer (Display)
- (id) showstars{
int i, x = [self integer];
for(i=0; i <>
printf("\n");
return
self;
}
- (id)
showint{
printf("%d\n", [self
integer]);
return self;
}
@end
*(main.m)
#import "Integer.h"
#import "arithmetic.h"
#import "display.h"
intmain(void){
Integer *num1 =
[Integer new], *num2 = [Integer new];
int x;
printf("Enter an
integer: ");
scanf("%d", &x);
[num1 integer:x];
[num1 showstars];
printf("Enter an integer: ");
scanf("%d", &x);
[num2
integer:x];
[num2 showstars];
[num1 add:num2];
[num1 showint];
return 0;
}
No comments:
Post a Comment