Guest User

Untitled

a guest
Mar 30th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #import <Foundation/Foundation.h>
  3.  
  4. @interface Rectangle: NSObject
  5.  
  6. {
  7.     int width;
  8.     int height;
  9. }
  10.  
  11. -(void) setWidth: (int) w;
  12. -(void) setHeight: (int) h;
  13. -(void) width;
  14. -(void) height;
  15. -(void) area;
  16. -(void) perimeter;
  17.  
  18. @end
  19.  
  20. @implementation Rectangle
  21.  
  22. -(void) setWidth:(int) w
  23. {
  24.     w = width;
  25. }
  26.  
  27. -(void) setHeight:(int) h
  28. {
  29.     h = height;
  30. }
  31. -(void) width
  32. {
  33.     NSLog(@"Width is %d", width);
  34. }
  35.  
  36. -(void) height
  37. {
  38.     NSLog(@"Height is %d", height);
  39. }
  40.  
  41. -(void) area
  42. {
  43.     NSLog(@"Area is %d", width*height);
  44. }
  45.  
  46. -(void) perimeter
  47. {
  48.     int w = (width+height)*2;
  49.     NSLog(@"Area is %i", w);
  50. }
  51.  
  52. @end
  53.  
  54. int main(int argc, const char * argv[]) {
  55.     @autoreleasepool {
  56.         Rectangle *rectangleOne = [[Rectangle alloc] init];
  57.         [rectangleOne setHeight:10];
  58.         [rectangleOne setWidth:5];
  59.         [rectangleOne height];
  60.         [rectangleOne width];
  61.         [rectangleOne perimeter];
  62.         [rectangleOne area];
  63.     }
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment