document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Program to work with fractions - class version                                                                            
  2.  
  3. #import <Foundation/Foundation.h>
  4.  
  5. //---- @interface section ----                                                                                              
  6.  
  7. @interface Fraction: NSObject
  8. {
  9.   int numerator;
  10.   int denominator;
  11. }
  12.  
  13. -(void) print;
  14. -(void) setNumberator: (int) n;
  15. -(void) setDenominator: (int) d;
  16.  
  17. @end
  18.  
  19. //----@implementation section ----                                                                                          
  20. -(void) print
  21. {
  22.   NSLog(@"%i/%i", numerator, denominator);
  23. }
  24.  
  25. -(void) setNumerator: (int) n
  26. {
  27.   numerator = n;
  28. }
  29.  
  30. -(void) setDenominator: (int) d
  31. {
  32.   denominator = d;
  33. }
  34. @end
  35.  
  36.  
  37. //----program section ----                                                                                                  
  38.  
  39. int main (int argc, const char * argv[]) {
  40.  
  41.   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  42.   Fraction *myFraction;
  43.  
  44.   // Create an instance of a Fraction                                                                                        
  45.  
  46.   myFraction = [Fraction alloc];
  47.   myFraction = [myFraction init];
  48.  
  49.   //Set fraction to 1/3                                                                                                      
  50.   [myFraction setNumerator: 1 ];
  51.   [myFraction setDenominator: 3];
  52.  
  53.   //Display the fraction using the print method                                                                              
  54.  
  55.   NSLog (@"The value of myFraction is: ");
  56.   [myFraction print];
  57.   [myFraction release];
  58.   [pool drain];
  59.   return 0;
  60.  
  61. }
');