Computer Science Canada
Programming C, C++, Java, PHP, Ruby, Turing, VB
Username:
Password:
Register
Wiki
Blog
Search
Turing
Chat Room
Members
[Obj-C] Helpful Links
Index
->
Programming, C++
->
C++ Tutorials
Author
Message
wtd
Posted:
Sun Feb 22, 2004 12:12 am
Post subject: [Obj-C] Helpful Links
The Objective-C Foundation Class are a library of classes and protocols devoid of dependence on either Apple's Cocoa API, or the GNUStep libaries.
http://ofc.sunsite.dk/
The Objective-C FAQ is always a good reference.
ftp://rtfm.mit.edu/pub/faqs/computer-lang/Objective-C/faq
Sponsor
Sponsor
rizzix
Posted:
Sun Feb 22, 2004 8:21 am
Post subject: (No subject)
nice.
got any programs you created in obj-c that you can show us?
wtd
Posted:
Mon Feb 23, 2004 12:42 am
Post subject: (No subject)
Unfortunately no. My recent work has been in C++ and Ruby primarily.
wtd
Posted:
Tue Feb 24, 2004 7:15 pm
Post subject: (No subject)
Saw a thread about a Fraction class in another forum here and thought it might make an educational example.
code:
// import the base class
#import <objc/Object.h>
@interface IntPair : Object
{
@private
int first, second;
}
- initWithFirst: (int) f andSecond: (int) s;
- (int) greater;
- (int) lesser;
- (bool) bothDivisibleBy: (int) t;
- (int) gcd;
- (int) first;
- (int) second;
- (void) first: (int) newValue;
- (void) second: (int) newValue;
- (void) swap;
@end
@interface Fraction : IntPair
- initWithNumerator: (int) initNum andDenominator: (int) initDenom;
- clone;
- (void) invert;
- (void) simplify;
- (int) numerator;
- (int) denominator;
- (void) numerator: (int) newValue;
- (void) denominator: (int) newValue;
- (void) simplifySigns;
- (void) multiplyBothBy: (int) multiplier;
- (int) wholeNumberValue;
- (Fraction *) remainder;
- (Fraction *) multiplyByFraction: (Fraction *) other;
- (Fraction *) multiplyByInt: (int) other;
@end
int main(int argc, char * argv[])
{
Fraction * f = [[Fraction alloc] initWithNumerator: 2 andDenominator: 3];
Fraction * s = [[Fraction alloc] initWithNumerator: 3 andDenominator: 4];
Fraction * r = [f multiplyByFraction: s];
}
@implementation IntPair
- initWithFirst: (int) f andSecond: (int) s
{
[super init];
[self first: f];
[self second: s];
return self;
}
- (int) greater
{
if ([self first] >= [self second])
return [self first];
else
return [self second];
}
- (int) lesser
{
if ([self first] <= [self second])
return [self first];
else
return [self second];
}
- (bool) bothDivisibleBy: (int) t
{
return ([self first] / t == 0 && [self second] / t == 0);
}
- (int) gcd
{
int counter;
for (counter = [self lesser]; counter <
}
- (int) first
{
return first;
}
- (int) second
{
return second;
}
- (void) first: (int) newValue
{
first = newValue;
}
- (void) second: (int) newValue
{
second = newValue;
}
- (void) swap
{
int temp = [self first];
[self first: [self second]];
[self second: temp];
}
@end
@implementation Fraction
- initWithNumerator: (int) initNum andDenominator: (int) initDenom
{
[super initWithFirst: initNum andSecond: initDenom];
[self denominator: initDenom;
num = initNum;
return self;
}
- clone
{
return [[Fraction alloc] initWithNumerator: num andDenominator: denom];
}
- (void) invert
{
[self swap];
}
- (void) simplify
{
}
- (int) numerator {
return [self first];
}
- (int) denominator
{
return [self second];
}
- (void) numerator: (int) newValue
{
[self first: newValue];
}
- (void) denominator: (int) newValue
{
[self second: newValue];
[self simplifySigns];
}
- (void) simplifySigns
{
if ([self denominator] < 0)
[self multiplyBothBy: -1];
}
- (void) multiplyBothBy: (int) multiplier
{
[self first: [self first] * multiplier];
[self second: [self second] * multiplier];
}
- (int) wholeNumberValue
{
return [self numerator] / [self denominator];
}
- (Fraction *) remainder
{
return [[Fraction alloc]
initWithNumerator: [self numerator] % [self denominator]
andDenominator: [self denominator]];
}
- (Fraction *) multiplyByFraction: (Fraction *) other
{
return [[Fraction alloc]
initWithNumerator: [self numerator] * [other numerator]
andDenominator: [self denominator] * [other denominator]];
}
- (Fraction *) multiplyByInt: (int) other
{
return [[Fraction alloc]
initWithNumerator: [self numerator] * other
andDenominator: [self denominator]];
}
@end
rizzix
Posted:
Tue Feb 24, 2004 11:17 pm
Post subject: (No subject)
nice.. thats all that i needed a simple example.
wtd
Posted:
Tue Feb 24, 2004 11:23 pm
Post subject: (No subject)
You're welcome.
I hope all of the syntax there was easy to follow. I didn't get mean and use Protocols, just because it wasn't warranted, though.
Display posts from previous:
All Posts
1 Day
7 Days
2 Weeks
1 Month
3 Months
6 Months
1 Year
Oldest First
Newest First
Index
->
Programming, C++
->
C++ Tutorials
Page
1
of
1
[ 6 Posts ]
Jump to:
Select a forum
CompSci.ca
------------
- Network News
- General Discussion
General Forums
-----------------
- Hello World
- Featured Poll
- Contests
Contest Forums
-----------------
- DWITE
- [FP] Contest 2006/2008
- [FP] 2005/2006 Archive
- [FP] 2004/2005 Archive
- Off Topic
Lounges
---------
- User Lounge
- VIP Lounge
Programming
--------------
- General Programming
General Programming Forums
--------------------------------
- Functional Programming
- Logical Programming
- C
C
--
- C Help
- C Tutorials
- C Submissions
- C++
C++
----
- C++ Help
- C++ Tutorials
- C++ Submissions
- Java
Java
-----
- Java Help
- Java Tutorials
- Java Submissions
- Ruby
Ruby
-----
- Ruby Help
- Ruby Tutorials
- Ruby Submissions
- Turing
Turing
--------
- Turing Help
- Turing Tutorials
- Turing Submissions
- PHP
PHP
----
- PHP Help
- PHP Tutorials
- PHP Submissions
- Python
Python
--------
- Python Help
- Python Tutorials
- Python Submissions
- Visual Basic and Other Basics
VB
---
- Visual Basic Help
- Visual Basic Tutorials
- Visual Basic Submissions
Education
-----------
- Student Life
Graphics and Design
-----------------------
- Web Design
Web Design Forums
---------------------
- (X)HTML Help
- (X)HTML Tutorials
- Flash MX Help
- Flash MX Tutorials
- Graphics
Graphics Forums
------------------
- Photoshop Tutorials
- The Showroom
- 2D Graphics
- 3D Graphics
Teams
------
- dTeam Public
Style:
Appalachia
blueSilver
eMJay
subAppalachia
subBlue
subCanvas
subEmjay
subGrey
subSilver
subVereor
Search:
You can syndicate this boards posts using the file
backend.php
or view the
topic map using sitemap.php.
Terms of Use
|
Privacy Policy