Ejemplo de una classe
¿Has encontrado un error? ¿Tienes la solución? Deja tu correción ;-)
Antes de comentar: Gran parte de los ejercicios propuestos no tienen librerías debido a que Wordpress las eliminó al verlas como etiquetas HTML.
Si sabes/tienes/conoces las librerías que hacen falta, déjalo en los comentarios. Y lo mas importante: Todos los ejemplos
fueron realizados por estudiante con únicamente conocimiento básico del lenguaje, no de programación.
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 | program Virtual_2;
uses crt;
{$R+}
type
Vehicle = object
Wheels : integer;
Weight : real;
constructor Init(In_Wheels : integer; In_Weight : real); procedure Message; virtual;
end;
Car = object(Vehicle) Passenger_Load : integer;
constructor Init(In_Wheels : integer;
In_Weight : real;
People : integer);
procedure Message; virtual; end;
Truck = Object(Vehicle)
Passenger_Load : integer; Payload : real;
constructor Init(People : integer;
Max_Load : real;
In_Wheels : integer;
In_Weight : real); procedure Message; virtual;
end;
{ ********************* Implementacion ******************** }
constructor Vehicle.Init(In_Wheels : integer; In_Weight : real);
begin
Wheels := In_Wheels;
Weight := In_Weight;
end;
procedure Vehicle.Message;
begin
WriteLn('This message is from the vehicle.');
end;
constructor Car.Init(In_Wheels : integer;
In_Weight : real; People : integer);
begin
Wheels := In_Wheels;
Weight := In_Weight;
Passenger_Load := People; end;
procedure Car.Message;
begin
WriteLn('This message is from the car.'); end;
constructor Truck.Init(People : integer; Max_Load : real;
In_Wheels : integer;
In_Weight : real);
begin
Passenger_Load := People; Payload := Max_Load;
Wheels := In_Wheels;
Weight := In_Weight;
end;
procedure Truck.Message;
begin
WriteLn('This message is from the truck.');
end;
procedure Output_A_Message(VAR Machine : Vehicle);
begin
Write('This is from Output_A_message; '); Machine.Message;
end;
{ ************************ main program ************************** }
var Unicycle : Vehicle;
Sedan : Car;
Semi : Truck;
begin
Unicycle.Init(1, 12.0);
Sedan.Init(4, 2100.0, 5);
Semi.Init(1, 25000.0, 18, 5000.0);
WriteLn;
Unicycle.Message;
Sedan.Message;
Semi.Message;
WriteLn;
Output_A_Message(Unicycle);
Output_A_Message(Sedan);
Output_A_Message(Semi); readkey;
end.
{ Result of execution
This message is from the vehicle.
This message is from the car.This message is from the truck.
This is from Output_A_Message; This message is from the vehicle.
This is from Output_A_Message; This message is from the car.
This is from Output_A_Message; This message is from the truck.
} |
Punto importante: Si vas a sugerir un segmento de código en algún lenguaje debes hacerlo así:
- Si es lenguaje C <code lang="c">Código en C</code>
- Si es lenguaje Pascal <code lang="pascal">Aquí dentro el código de Pascal</code>.
De esta manera el código coloreas el código.
Deja un comentario