forked from mouredev/roadmap-retos-programacion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeandroCFD.f90
164 lines (130 loc) · 5.49 KB
/
LeandroCFD.f90
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
module modulo_herencia !Definicion del modulo
implicit none
type :: Animal !Definición de la superclase Animal
character(len=20) :: nombre !Atributos de la clase
character(len=20) :: especie
integer :: edad
contains
procedure :: Sonido !Metodo de la clase
end type Animal
type, extends(Animal) :: Perro !Definición de la subclase Perro utilizando la sentencia extends para heredar de la clase Animal
character(len=20) :: raza !Atributos de la clase
contains
procedure :: Sonido => Ladrar !Sobrecarga del metodo Sonido
end type Perro
type, extends(Animal) :: Gato !Definición de la subclase Gato utilizando la sentencia extends para heredar de la clase Animal
character(len=20) :: raza !Atributos de la clase
contains
procedure :: Sonido => Maullar !Sobrecarga del metodo Sonido
end type Gato
contains
subroutine Sonido(this) !Implementación del metodo Sonido de la clase Animal
class(Animal), intent(in) :: this
print *, 'El animal ', this%nombre,'no hace ningun sonido'
end subroutine Sonido
subroutine Ladrar(this) !Implementación del metodo Sonido de la clase Perro
class(Perro), intent(in) :: this
print *, 'El perro ', this%nombre, 'hace guau'
end subroutine Ladrar
subroutine Maullar(this) !Implementación del metodo Sonido de la clase Gato
class(Gato), intent(in) :: this
print *, 'El gato ', this%nombre, 'hace miau'
end subroutine Maullar
end module modulo_herencia
module Empleados
implicit none
type :: Empleado
character(len=20) :: Nombre
integer :: Identificador
character(len=20), dimension(100) :: Empleados_a_cargo
contains
procedure :: Agregando_Empleado
end type Empleado
type, extends(Empleado) :: Gerente
contains
procedure :: Proyectos
end type Gerente
type, extends(Empleado) :: Gerente_de_proyecto
contains
procedure :: Proyecto
end type Gerente_de_proyecto
type, extends(Empleado) :: Programador
character(len=20) :: Lenguaje
contains
procedure :: Code
procedure :: Agregando_Empleado => Empleados_Programador
end type Programador
contains
subroutine Agregando_Empleado(this, Nombre, Identificador)
class(Empleado), intent(inout) :: this
character(len=20), intent(in) :: Nombre
integer, intent(in) :: Identificador
this%Empleados_a_cargo(Identificador)=Nombre
end subroutine Agregando_Empleado
subroutine Empleados_Programador(this, Nombre, Identificador)
class(Programador), intent(inout) :: this
character(len=20), intent(in) :: Nombre
integer, intent(in) :: Identificador
integer :: i
i=Identificador
print*, "No se puede agregar empleados a cargo de un programador, ", this%Nombre, "no puede estar a cargo de ", Nombre
end subroutine Empleados_Programador
subroutine Proyectos(this)
class(Gerente), intent(in) :: this
print *, 'El gerente ', this%Nombre, 'esta coordinando proyectos'
end subroutine Proyectos
subroutine Proyecto(this)
class(Gerente_de_proyecto), intent(in) :: this
print *, 'El gerente de proyecto ', this%Nombre, 'esta trabajando en su proyecto '
end subroutine Proyecto
subroutine Code(this)
class(Programador), intent(in) :: this
print *, 'El programador ', this%Nombre, 'esta programando en ', this%Lenguaje
end subroutine Code
end module Empleados
program HERENCIA
use modulo_herencia !Se llama a el modulo que contiene las clases
use Empleados
implicit none
integer :: i
type(Animal) :: Mianimal !Se crean objetos de las clases
type(Perro) :: Miperro
type(Gato) :: Migato
type(Gerente) :: MiGerente
type(Gerente_de_proyecto) :: MiGerente_de_proyecto
type(Programador) :: MiProgramador
Mianimal=Animal('Leandro', 'Desconocida', 0) !Se inicializan los objetos
Miperro=Perro('Toby', 'Canino', 5, 'Labrador')
Migato=Gato('Garfield', 'Felino', 3, 'Siames')
call Miperro%Sonido() !Se llama al metodo Sonido de cada objeto
call Migato%Sonido()
call Mianimal%Sonido()
!DIFICULTAD EXTRA
print*, " "
print*, "****************"
print*, "DIFICULTAD EXTRA"
print*, "****************"
print*, " "
MiGerente=Gerente('Juan', 1, '')
MiGerente_de_proyecto=Gerente_de_proyecto('Pedro', 2, '')
MiProgramador=Programador('Luis', 3, '', 'Fortran')
call MiGerente%Proyectos()
call MiGerente_de_proyecto%Proyecto()
call MiProgramador%Code()
call MiGerente%Agregando_Empleado(MiGerente_de_proyecto%Nombre,MiGerente_de_proyecto%Identificador)
call MiGerente%Agregando_Empleado(MiProgramador%Nombre,MiProgramador%Identificador)
call MiGerente_de_proyecto%Agregando_Empleado(MiProgramador%Nombre,MiProgramador%Identificador)
call MiProgramador%Agregando_Empleado(MiGerente%Nombre, MiGerente%Identificador)
print*, "Los empleados a cargo de ", MiGerente%Nombre, "son: "
do i = 1, 100
if (MiGerente%Empleados_a_cargo(i) /= '') then
print*," ", MiGerente%Empleados_a_cargo(i)
end if
end do
print*, "Los empleados a cargo de ", MiGerente_de_proyecto%Nombre, "son: "
do i = 1, 100
if (MiGerente_de_proyecto%Empleados_a_cargo(i) /= '') then
print*," ", MiGerente_de_proyecto%Empleados_a_cargo(i)
end if
end do
end program HERENCIA