Created
December 8, 2008 21:57
-
-
Save bryanwoods/33635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// prog1 | |
// | |
// Created by Bryan Woods on 12/8/08. | |
// Copyright __MyCompanyName__ 2008. All rights reserved. | |
// | |
#import <stdio.h> | |
#import <objc/Object.h> | |
@interface Fraction: Object | |
{ | |
int numerator; | |
int denominator; | |
} | |
-(void) print; | |
-(void) setNumerator: (int) n; | |
-(void) setDenominator: (int) d; | |
@end | |
@implementation Fraction; | |
-(void) print | |
{ | |
printf(" %i/%i ", numerator, denominator); | |
} | |
-(void) setNumerator: (int) n | |
{ | |
numerator = n; | |
} | |
-(void) setDenominator: (int) d | |
{ | |
denominator = d; | |
} | |
@end | |
int main (int argc, char *argv[]) | |
{ | |
Fraction *myFraction; | |
// Create an instance of a Fraction | |
myFraction = [Fraction alloc]; | |
myFraction = [myFraction init]; | |
//Set fraction to 1/3 | |
[myFraction setNumerator: 1]; | |
[myFraction setDenominator: 3]; | |
// Display the fraction using the print method | |
printf("The value of myFraction is:"); | |
[myFraction print]; | |
printf("\n"); | |
[myFraction free]; | |
return 0; | |
// ZOMGZ a fuckload of code to print a fraction | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment