- Joined
- Feb 21, 2011
- Messages
- 22
- Reaction score
- 0
- Points
- 1
- Your Mac's Specs
- Macbook Air 11", 64 GB, Intel core i5, 1.6 GHz, OSX Lion 10.7
Hello,
i just wrote a code to perform mathematical operations. the interface, implementation and main sections are written in the same file. after building and running, the code shows the following error.
Fraction.h no such file or directory
cannot find interface declaration for fraction
I tried to remove these errors by writing interface file again but its of no use. plz go through the code and let me know my mistake
Here's the code...
i just wrote a code to perform mathematical operations. the interface, implementation and main sections are written in the same file. after building and running, the code shows the following error.
Fraction.h no such file or directory
cannot find interface declaration for fraction
I tried to remove these errors by writing interface file again but its of no use. plz go through the code and let me know my mistake
Here's the code...
Code:
#import "Fraction.h"
@interface Fraction (MathOps)
-(Fraction *) add: (Fraction *) f;
-(Fraction *) mul: (Fraction *) f;
-(Fraction *) sub: (Fraction *) f;
-(Fraction *) div: (Fraction *) f;
@end
@implementation Fraction (MathOps)
-(Fraction *) add: (Fraction *) f
{
// To add two fractions;
// a/b + c/d = ((a*d) + (b*c)) / (b*d)
Fraction *result = [[Fraction alloc] init];
int resultNum, resultDenom;
resultNum = (numerator * f.denominator) + (denominator * f.numerator);
resultDenom = denominator * f.denominator;
[result setTo: resultNum over: resultDenom];
[result reduce];
return result;
}
-(Fraction *) sub: (Fraction *) f
{
// To sub two fractions:
// a/b - c/d = ((a*d) - (b*c)) / (b*d)
Fraction *result = [[Fraction alloc] init];
int resultNum, resultDenom;
resultNum = (numerator * f.denominator) - (denominator * f.numerator);
resultDenom = denominator * f.denominator;
[result setTo: resultNum over: resultDenom];
[result reduce];
return result;
}
-(Fraction *) mul: (Fraction *) f
{
Fraction *result = [[Fraction alloc] init];
[result setTo: numerator * f.numerator over: denominator * f.denominator];
[result reduce];
return result;
}
-(Fraction *) div: (Fraction *) f
{
Fraction *result = [[Fraction alloc] init];
[result setTo: numerator * f.denominator over: denominator * f.numerator];
[result reduce];
return result;
}
@end
int main (int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Fraction *a = [[Fraction alloc] init];
Fraction *b = [[Fraction alloc] init];
Fraction *result;
[a setTo: 1 over: 3];
[b setTo: 2 over: 5];
[a print];
NSLog (@" +");
[b print];
NSLog (@"-----");
result = [a add: b];
[result print];
NSLog (@"\n");
[result release];
[a print];
NSLog (@" -");
[b print];
NSLog (@"-----");
result = [a sub: b];
[result print];
NSLog (@"\n");
[result release];
[a print];
NSLog (@" *");
[b print];
NSLog (@"-----");
result = [a mul: b];
[result print];
NSLog (@"\n");
[result release];
[a print];
NSLog (@" /");
[b print];
NSLog (@"-----");
result = [a div: b];
[result print];
NSLog (@"\n");
[result release];
[a release];
[b release];
[pool drain];
return 0;
}