#import <Foundation/Foundation.h>

@interface Shape : NSObject 
{
  CGFloat area;
}
-(void)printArea;
-(void)calculateArea;
@end

@implementation Shape

-(void)printArea {
 NSLog(@"The area is %f",area);
}

-(void)calculateArea {
}

@end


@interface Square : Shape
{
  CGFloat length;
}

-(id)initWithSide : (CGFloat)side;
-(void)calculateArea;

@end


@implementation Square 

-(id)initWithSide : (CGFloat)side {
 length = side;
 return self;
}

-(void)calculateArea {
 area = length * length;
}

-(void)printArea {
 NSLog(@"The area of square is %f", area);
}

@end


@interface Rectangle : Shape 
{
 CGFloat length;
 CGFloat breadth;
}
-(id)initWithLength: (CGFloat)rLen andBreadth:(CGFloat)rBreadth;

@end


@implementation Rectangle

-(id)initWithLength: (CGFloat)rLen andBreadth:(CGFloat)rBreadth {
 length = rLen;
 breadth = rBreadth;
 return self;
}

-(void)calculateArea {
 area = length * breadth;
}

-(void)printArea {
 NSLog(@"The area of Rectangle is %f", area);
}

@end


int main(int ar, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
  Shape *square = [[Square alloc]initWithSide:4.2];
  [square calculateArea];
  [square printArea];
  Shape *rect = [[Rectangle alloc]initWithLength:7.88 andBreadth:6.35];
  [rect calculateArea];
  [rect printArea];
  
  [pool drain];
  return 0;
  
}

 

相关文章:

  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-07-17
  • 2021-08-08
猜你喜欢
  • 2021-09-17
  • 2021-06-17
  • 2021-12-12
  • 2022-03-04
  • 2021-11-09
  • 2022-01-22
相关资源
相似解决方案