SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  main.m
  3. //  objecttutorial
  4. //
  5. //  Created by Valeriy Filippov on 9/29/11.
  6. //  Copyright 2011 __MyCompanyName__. All rights reserved.
  7. //
  8.  
  9. #import <Foundation/Foundation.h>
  10.  
  11.  
  12. typedef enum{
  13.     kCirce,
  14.     kRectangle,
  15.     kOblateSpheroid
  16. }ShapeType;
  17.  
  18. typedef enum{
  19.     kRedColor,
  20.     kGreenColor,
  21.     kBlueColor
  22. }ShapeColor;
  23.  
  24. typedef struct{
  25.     int x,y,width,height;
  26. }ShapeRect;
  27.  
  28.  
  29. @interface Shape:NSObject{
  30.     ShapeColor color;
  31.     ShapeRect bounds;
  32. }
  33.  
  34. -(void)setFillColor:(ShapeColor)fillColor;
  35. -(void)setBounds:(ShapeRect)bounds;
  36. -(void)draw;
  37. @end
  38.  
  39.  
  40. @interface Circle:Shape
  41.  
  42. @end
  43.  
  44. @interface Triangle : Shape
  45. @end
  46.  
  47. @implementation Shape
  48.  
  49. -(void) setFillColor:(ShapeColor)c{
  50.     color=c;
  51. }
  52.  
  53. -(void)setBounds:(ShapeRect)b{
  54.     bounds=b;
  55. }
  56. -(void)draw{
  57.    
  58. }
  59. @end
  60.  
  61.  
  62. @implementation Circle
  63.  
  64. -(void) setFillColor:(ShapeColor)c{
  65.    
  66.     if (c==kBlueColor){
  67.         c=kRedColor;
  68.     }
  69.     [super setFillColor:<#c#>];
  70. }
  71.  
  72.  
  73. -(void)draw{
  74.     NSLog(@"Рисуем окружность");    
  75. }
  76. @end
  77.  
  78. @implementation Triangle
  79.  
  80. -(void)draw{
  81.     NSLog(@"Рисуем треугольник");    
  82. }
  83. @end
  84.  
  85. int main (int argc, const char * argv[])
  86. {
  87.  
  88.     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  89.  
  90.     // insert code here...
  91.     id shapes[3];
  92.     ShapeRect rect0={20,20,20,20};
  93.     shapes[0]=[Circle new];
  94.     [shapes[0] setBounds:rect0];
  95.     [shapes[0] setFillColor:kRedColor];
  96.    
  97.     ShapeRect rect1;
  98.     shapes[1]= [Triangle new];
  99.     [shapes[1] setBounds:rect1];
  100.     [shapes[1] setFillColor:kBlueColor];
  101.     NSLog(@"Hello world");    
  102.  
  103.     [pool drain];
  104.     return 0;
  105. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top