Amazon.com Widgets Exercise 6.3
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 12:05:33 PM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 6
| | | |-+  Exercise 6.3
Pages: [1]   Go Down
Print
Author Topic: Exercise 6.3  (Read 369 times)
johnyorke
Newbie
*
Posts: 18


Email




« on: January 19, 2012, 01:46:03 PM »

Code: (Objective-C)
#import <Foundation/Foundation.h>

@interface Fraction: NSObject
{
int numerator, denominator;
   
}

-(void) print;

-(void) setNumerator: (int) n;

-(void) setDenominator: (int) d;

@end


@implementation Fraction

-(void) print
{
    int wholeNumber;
    if (numerator != 0) {
        wholeNumber = numerator / denominator;
        NSLog (@"%i", wholeNumber);}
    else NSLog(@"zero");
}

-(void) setNumerator: (int) n
{
numerator = n;
}

-(void) setDenominator: (int) d
{
denominator = d;
}

@end

int main (int argc, char *argv[])
{
Fraction * myFraction = [[Fraction alloc] init];
   
[myFraction setNumerator: 99];
   
[myFraction setDenominator: 88];
   
    [myFraction print];

return 0;

}
Output:
Quote
2012-01-19 20:45:37.788 exercises[1978:707] 5
Feedback welcome.
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.