Open judaco opened 7 years ago
//
// Rectangle.h
// Inheritance
//
// Created by hackeru on 19/03/2017.
// Copyright © 2017 Juda. All rights reserved.
//
#import <Foundation/Foundation.h>
@class XYPoint; //don't import all the code, just know which the class exists - much more efficiency
@interface Rectangle : NSObject
@property int width, height;
-(int) area;
-(int) perimeter;
-(void) setWidth:(int)w andHeight: (int) h;
-(void) setOrigin: (XYPoint *) o;//setter for XY
-(XYPoint *) origin;//getter for XY
@end
//
// Rectangle.m
// Inheritance
//
// Created by hackeru on 19/03/2017.
// Copyright © 2017 Juda. All rights reserved.
//
#import "Rectangle.h"
@implementation Rectangle
{
XYPoint *origin;
}
@synthesize width, height;
-(void) setWidth:(int)w andHeight:(int)h {
width = w;
height = h;
}
-(int) area {
return width * height;
}
-(int) perimeter {
return 2*(width + height);
}
-(void) setOrigin:(XYPoint *)o {
origin = o;
}
-(XYPoint *) origin {
return origin;
}
@end
//
// Square.h
// Inheritance
//
// Created by hackeru on 19/03/2017.
// Copyright © 2017 Juda. All rights reserved.
//
#import "Rectangle.h"
@interface Square : Rectangle
-(void) setSide: (int) s;
-(int) side;
@end
//
// Square.m
// Inheritance
//
// Created by hackeru on 19/03/2017.
// Copyright © 2017 Juda. All rights reserved.
//
#import "Square.h"
@implementation Square
-(void)setSide:(int)s {
[super setWidth:s andHeight: s];
}
-(int)side {
return self.width;
}
@end
//
// XYPoint.h
// Inheritance
//
// Created by hackeru on 19/03/2017.
// Copyright © 2017 Juda. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface XYPoint : NSObject
@property int x, y;
-(void) setX:(int) xVal andY: (int) yVal;
@end
//
// XYPoint.m
// Inheritance
//
// Created by hackeru on 19/03/2017.
// Copyright © 2017 Juda. All rights reserved.
//
#import "XYPoint.h"
@implementation XYPoint
@synthesize x, y;
-(void)setX:(int)xVal andY:(int)yVal {
x = xVal;
y = yVal;
}
@end