Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Foundation/Foundation.h>
- @interface Rectangle: NSObject
- {
- int width;
- int height;
- }
- -(void) setWidth: (int) w;
- -(void) setHeight: (int) h;
- -(void) width;
- -(void) height;
- -(void) area;
- -(void) perimeter;
- @end
- @implementation Rectangle
- -(void) setWidth:(int) w
- {
- w = width;
- }
- -(void) setHeight:(int) h
- {
- h = height;
- }
- -(void) width
- {
- NSLog(@"Width is %d", width);
- }
- -(void) height
- {
- NSLog(@"Height is %d", height);
- }
- -(void) area
- {
- NSLog(@"Area is %d", width*height);
- }
- -(void) perimeter
- {
- int w = (width+height)*2;
- NSLog(@"Area is %i", w);
- }
- @end
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- Rectangle *rectangleOne = [[Rectangle alloc] init];
- [rectangleOne setHeight:10];
- [rectangleOne setWidth:5];
- [rectangleOne height];
- [rectangleOne width];
- [rectangleOne perimeter];
- [rectangleOne area];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment