main Lesson5 Created by Admin on 15 02 15 Copyright 2015 Andrei Poliak

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// main.m
// Lesson5
//
// Created by Admin on 15.02.15.
// Copyright (c) 2015 Andrei Poliakov. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "CreatureProtocol.h"
#import "APCreature.h"
#import "APDog.h"
#import "APHuman.h"
#import "APMan.h"
#import "APWoman.h"
typedef enum{
_man,
_woman,
_dog
}creature;
APCreature* getRandomCreature(){
APCreature *creature = [[APCreature alloc] init];
switch (rand()%3+0) {
case 0:
creature = [APMan ManWithAge:10 name:@"VASYA"];
break;
case 1:
creature = [APWoman WomanWithAge:10 name:@"KATYA"];
break;
case 2:
creature = [APDog DogWithAge:10 name:@"SHARIK"];
break;
default:
break;
}
return creature;
}
int main(int argc, const char * argv[]) {
id<CreatureProtocol> vasya = [APMan ManWithAge:19 name:@"Vasya"];
NSLog(@"%@", [vasya creatureInfo]);
for (int i = 0; i < 5; i++) {
vasya = getRandomCreature();
NSLog(@"%@", [vasya creatureInfo]);
}
return 0;
}