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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 | program poo_animal;
uses crt;
{$R+}
type
generos = (macho,hembra);
tipos =(herbiboro,carnivoro,carronero);
Animal = object
sexo : generos; nomb : string[20];
peso : real;
tipo : tipos;
edad : integer;
constructor Nacer(in_sexo : generos; In_peso : real;in_edad : integer;in_nombre:string); procedure mensaje; virtual;
procedure comer; virtual;
procedure caminar;virtual;
end;
Mamifero = object(Animal)
constructor Nacer(in_sexo : generos; In_peso : real;in_edad : integer;in_nombre:string;in_tipo:tipos);
procedure mensaje; virtual;
procedure correr;virtual;
procedure cazar;virtual; procedure saltar;virtual;
end;
Ave = Object(Animal) constructor Nacer(in_sexo : generos; In_peso : real;in_edad : integer;in_nombre:string;in_tipo:tipos);
procedure mensaje; virtual;
procedure volar;virtual;
end;
{ ********************* Implementacion ******************** }
Function evaluaTipo(in_tipo:tipos):string;
begin
if in_tipo=herbiboro then evaluaTipo := 'herbÃÂboro';
if in_tipo=carnivoro then
evaluaTipo:='carnivoro';
if in_tipo=carronero then
evaluaTipo := 'carronero';
end;
Function evaluaGenero(in_Genero:generos):string;
begin
if in_Genero=Macho then evaluaGenero := 'Macho'
else
evaluaGenero := 'Hembra';
end; constructor Animal.Nacer(in_sexo : generos; In_peso : real;in_edad : integer;in_nombre:string);
begin
sexo := in_sexo;
nomb := in_nombre;
peso := In_peso; edad := in_edad;
writeln ('Animal creado; nombre: ', nomb);
end;
procedure Animal.mensaje; begin
WriteLn(nomb, ' es un animal de ',edad,' años y pesa ',peso,' kg.');
end;
procedure Animal.comer;
begin WriteLn(nomb, ' esta comiendo');
end;
procedure Animal.caminar;
begin
WriteLn(nomb, ' esta caminando'); end;
constructor Mamifero.Nacer(in_sexo : generos; In_peso : real;in_edad : integer;in_nombre:string;in_tipo:tipos);
begin
sexo := in_sexo; nomb := in_nombre;
peso := In_peso;
edad := in_edad;
tipo := in_tipo;
writeln ('Mamifero creado; nombre: ', nomb); end;
procedure Mamifero.mensaje;
begin
WriteLn(nomb, ' es un mamifero ',evaluaTipo(tipo),'; un ', evaluaGenero(sexo),' de ',edad,' años y pesa ',peso,' kg.');
end; procedure Mamifero.cazar;
begin
WriteLn(nomb, ' esta cazando');
end;
procedure Mamifero.correr; begin
WriteLn(nomb, ' esta corriendo');
end;
procedure Mamifero.saltar;
begin Write(nomb,' esta saltando');
end;
constructor Ave.Nacer(in_sexo : generos; In_peso : real;in_edad : integer;in_nombre:string;in_tipo:tipos);
begin
sexo := in_sexo; nomb := in_nombre;
peso := In_peso;
edad := in_edad;
tipo := in_tipo;
write ('Ave creada; nombre: ', nomb); end;
procedure Ave.mensaje;
begin
WriteLn(nomb, ' es una ave ',evaluaTipo(tipo),'; un ', evaluaGenero(sexo),' de ',edad,' años y pesa ',peso,' kg.');
end; procedure Ave.volar;
begin
WriteLn(nomb, ' esta volando');
end;
procedure alerta(VAR especie : animal);
begin
especie.Mensaje;
end;
{ ************************ principal ************************** }
var Delfin : Animal;
Tigre : Mamifero; Canario : Ave;
begin
clrscr; Delfin.Nacer(macho,50.2,3,'Delfin');
Tigre.Nacer(macho, 50.2,3,'Tigre',carnivoro);
Canario.Nacer(hembra, 0.25,1,'Canario',herbiboro);
WriteLn;
WriteLn; alerta(Delfin);
Delfin.comer;
alerta(Tigre);
Tigre.cazar;
alerta(Canario); Canario.volar;
readkey;
end. |
Luis
0000-00-00 00:00:00
HOLA MUY BUENO EL APORTE CON OBJETOS EN PASCAL. TE PIDO UN FAVOR, SI TENES ALGO CON LISTAS O REGISTROS HECHOS CON OBJETOS TE AGRADECERIA O HACER UN OBJETO EN UNA UNIDAD Y DESPUES IMPLEMENTARLO EN ALGUN PROGRAMA. MUCHAS GRACIAS, SEGUI ASI : )