Total Pageviews

Friday 28 June 2013

Define a new class called Rectangle having width and height. Develop the methods to set rectangle's width and height. Retrieve these values and calculate area of the rectangle and perimeter. Using interface and implementation.

made an Xcode Program and write a code into .h file

#import <Foundation/Foundation.h>
@interface rectangle:NSObject
{
    float l,w;
    float area,per;
}

-(void)calculate;
         
@end


@implementation rectangle

-(void)calculate;
{

    printf("Enter the 2 values for each side of the rectangle:\n");
    scanf("%f%f",&l,&w);
   
    area=l*w;
    per=2*(l+w);
    printf("Area of Rectangle is:%f\n",area);
    printf("\nPerimeter of Rectangle is:%f",per);
   
   
}

@end


int main (int argc, const char * argv[])
{

    rectangle *rec=[[rectangle alloc]init];
    [rec calculate];
    return 0;

}

No comments:

Post a Comment