You are on page 1of 8

PROGRAMACION ORIENTADA A OBJETOS

EJERCICIO: HERENCIA Y POLIMORFISMO

A. La clase clsPersona

Public Class clsPersona


Private m_Codigo As String
Private m_FechaNac As Date
Private m_Nombres As String

Sub New(ByVal Cod As String, ByVal Fecha As Date, ByVal Nom As


String)
m_Codigo = Cod
m_FechaNac = Fecha
m_Nombres = Nom
End Sub

Public Property Codigo() As String


Get
Return m_Codigo
End Get
Set(ByVal value As String)
m_Codigo = value
End Set
End Property

Public Property Nombres() As String


Get
Return m_Nombres
End Get
Set(ByVal value As String)
m_Nombres = value
End Set
End Property

End Class

B. La clase clsCliente

Public Class clsCliente


Inherits clsPersona
Private m_Credito As Double
Private m_Empresa As String
Private m_RUC As String

Sub New(ByVal Cod As String, ByVal Fecha As Date, ByVal Nom As


String, _
ByVal Cre As Double, ByVal Emp As String, ByVal R As
String)
MyBase.New(Cod, Fecha, Nom)
m_Credito = Cre
m_Empresa = Emp

1
m_RUC = R
End Sub

Public Property Empresa() As String


Get
Return m_Empresa
End Get
Set(ByVal value As String)
m_Empresa = value
End Set
End Property
End Class

C. La clase clsEmpleado

Public Class clsEmpleado


Inherits clsPersona
Private m_Comision As Double
Private m_HoraEntrada As Date
Private m_HoraSalida As Date
Private m_SueldoBasico As Double

Sub New(ByVal Cod As String, ByVal Fecha As Date, ByVal Nom As


String, _
ByVal Com As Double, ByVal HE As Date, ByVal HS As Date,
ByVal SB As Double)
MyBase.New(Cod, Fecha, Nom)
m_Comision = Com
m_HoraEntrada = HE
m_HoraSalida = HS
m_SueldoBasico = SB
End Sub

Public Property Sueldo() As Double


Get
Return m_SueldoBasico
End Get
Set(ByVal value As Double)
m_SueldoBasico = value
End Set
End Property
End Class

D. La clase clsLista

Public Class clsLista


Private m_Total As Integer
Private m_Datos() As clsPersona

Public Sub Agregar(ByVal obj As clsPersona)


ReDim Preserve m_Datos(m_Total)
m_Datos(m_Total) = obj
m_Total = m_Total + 1

2
End Sub

Public Function Buscar(ByVal Cod As String) As clsPersona


Dim obj As clsPersona

For Each obj In m_Datos


If obj.Codigo = Cod Then
Return obj
End If
Next
Return Nothing
End Function

Public Function BuscarPosicion(ByVal Cod As String) As Integer


Dim obj As clsPersona
Dim i As Integer

i = 0
For Each obj In m_Datos
If obj.Codigo = Cod Then
Return i
End If
i = i + 1
Next
Return Nothing
End Function

Public ReadOnly Property getPersona(ByVal Pos As Integer) As


clsPersona
Get
Return m_Datos(Pos)
End Get
End Property

Public ReadOnly Property Datos() As clsPersona()


Get
Return m_Datos
End Get
End Property
End Class

E. Ventana de men de opciones

F. Formulario frmAgregarPersona

3
Imports LibreriaHerencia

Public Class frmAgregarPersona

Private Sub rbtCliente_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles rbtCliente.CheckedChanged
gbEmpleado.Visible = False
gbCliente.Visible = True
End Sub

Private Sub rbtEmpleado_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles rbtEmpleado.CheckedChanged
gbEmpleado.Visible = True
gbCliente.Visible = False
End Sub

Private Sub btnRegistrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnRegistrar.Click
Dim obj As clsPersona

If rbtCliente.Checked Then
obj = New clsCliente(txtCodigo.Text, dtpFecha.Value, txtNombres.Text, _
CDbl(txtCredito.Text), txtEmpresa.Text, txtRUC.Text)
Else
obj = New clsEmpleado(txtCodigo.Text, dtpFecha.Value, txtNombres.Text, _
CDbl(txtComision.Text), dtpHoraEntrada.Value, _
dtpHoraSalida.Value, CDbl(txtSueldo.Text))
End If
Lista.Agregar(obj)
MsgBox("Registro con exito", MsgBoxStyle.Information)
End Sub

End Class

G. Formulario frmBuscarPersona

4
Imports LibreriaHerencia

Public Class frmBuscarPersona

Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnBuscar.Click
Dim obj As clsPersona
Dim Pos As Integer

Pos = Lista.BuscarPosicion(txtCodigo.Text)
obj = Lista.getPersona(Pos)
If Not obj Is Nothing Then
If TypeOf obj Is clsCliente Then
gbCliente.Visible = True
gbEmpleado.Visible = False
rbtCliente.Checked = True
txtEmpresa.Text = CType(obj, clsCliente).Empresa
Else
gbCliente.Visible = False
gbEmpleado.Visible = True
rbtEmpleado.Checked = True
txtSueldo.Text = CType(obj, clsEmpleado).Sueldo.ToString
End If
End If
End Sub
End Class

H. Formulario frmListadoPorTipos

5
Imports LibreriaHerencia

Public Class frmListadoPorTipos

Private Sub cmbTipo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles cmbTipo.SelectedIndexChanged
Dim obj As clsPersona
Dim Cad As String

lstDatos.Items.Clear()
If cmbTipo.Text = "Cliente" Then
For Each obj In Lista.Datos
If TypeOf obj Is clsCliente Then
Cad = CType(obj, clsCliente).Codigo & " - " & CType(obj, clsCliente).Nombres & _
" - " & CType(obj, clsCliente).Empresa
lstDatos.Items.Add(Cad)
End If
Next
Else
For Each obj In Lista.Datos
If TypeOf obj Is clsEmpleado Then
Cad = CType(obj, clsEmpleado).Codigo & " - " & CType(obj, clsEmpleado).Nombres & _
" - " & CType(obj, clsEmpleado).Sueldo
lstDatos.Items.Add(Cad)
End If
Next
End If
End Sub
End Class

I. Formulario frmModificar

6
Imports LibreriaHerencia

Public Class frmModificar


Dim obj As clsPersona
Dim Pos As Integer

Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnBuscar.Click
Pos = Lista.BuscarPosicion(txtCodigo.Text)
obj = Lista.getPersona(Pos)
If Not obj Is Nothing Then
txtCodigo.Enabled = False
gbTipo.Enabled = False
If TypeOf obj Is clsCliente Then
gbCliente.Visible = True
gbEmpleado.Visible = False
rbtCliente.Checked = True
txtEmpresa.Text = CType(obj, clsCliente).Empresa
Else
gbCliente.Visible = False
gbEmpleado.Visible = True
rbtEmpleado.Checked = True
txtSueldo.Text = CType(obj, clsEmpleado).Sueldo.ToString
End If
End If
End Sub

Private Sub btnModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles btnModificar.Click
If Not obj Is Nothing Then
If TypeOf obj Is clsCliente Then
CType(obj, clsCliente).Empresa = txtEmpresa.Text
Else
CType(obj, clsEmpleado).Sueldo = CDbl(txtSueldo.Text)
End If

7
Lista.Datos(Pos) = obj
End If
End Sub
End Class

J. Modulo modBasico

Imports LibreriaHerencia

Module modBasico
Public Lista As New clsLista
End Module

You might also like