Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PRogram 3.2 - simple class
//gcc 4.8.4 #import <stdio.h> #import <Foundation/Foundation.h> // interface: // - basic program-wide definitations // - two instance variables - every instance of Fraction will have a new set of these @interface Fraction : NSObject { int numerator; int denominator; } - (void)showResults; - (void)setNumerator:(int)n; - (void)setDenominator:(int)d; @end // implementation: // - implementation of the methods defined in our interface @implementation Fraction - (void)showResults { NSLog(@"This is a fraction with a value of %d/%d", numerator, denominator); } -(void)setNumerator:(int)n { numerator = n; } -(void)setDenominator:(int)d { denominator = d; } @end // main: // - area where everything is executed int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; // Create an instance of Fraction Fraction *myFraction; myFraction = [[Fraction alloc] init]; // nmyFraction's numerator and denominator [myFraction setNumerator:2]; [myFraction setDenominator:5]; // Display the value of myFraction [myFraction showResults]; // Clear up memory [myFraction release]; [pool drain]; return 0; }
run
|
edit
|
history
|
help
0
Az Flights Optimization
emp class
find maximum in objective c
HAL is IBM
string divison
NSString Examples in one
NSMutable Example
find simple Interest in objective c
geomatric operations in objective c
objective c find factorial