Objective C: main.m

//
//  main.m
//  shape6
// Like shape6 java example, shows simple Objective C class syntax
//

#import <Foundation/Foundation.h>
#import "MyRect.h"
#import "Circle.h"


// Just a main program for testing our objects
int main(int argc, const char * argv[]) {
    /*
	 * Data definitions
	 */
	MyRect *r1, *r2;
	Circle *c1;
    
	/*
	 * Instantiate and initialize the objects
	 * (could have done in defs above)
	 */
	r1 = [[MyRect alloc] init: 10 y:10 wid:50 ht:50];
	r2 = [[MyRect alloc] init: 80 y:10 wid:10 ht:100];
	c1 = [[Circle alloc] init: 35 y:90 rad:10];
    
	/*
	 * "Draw" them
	 */
	[r1 draw];
	[r2 draw];
	[c1 draw];
    
	/*
	 * Compute and print total area
	 */
	printf ("Total area = %f\n", ([r1 area] + [r2 area] + [c1 area]));
}

[download file]