Programming in C

(Barry) #1

416 Chapter 19 Object-Oriented Programming


printf ("The value of the fraction is %i/%i\n", numerator, denominator);
}

@end

//------- program section -------

int main (void)
{
Fraction *myFract;

myFract = [Fraction new];

[myFract setNumerator: 1];
[myFract setDenominator: 3];

printf ("The numerator is %i, and the denominator is %i\n",
[myFract numerator], [myFract denominator]);
[myFract print]; // use the method to display the fraction

[myFract free];

return 0;
}

Program 19.2 Output
The numerator is 1, and the denominator is 3
The value of the fraction is 1/3

As you can see from the comments in Program 19.2, the program is logically divided
into three sections: the @interface section, the @implementation section, and the pro-
gram section.These sections are typically placed in separate files.The @interface section
is usually put into a header file that gets included in any program that wants to work
with that particular class. It tells the compiler what variables and methods are contained
in the class.
The @implementation section contains the actual code that implements these meth-
ods. Finally, the program section contains the program code to carry out the intended
purpose of the program.

Program 19.2 Continued
Free download pdf