You are on page 1of 102

qwertyuiopasdfghjklzxcvbnmqw

ertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmqwertyuiopa
Portafolio
Desarrollo de Aplicaciones
sdfghjklzxcvbnmqwertyuiopasdf
Emmanuel Quiroz Reyes
ghjklzxcvbnmqwertyuiopasdfghj
klzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnmqw
ertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmqwertyuiopa
sdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghj
klzxcvbnmqwertyuiopasdfghjklzx
3G

ndice
Introduccin....1
Prctica 1: Hipotenusa2 4
Prctica 2: rea y Permetro.5 8
Prctica 3: Invertir, Multiplicar e Invertir..9 14
Prctica 4: Suma y Resta.15 17
Prctica 5: Venta producto...18 20
Prctica 6: Nmeros primos.21 - 24
Prctica 7: Nmeros Pares e Impares25 - 28
Prctica 8: Controles..29 - 37
Prctica 9: Mostrar Mayores y Eliminar..38 - 42
Prctica 10: Desviacin Estndar y Varianza43 46
Unidad 2...47
Prctica 11:

Arreglo de objetos Ventas.48 - 57

Prctica 12: Programa de Herencia (Cajero y Vendedor)58 - 64


Prctica 13: Herencia, Ejecutivo y Secretaria.....65 68
Prctica 14: Herencia 5..69 - 77
Prctica 15: Excepciones....78 87
Prctica 16: Control de Empleado.85 95
Conclusin.96

Introduccin
En este documento se encontrara todo lo relacionado a lo visto en el primer parcial.
2

En cada programa se estar explicando la Problemtica: que tiene cada ejercicio, as


como su Diagrama de clases correspondientemente, ya que nos permite visualizar en ella
la clase, junto a sus mtodos y atributos.
Su Cdigo de la clase: nos permitir saber l como ya aadir lo establecido en el
Diagrama de clases, as como los atributos correspondientes a la Problemtica: del
programa y los mtodos que sern importantes para poder plasmar y satisfacer el
paradigma que muestra el programa.
El Cdigo del formulario: es nuevo para el alumnado ya que estamos interactuando con la
interfaz que un usuario puede manejar, es por ello que en el documento se muestra el
cdigo para poder llamar a nuestra clase y manipular a nuestra conveniencia, para poner
en funcionamiento la aplicacin
Y por ltimo se mostrara los pantallazos de las aplicaciones, para demostrar el resultado
de cada Problemtica: (aplicacin)

Prctica 1: Hipotenusa
Problemtica:
3

En este programa se est solicitando sacar la hipotenusa de un tringulo solicitando los


datos de Cateto A y Cateto B.
Diagrama de clase

Cdigo de la clase:
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace hipo
{
classTRIANGULO
{
privatedouble ca_A, ca_B;
publicdouble Cateto_1
{
get { return ca_A; }
set { ca_A = value; }
}
publicdouble Cateto_2
{
get { return ca_B; }
set { ca_B = value; }
}
public TRIANGULO()
{
ca_A = 0;
ca_B = 0;
}
public TRIANGULO(double cA,double cB)
{
ca_A = cA;
ca_B = cB;
}

publicdouble Calcular_Hipotenusa()
{
double c_A = Math.Pow(ca_A, 2);
double c_B = Math.Pow(ca_B, 2);
double sum = c_A + c_B;
double hipo = Math.Sqrt(sum);
return hipo;
}
}
}

Cdigo del formulario:


using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;

namespace hipo
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
privatevoid button1_Click_1(object sender, EventArgs e)
{
TRIANGULO T_hipo = newTRIANGULO();
T_hipo.Cateto_1 = Convert.ToDouble(txtCateA.Text);
T_hipo.Cateto_2 = Convert.ToDouble(txtCateB.Text);
lblResultado.Text = " El resultado de la hipotenusa es: " + T_hipo.Calcular_Hipotenusa();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
}
}

Impresin del formulario resuelto

Prctica 2: rea y Permetro

Problemtica:
En este programa se est solicitando sacar el rea y permetro de un cuadrado, circulo y
triangulo, solicitando al usuario los datos en el tringulo la base y la altura, en el cuadrado
el lado y en el crculo el radio

Diagrama de clase

Cdigo de la clase:
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Figuras
{
publicclassTRIANGULO
{
privatedouble bas, altura;
publicdouble Bas
{
get{return bas;}
set{bas = value;}
}
publicdouble Altura
{

get { return altura; }


set { altura = value; }
}
public TRIANGULO()
{
bas = 0;
altura = 0;
}
public TRIANGULO (double b, double h)
{
bas = b;
altura = h;
}
publicdouble Area_Triangulo ()
{
return (bas * altura) / 2;
}
publicdouble Perimetro_Triangulo()
{
return bas * 3;
}
}
publicclassCUADRADO
{
privatedouble lado;
publicdouble Lado
{
get { return lado; }
set { lado = value; }
}
public CUADRADO()
{
lado = 0;
}
public CUADRADO(double la)
{
lado = la;
}
publicdouble Area_Cuadrado()
{
return lado * lado;
}
publicdouble Perimetro_Cuadrado()
{
return lado * 4;
}
}

Cdigo del formulario:


using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
Figuras;

namespace Form_figuras
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
privatevoid label1_Click(object sender, EventArgs e)
{
}
privatevoid btnCalcular_Click(object sender, EventArgs e)
{
TRIANGULO objetT = newTRIANGULO();
CUADRADO objetCC = newCUADRADO();
CIRCULO objetCir = newCIRCULO();
objetT.Bas = Convert.ToDouble(txtBase.Text);
objetT.Altura = Convert.ToDouble(txtAltura.Text);
objetCC.Lado = Convert.ToDouble(txtLado.Text);
objetCir.Radio = Convert.ToDouble(txtRadio.Text);
lblResultadosT.Text = "El area del Triangulo es: " + objetT.Area_Triangulo() + "\n Y el
Perimetro es: " + objetT.Perimetro_Triangulo();
lblResultadosC.Text = "El area del Cuadrado es: " + objetCC.Area_Cuadrado() + "\n Y
el Perimetro es: " + objetCC.Perimetro_Cuadrado();
lblResultadosCir.Text = "El area del Circulo es: " + objetCir.Area_Circulo() + "\n Y el
Perimetro es: " + objetCir.Perimetro_Circulo();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
}
}
}

Impresin del formulario resuelto

10

Prctica 3: Invertir, Multiplicar e Invertir

Problemtica:
Realizar un programa, el cual tenga la funcin de que el usuario pueda ingresar un arreglo
de n cantidad de nmeros, con los cuales podr realizar las siguientes funciones: Invertir,
Multiplicar y Convertir

Diagrama de clases

Cdigo de la clase:
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Numeros_conertir_multiplicar_invertir
{
publicclassNUMEROS
{

11

privateint[] a;
int pos, tam;
publicint[] A
{
get { return a; }
}
publicint Posicion
{
get { return pos; }
}
public NUMEROS()
{
a = newint[5];
tam = 5;
}
public NUMEROS(int t)
{
a = newint[t];
tam = t;
}
publicString Llenar(int x)
{
String mensaje="";
if (pos < tam)
{
a[pos] = x;
pos++;
}
else
mensaje = " Te has pasado!! ";
return mensaje;
}
publicint[] Invertir()
{
int[] Inver = newint[tam];
int w = pos-1;
for (int m = 0; m < pos; m++)
{
Invertiir[m] = a[w];
w--;
}
return Invertiir;
}
publicint[] Multiplicar()
{
int[] Mul = newint[tam];
for (int p = 0; p < pos; p++)
Mul[p]=5 * a[p];
return Mul;
}
publicint[] Convertir()
{
int mod;
int[]convert = newint[tam];
for (int s = 0; s < pos; s++)
{

12

mod = a[s] % 2;
if (mod == 0)
{
convert[s] = 0;
}
else
if (mod == 1)
{
convert [s] = 1;
}
}
returnconvert;
}
}

Cdigo del formulario:


using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
Numeros_conertir_multiplicar_invertir;

namespaceFormulario_Numeros
{
publicpartialclassfmrNumeros : Form
{
NUMEROS N_objeto;
public fmrNumeros()
{
InitializeComponent();
}
privatevoid btnLlenar_Click(object sender, EventArgs e)
{
if (txtNumero1.Text == "")
MessageBox.Show(" Debes Ingresar algo primero ");
else
{
String m = N_objeto.Llenar(Convert.ToInt32(txtNumero1.Text));
if (m == "")
{
lstNumero1.Items.Add(txtNumero1.Text);
}
else
MessageBox.Show(m);
txtNumero1.Text = "";
txtNumero1.Focus();

13

privatevoid btnInvertir_Click(object sender, EventArgs e)


{
lstResultado.Items.Clear();
int[] r = newint[N_objeto.Posicion];
r = N_objeto.Invertir();
for (int i = 0; i < N_objeto.Posicion; i++)
lstResultado.Items.Add(r[i]);
}
privatevoid cmbTamao_SelectedIndexChanged(object sender, EventArgs e)
{
N_objeto = newNUMEROS(Convert.ToInt32(cmbTamao.Text));
}
privatevoid btnMutiplicar_Click(object sender, EventArgs e)
{
lstResultado.Items.Clear();
int[] r = newint[N_objeto.Posicion];
r=N_objeto.Multiplicar();
for (int i = 0; i < N_objeto.Posicion; i++)
lstResultado.Items.Add(r[i]);
}
privatevoid btnConvertir_Click(object sender, EventArgs e)
{
lstResultado.Items.Clear();
int[] r = newint[N_objeto.Posicion];
r = N_objeto.Convertir();
for (int i = 0; i < N_objeto.Posicion; i++)
lstResultado.Items.Add(r[i]);
}
privatevoid fmrNumeros_Load_1(object sender, EventArgs e)
{
for (int i = 1; i <= 30; i++)
cmbTamao.Items.Add(i);
}
}
}

14

Impresin del formulario resuelto


(Invertir)

(Multiplicar)

15

(Convertir)

16

Prctica 4: Suma y Resta


Problemtica::
Realizar un programa, el cual tenga la funcin de que el usuario pueda ingresar 2
nmeros, con los cuales podr realizar las siguientes funciones: Suma y Resta, mostrado
en la pantalla el resultado de las operaciones de ambos nmeros.

Diagrama de clase:

17

Cdigo de la clase:
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Operaciones
{
classNUMEROS
{
privatedouble num1;
privatedouble num2;
publicdouble Numero_1
{
get { return num1; }
set { num1 = value; }
}
publicdouble Numero_2
{
get { return num2; }
set { num2 = value; }
}
public NUMEROS()
{
num1 = 0;
num2 = 0;
}
public NUMEROS(double n1, double n2)
{
num1 = n1;
num2 = n2;
}
publicdouble Suma()
{

18

double suma = 0;
suma = num1 + num2;
return suma;
}
publicdouble Resta()
{
return num1 - num2;
}
}
}

Cdigo del formulario:


using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
Numeros;

namespace Operaciones
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
privatevoid btnCalcular_Click(object sender, EventArgs e)
{
NUMERITOS NU_oper = new NUMERITOS();
NU_oper.Numero_1 = Convert.ToDouble(txtNumero1.Text);
NU_oper.Numero_2 = Convert.ToDouble(txtNumero2.Text);
lblResultado.Text = " El resultado de la suma es: " + NU_oper.Suma() + "\n El
resultado de la resta es: " + NU_oper.Resta();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(" BIENVENIDO, OPRIME ACEPTAR PARA CONTINUAR... ");
}
}
}

Impresin del formulario resuelto

19

Prctica 5: Venta producto


Problemtica:
Realizar un programa, el cual tenga la funcin de que el usuario pueda ingresar la
descripcin y el precio de un producto, con los cuales podr realizar la siguiente funcin:
Mostrar a pantalla la descripcin de producto y el monto total a pagar.

Diagrama de clases:
20

Cdigo de la clase:
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Clase_ventas
{
public class Ventas
{
private String descripcion;
private double costo;
//Propiedad
public String Descripcion
{
get { return descripcion; }
set { descripcion = value; }
}
public double Costo
{
get { return costo; }
set { costo = value; }
}
//Constructor
public Ventas()
{
descripcion = "";
costo = 0;
}
public Ventas(String d, double c)
{
descripcion = d;

21

costo = c;

//Metodos
public double precio_venta()
{
return costo + costo * 1.2 + costo * 0.15;
}
}

Cdigo del formulario:


using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
Clase_ventas;

namespace Prueba_ventas
{
public partial class rfmVentas : Form
{
public rfmVentas()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnCalcular_Click(object sender, EventArgs e)
{
Ventas objeto = new Ventas();
objeto.Descripcion = txtDescripcion.Text;
objeto.Costo = Convert.ToDouble(txtCosto.Text);
MessageBox.Show(" El producto " + objeto.Descripcion + " Tiene un costo de: " +
objeto.precio_venta(),"Ventana de
resultados",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
}
}
}

22

Impresin del formulario resuelto

Prctica 6: Nmeros primos


Problemtica:
Realizar un programa, el cual tenga la funcin de que el usuario pueda ingresar el arreglo
de n nmeros con lo cual podr realizar la siguiente funcin: Mostrar en un listBox todos
los nmeros ingresados por el usuario y en otro listBox colocar solamente los nmeros
primos, de los nmeros anteriormente agregados.
23

Diagrama de clase:

Cdigo de la clase:
using System;
usingSystem.Collections.Generic;
using System.Linq;
using System.Text;
namespaceClase_Primos
{
publicclassPrimos
{
privateint[] N;
int pos = 0, tam;
publicint[] Num
{
get { return N; }
}
publicint Pos
{
get { return pos; }
}
public Primos()
{
N = newint[5];
tam = 5;
}
public Primos(int t)

24

{
}

N = newint[t];
tam = t;

publicString Llenar(int n)
{
String mensaje = "";
if (pos < tam)
{
N[pos] = n;
pos++;
}
else mensaje = "Arreglo lleno";
return mensaje;
}
publicString[] Es_primo()
{
Boolean Es_primo=false;
String[] res = newString[pos];
//Recorrer el numero de arreglo
for (int i = 0; i < pos; i++)
{
//Para contar los residuos
for (int j = 2; j < N[i]; j++)
{
if (N[i] % j == 0)
Es_primo = true;
}
if (Es_primo == true)
res[i] = "No es un nmero primo";
else
res[i] = " Es un nmero primo";
}
return res;
}
}

Cdigo del formulario:


using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;

25

using
using
using
using

System.Linq;
System.Text;
System.Windows.Forms;
Numeros_Primos;

namespace Numeros_Primos
{
publicpartialclassForm1 : Form
{
Numeros_Primos
public Form1()
{
InitializeComponent();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
}
privatevoid cmbTamao_SelectedIndexChanged(object sender, EventArgs e)
{
objeto=new Numeros_Primos(Covert.ToInt32(cmbTamao)
}
privatevoid btnLlamar_Click(object sender, EventArgs e)
{
if (txtNumero.Text=="")
MessageBox.Show("Escribe algo")
else
{
String m=objeto.Llenar(Convert.ToInt32(
if (m=="")
{
lstNumeros.Items.Add(txtNumero.Text);
txtNumero.Text="";
txtNumero.Focus();
}
}
}
privatevoid btnPrimos_Click(object sender, EventArgs e)
{
String[]tem=newString [objeto.Pos];
temp=objeto.Es_primo();
lstResultado.Items
for (int i=0; i<objeto.Pos;i++);

Impresin del formulario resuelto


26

Prctica 7: Nmeros Pares e Impares


Problemtica:

27

Realizar un programa, el cual tenga la funcin de que el usuario pueda ingresar en un


arreglo de n nmeros, con lo cual podr realizar la siguiente funcin: Mostrar en un listBox
todos los nmeros ingresados por el usuario y en otro listBox colocar solamente los
nmeros pares o impares.

Diagrama de clase:

Cdigo de la clase:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace Clase_Numeros._._.par_e_imprar
{
public class Numero
{
private int[] num;
private int pos = 0, tam;
//Propiedad
public int[] Num
{
get { return num; }
}
public int Pos
{
get { return pos; }

28

}
public Numero()
{
num = new int[10];
tam = 10;
}
//inicializar
public Numero(int t)
{
num = new int[t];
tam = t;
}
//Metodos
public String Llenar(int x)
{
String m = "";
if (pos < tam)
{
//llenar el arreglo de num
Num[pos] = x;
pos++;
}
else
m = "Arreglo lleno";
return m;
}
public int[] Pares()
{
int j = 0;
int[] par = new int[pos];
for (int i = 0; i < pos; i++)
{
if (num[i] % 2 == 0)
{
par[j] = num[i];
j++;
}
}
return par;
}
public int[] Impares()
{
int j = 0;
int[] impar = new int[pos];
for (int i = 0; i < pos; i++)
{
if (num[i] % 2 != 0)
{
impar[j] = num[i];
j++;
}
}
return impar;

29

Cdigo del formulario:


using
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;
Clase_Numeros._._.par_e_imprar;

namespace Formulario_Numero_pares_e_impares
{
public partial class Form1 : Form
{
Numero obj;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Inicializar Arreglos
for (int i=1 ; i<31;i++)
{
cmbTamao.Items.Add(i);
}
}
private void cmbTamao_SelectedIndexChanged(object sender, EventArgs e)
{
// Covertir...obj=new Numero(cmbTamao.Text)
obj = new Numero(Convert.ToInt32(cmbTamao.Text));
}
private void btnLlenar_Click(object sender, EventArgs e)
{

String m = obj.Llenar(Convert.ToInt32(txtLlenar.Text));
if (m == "")
lstLlenar.Items.Add(txtLlenar.Text);
else
MessageBox.Show(m);

30

private void btnPar_Click(object sender, EventArgs e)


{
lstResultado.Items.Clear();
int [] temp=new int [obj.Pos];
temp = obj.Pares();
//vaciar en el listbox uno por uno
for (int i = 0; i < obj.Pos; i++)
lstResultado.Items.Add(temp[i]);
//Ya no te ponen los ceros en el formulario
if (temp[i]!=0)
lstResultado.Items.Add(temp[i]);
}
private void btnImpar_Click(object sender, EventArgs e)
{
lstResultado.Items.Clear();
int[] temp = new int[obj.Pos];
temp = obj.Impares();
//vaciar en el listbox uno por uno
for (int i=0; i < obj.Pos; i++)
lstResultado.Items.Add(temp[i]);
//Ya no te ponen los ceros en el formulario
if (temp [i]!=0)
lstResultado.Items.Add(temp[i]);
}

Impresin del formulario resuelto:

Prctica 8: Controles

31

Problemtica:
Realizar un programa de controles, el cual tenga la funcin de poder enlazar Formularios;
en el primer formulario realizar la funcin de que el usurario pueda ingresar una cantidad
de elementos y colocarlos en un listado para que posteriormente cuando se seleccione un
elemento del listado pueda dar, Cul es el elemento actual? Cul es su posicin
actual? Y Cul es el total de elementos agregados? En el segundo formulario poder
saber el Seno, Coseno y la Tangente con solo seleccionar ngulo. En el Tercer Formulario
poder seleccionar el color en una base determinada y ponerla en un ancho y altura que se
desea y Finalmente en el cuarto formulario tener una suma de vectores en dos diferentes
listBox para solo generarlos en un solo y tercer listBox.

Diagrama de clases:

Cdigo de la clase:
32

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceClase_suma
{
publicclassVec_Suma
{
privateint[] a, b;
intpos = 0, tam;
publicint[] A
{
get { return a; }
}
publicint[] B
{
get { return b; }
}
publicintPos
{
get { returnpos; }
}
publicVec_Suma()
{
a = newint[5];
b = newint[5];
tam = 5;
}
publicVec_Suma(int t)
{
a = newint[t];
b = newint[t];
tam = t;
}
publicStringllenar(int x, int y)
{
Stringmensaje="";
if (pos< tam)
{
a[pos] = x;
b[pos] = y;
pos++;
}
else
mensaje = "Error!! Te pasaste!!";
returnmensaje;
}
publicint[] Suma()
{
int[] Res = newint[tam];
for (int i = 0; i <pos; i++)
Res[i] = a[i] + b[i];
return Res;
}
}

33

Cdigo del formulario:


1)- Agregar elementos:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace controles_2
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
privatevoidbtnAgregar_Click(object sender, EventArgs e)
{
if (txtNuevo.Text == "")
MessageBox.Show("El nuevo elemento no puede estar vacio");
else
{
lstListado.Items.Add(txtNuevo.Text);
lblTotal.Text = Convert.ToString(lstListado.Items.Count);
txtNuevo.SelectAll();
txtNuevo.Focus();
}
}
privatevoidlstListado_SelectedIndexChanged(object sender, EventArgs
{
if (lstListado.SelectedIndex != -1)
{
lblActual.Text = lstListado.SelectedItem.ToString();
lblPosicion.Text = lstListado.SelectedIndex.ToString();
}
}
privatevoidbnEliminar_Click(object sender, EventArgs e)
{
if (lstListado.SelectedIndex == -1)
MessageBox.Show("Primero debes seleccionar un elemento");
else
{
lstListado.Items.RemoveAt(lstListado.SelectedIndex);
lblTotal.Text = lstListado.Items.Count.ToString();

34

lblActual.Text = "____________";
lblPosicion.Text = "_____________";
}
}
privatevoidlnkSiguiente_LinkClicked(objectsender,LinkLabelLinkClickedEventArgs e)
{

frmComboventana = newfrmCombo();
ventana.ShowDialog();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
}

2)-Seleccionar Angulo:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace controles_2
{
publicpartialclassfrmCombo : Form
{
publicfrmCombo()
{
InitializeComponent();
}
privatevoidcmbAngulo_SelectedIndexChanged(object sender, EventArgs e)
{
double x = Convert.ToDouble(cmbAngulo.Text);
lblSeno.Text = Math.Sin(x).ToString();
lblCoseno.Text = Math.Cos(x).ToString();
lblTangente.Text = Math.Tan(x).ToString();
}
privatevoidfrmCombo_Load(object sender, EventArgs e)
{
for (int i = 0; i <= 360; i+=10)
{
cmbAngulo.Items.Add(i);
}
}
privatevoidlnkSiguiente_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{

35

frmCombinados ventana = newfrmCombinados();


ventana.ShowDialog();
}
}
}

3) Colores y tamao:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespace controles_2
{
publicpartialclassfrmCombinados : Form
{
publicfrmCombinados()
{
InitializeComponent();
}
privatevoidfrmCombinados_Load(object sender, EventArgs e)
{
lstColor.Items.Add("Rojo");
lstColor.Items.Add("Amarillo");
lstColor.Items.Add("Verde");
lstColor.Items.Add("Azul");
for (int i = 0; i <= 3000; i += 100)
{
cmbAlto.Items.Add(i);
cmbAncho.Items.Add(i);
}
}
privatevoidlstColor_SelectedIndexChanged(object sender, EventArgs e)
{
switch (lstColor.SelectedIndex)
{
case 0: txtPrueba.BackColor = Color.Red; break;
case 1: txtPrueba.BackColor = Color.Yellow; break;
case 2: txtPrueba.BackColor = Color.Green; break;
case 3: txtPrueba.BackColor = Color.Blue; break;
}
}
privatevoidcmbAncho_SelectedIndexChanged(object sender, EventArgs e)
{
txtPrueba.Width = Convert.ToInt32(cmbAncho.Text);
}
privatevoidcmbAlto_SelectedIndexChanged(object sender, EventArgs e)
{
txtPrueba.Height = Convert.ToInt32(cmbAlto.Text);

36

4) Suma de Vectores:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingClase_suma;
namespace controles_2
{
publicpartialclassfrmSuma : Form
{
Vec_Suma objeto;
public frmSuma()
{
InitializeComponent();
}
privatevoidbtnLlenar_Click(object sender, EventArgs e)
{
if (txtN1.Text == "" || txtN2.Text == "")
MessageBox.Show("Debes escribir valores primero");
else
{
String m=objeto.llenar(Convert.ToInt32(txtN1.Text), Convert.ToInt32(txtN2.Text));
if (!m.Equals(""))
MessageBox.Show(m);
else
{
lstN1.Items.Add(txtN1.Text);
lstN2.Items.Add(txtN2.Text);
}
}
}
privatevoidbtnSuma_Click(object sender, EventArgs e)
{
int[] R=newint[Convert.ToInt32(cmbTam.Text)];
R = objeto.Suma();
int num = objeto.Pos;
for (int i = 0; i <num; i++)
lstRes.Items.Add(R[i]);
}
privatevoidfrmSuma_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 50; i++)
cmbTam.Items.Add(i);

37

}
privatevoidcmbTam_SelectedIndexChanged(object sender, EventArgs e)
{
objeto = newVec_Suma(Convert.ToInt32(cmbTam.Text));
}

Impresin del formulario resuelto


1)- Agregar elementos:

38

2)- Seleccionar Angulo:

3) Colores y tamao:

39

4) Suma de Vectores:

40

Prctica 9: Mostrar Mayores y Eliminar.

Problemtica:
41

Realizar un programa, el cual tenga la funcin de que el usuario pueda ingresar en un


arreglo de n datos, con lo cual podr realizar la siguiente funcin: Agregar el Nombre y la
edad a un comboBox y a un listBox, con un segundo listBox para poder Mostrar a los
mayores de edad de dicha lista y si se cometi un error al meter un nombre tener un
botn de eliminar elemento.

Diagrama de la clase:

Cdigo de la clase:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace Mayor_edad
{
public class Mayor_de_edad
{
private String[] nombre;
private int[] edad;
int pos = 0, tam;
public String[] Nombre
{
get { return nombre; }

42

}
public int[] Edad
{
get { return edad; }
}
public int Pos
{
get { return pos; }
}
public Mayor_de_edad()
{
nombre = new String[10];
edad = new int[10];
tam = 10;
}
public Mayor_de_edad(int t)
{
nombre = new String[t];
edad = new int[t];
tam = t;
}
public String llenar(String x, int y)
{
String mensaje = "";
if (pos < tam)
{
nombre[pos] = x;
edad[pos] = y;
pos++;
}
else
mensaje = "debes seleccionar una cantidad mayor !!";
return mensaje;
}
public bool baja(String n)
{
bool encontro = false;
for (int i = 0; i < pos; i++)
{
if (nombre[i].Equals(n))
{
encontro = true;
for (int j = i; j < pos - 1; j++)
{
Nombre[j] = (nombre[j + 1]);
Edad[j] = (edad[j + 1]);
}
pos--;
}
}
return encontro;
}
public int consulta(String n)
{
int res = 0;
for (int i = 0; i < pos; i++)

43

if (nombre[i].Equals(n))
{
res = edad[i];
}

}
return res;

}
public String[] mayores()
{
String[] res = new String[tam];
int j = 0;
for (int i = 0; i < pos; i++)
{
if (edad[i] >= 18)
{
res[j] = nombre[i];
j++;
}
}
return res;
}
}

Cdigo del formulario:


using
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;
Mayor_edad;

namespace formulario_MayoresEdad
{
public partial class Form1 : Form
{
Mayor_de_edad objeto;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 50; i++)
{
cmbTamao.Items.Add(i);

44

private void cmbTamao_SelectedIndexChanged(object sender, EventArgs e)


{

objeto = new Mayor_de_edad(Convert.ToInt32(cmbTamao.Text));

}
private void btnAgregar_Click(object sender, EventArgs e)
{
if (txtNombre.Text == "" || txtEdad.Text == "")
MessageBox.Show("no debes dejar el texto vacio");
else
{
String m = objeto.llenar(txtNombre.Text, Convert.ToInt32(txtEdad.Text));
if (!m.Equals(""))
MessageBox.Show(m);
else
{
lstEliminar.Items.Add(txtNombre.Text);
cmbNombres.Items.Add(txtNombre.Text);
}
}
txtNombre.Text = "";
txtEdad.Text = "";
txtNombre.Focus();
}
private void cmbNombres_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("la edad es: " + objeto.consulta(cmbNombres.Text));
}
private void button1_Click(object sender, EventArgs e)
{
lstM_Edad.Items.Clear();
String[] r = new String[objeto.Pos];
r = objeto.mayores();
int c = 0;
while (r[c] != null)
{
lstM_Edad.Items.Add(r[c]);
c++;
}
}
private void button2_Click(object sender, EventArgs e)
{
bool res = false;
if (lstEliminar.SelectedIndex == -1)
MessageBox.Show("primero seleccione un elemento");
else
{
res = objeto.baja(lstEliminar.SelectedItem.ToString());
if (res == true)
{

45

lstEliminar.Items.Clear();
cmbNombres.Items.Clear();
String[] t = new String[objeto.Pos];
t = objeto.Nombre;
for (int i = 0; i < objeto.Pos; i++)
{
lstEliminar.Items.Add(t[i]);
cmbNombres.Items.Add(t[i]);
}
}
else
MessageBox.Show("no se encontro el nombre");
}
}
}
}

Impresin del formulario resuelto:

46

Prctica 10: Desviacin Estndar y Varianza


Problemtica:
Resuelve el siguiente problema utilizando una biblioteca de clases y probando tu clase
con un formulario de Windows.
Calcular la varianza y la desviacin estndar de un conjunto de datos estadsticos.
Diagrama de clase:

Cdigo de la clase:
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Clase_varianza
{
public class EstVar
{
//Atributos
private int[] o;
int pos = 0, tam;
//Propiedades
public int[] O
{
get { return o; }

47

}
public int Pos
{
get { return pos; }
}
//Constructores
public EstVar()
{
o = new int[5];
tam = 5;
}
public EstVar(int t)
{
o = new int[t];
tam = t;
}
//Metodos
public String Llenar(int x)
{
String mensaje = "";
if (pos < tam)
{
o[pos] = x;
pos++;
}
else
mensaje = "Te has sobrepasado!!";
return mensaje;
}
public double Promedio()
{
double rest = new double();
for (int i = 0; i < tam; i++)
{
rest = (rest + o[i]);
}
return rest / tam;
}
public double Estandar()
{
double[] rest = new double[tam];
double r = 0;
for (int i = 0; i < tam; i++)
{
rest[i] = (o[i] - Promedio());
rest[i] = rest[i] * rest[i];
r = rest[i] + r;
}
r = r / tam;
r = Math.Sqrt(r);
return r;
}
public double Varianza()
{
double k = 0;

48

k = Estandar() * Estandar();
return k;
}

Cdigo del formulario:


using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
Clase_varianza;

namespace Ejemplo_calculo
{
public partial class Form1 : Form
{
EstVar objeto;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 100; i++)
cmbTamao.Items.Add(i);
}
private void cmbTamao_SelectedIndexChanged(object sender, EventArgs e)
{
objeto = new EstVar(Convert.ToInt32(cmbTamao.Text));
}
private void btnAgregar_Click(object sender, EventArgs e)
{
if (txtAgregar.Text == "")
MessageBox.Show("Ingresa valores!!");
else
{
String m = objeto.Llenar(Convert.ToInt32(txtAgregar.Text));
if (!m.Equals(""))
MessageBox.Show(m);
else
{
lstNumeros.Items.Add(txtAgregar.Text);
lstNumeros.Focus();

49

}
private void btnCalcular_Click(object sender, EventArgs e)
{
lblVarianza.Text = (Convert.ToString(objeto.Varianza()));
lblEstandar.Text = (Convert.ToString(objeto.Estandar()));
txtAgregar.Text = "";
}
}

Impresin del formulario resuelto:

50

UNIDAD
II
51

Practica 11 - Arreglo de objetos Ventas


Problemtica:
Elaborar un programa con la interfaz que se muestra, se trata del control de
ventas de la tienda X. Utiliza un arreglo de objetos para almacenar los datos
de cada producto, en la parte superior inventa un logo y nombre de tu
empresa, el logo lo colocas como imagen.
Al realizar las ventas, selecciona del combo una clave de producto, al
seleccionar coloca la descripcin en una etiqueta, si se compran ms de 10
productos se toma el precio de mayoreo, si se compran ms de 20 productos
adems se le aplica un 10% de descuento al precio del mayoreo. Para mostrar
el total a pagar incluye una etiqueta en la que imprimas cual fue el costo
unitario y el total.
Para dar de baja un producto, selecciona la clave, coloca la descripcin del
producto en una etiqueta y procede a dar de baja al producto al presionar el
botn baja ( como algo adicional antes de dar de baja pregunta si est
seguro de la baja, si est seguro entonces eliminarlo, si no, cancelas el
procedimiento ). La baja ocasiona que se elimine completamente el producto
del arreglo, es decir, los productos que estn abajo del que se eliminar se
recorrern una posicin arriba en el arreglo.

Diagrama de clase

Diagrama de clase Arreglo

52

Cdigo de la clase:

using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace Clase_producto
{
public class Productos
{
public int Clave { get; set; }
public String Descripcion { get; set; }
public double Precio { get; set; }
public double Precio_mayoreo { get; set; }
public Productos()
{
Clave = 0;
Descripcion = "";
Precio = 0;
Precio_mayoreo = 0;
}
public Productos(int c, String d, double p, double pm)
{
Clave = c;
Descripcion = d;
Precio = p;
Precio_mayoreo = pm;

53

}
public double Ventas(int cantidad)
{
double pago = 0, descuento = 0, precios = 0;
if (cantidad < 10)
{
pago = cantidad * Precio;
}
if (cantidad >= 10 && cantidad < 20)
{
pago = cantidad * Precio_mayoreo;
}
else
if (cantidad >= 20)
{
precios= ((Precio_mayoreo * 10) / 100);
descuento = Precio_mayoreo - precios;
pago = descuento * cantidad;
}
return pago;
}

public class ARREGLO_PRODUCTOS


{
private Productos[] arr_productos;
int pos = 0, tam;
public Productos[] Arreglos_productos
{
get { return arr_productos; }
}
public int Pos
{
get { return pos; }
}
public ARREGLO_PRODUCTOS()
{
arr_productos = new Productos[5];
tam = 5;
}
public ARREGLO_PRODUCTOS(int t)
{
arr_productos = new Productos[t];
tam = t;
}
public void Inicializar(int p)
{
arr_productos[p] = new Productos();
}
public String Llenar(int p, int c, String d, double pr, double pm)
{
String mensaje = "";
if (p < tam)
{
arr_productos[p].Clave = c;
arr_productos[p].Descripcion = d;

54

arr_productos[p].Precio = p;
arr_productos[p].Precio_mayoreo = pm;
}
else
mensaje = " Error! El sistema a rebasado su Limite";
return mensaje;
}
public double Compra_p(int p, int cant)
{
return arr_productos[p].Ventas(cant);
}
public Productos Buscar(int clav, int num)
{
for (int i = 0; i < num; i++)
{
if (clav == arr_productos[i].Clave)
return arr_productos[i];
}
return null;
}
public void Baja(int clav, int num)
{
for (int i = 0; i < num; i++)
{
if (clav == arr_productos[i].Clave || arr_productos[i] != null)
{
for (int k = i; k < num - 1; k++)
{
arr_productos[k] = arr_productos[k + 1];
}
}
}
}

Cdigo del formulario:


using
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Windows.Forms;
Clase_producto;

55

namespace Formulario_productos
{
public partial class Form1 : Form
{
ARREGLO_PRODUCTOS Objeto;
Productos OBJ;
int numE = 0;
public Form1()
{
InitializeComponent();
}
private void btnSiguiente_Click(object sender, EventArgs e)
{
if (txtClaveAlta.Text == "" || txtDescripcin.Text == "" || txtPrecioMayoreo.Text ==
"" || txtPrecioMenudeo.Text == "")
MessageBox.Show(" No se han ingresado los Datos POR FAVOR!! Ingresa todos
los datos del producto ");
else
{
int cla = Convert.ToInt32(txtClaveAlta.Text);
String desc= txtDescripcin.Text;
double p = Convert.ToDouble(txtPrecioMenudeo.Text);
double pm = Convert.ToDouble(txtPrecioMayoreo.Text);
Objeto.Inicializar(numE);
String mens = Objeto.Llenar(numE, cla, desc, p, pm);
}
cmbClaveVentas.Items.Add(txtClaveAlta.Text);
cmbClaveBaja.Items.Add(txtClaveAlta.Text);
txtClaveAlta.Text = "";
txtDescripcin.Text = "";
txtPrecioMayoreo.Text = "";
txtPrecioMenudeo.Text = "";
numE++;
txtClaveAlta.Focus();
}
private void Form1_Load(object sender, EventArgs e)
{
Objeto = new ARREGLO_PRODUCTOS();
OBJ = new Productos();
}
private void btnCompra_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(txtCantidad.Text) >= 10 && Convert.ToUInt32(txtCantidad.Text)
< 20)
{
rbMayoreo.Checked = true;
rbMenudeo.Checked = false;
chbDescuento.Checked = false;
MessageBox.Show(" Su Total a Pagar es de : $" +
Convert.ToString(OBJ.Ventas(Convert.ToInt32(txtCantidad.Text))) + ", El precio normal del
producto es de: $" + OBJ.Precio_mayoreo);
}
else

56

if (Convert.ToUInt32(txtCantidad.Text) < 10)


{
rbMenudeo.Checked = true;
rbMayoreo.Checked = false;
chbDescuento.Checked = false;
MessageBox.Show("Su Total a Pagar es de: $" +
Convert.ToString(OBJ.Ventas(Convert.ToInt32(txtCantidad.Text))) + ",El precio normal del
producto es de: $" + OBJ.Precio);
}
if (Convert.ToInt32(txtCantidad.Text) >= 20)
{
rbMayoreo.Checked = true;
chbDescuento.Checked = true;
rbMenudeo.Checked = false;
MessageBox.Show("Su Total a Pagar es de: $" +
Convert.ToString(OBJ.Ventas(Convert.ToInt32(txtCantidad.Text))) + ", El descuento es de el
%10, El precio normal del producto es de: $" + OBJ.Precio_mayoreo);
}
}
private void cmbClave1_SelectedIndexChanged(object sender, EventArgs e)
{
OBJ = Objeto.Buscar(Convert.ToInt32(cmbClaveVentas.Text), numE);
lblDescripcion.Text = OBJ.Descripcion + "- Precio Menudeo: $" + OBJ.Precio + ",
Precio Mayoreo: $" + OBJ.Precio_mayoreo;
}
private void cmbClave2_SelectedIndexChanged(object sender, EventArgs e)
{
OBJ = Objeto.Buscar(Convert.ToInt32(cmbClaveBaja.Text), numE);
lblDescripcion2.Text = OBJ.Descripcion + "- Precio Menudeo: $" + OBJ.Precio + ",
Precio Mayoreo: $" + OBJ.Precio_mayoreo;
}
private void btnEliminar_Click(object sender, EventArgs e)
{
if (cmbClaveBaja.SelectedIndex != -1)
{
Objeto.Baja(Convert.ToInt32(cmbClaveBaja.Text), numE);
numE--;
cmbClaveVentas.Items.Clear();
cmbClaveBaja.Items.Clear();
Productos[] temp = new Productos[10];
temp = Objeto.Arreglos_productos;
for (int i = 0; i < numE; i++)
{
cmbClaveVentas.Items.Add(temp[i].Clave);
cmbClaveBaja.Items.Add(temp[i].Clave);
}
cmbClaveBaja.Text = "";
lblDescripcion2.Text = "___________";
cmbClaveVentas.Text = "";
lblDescripcion.Text = "___________";
txtCantidad.Text = "";
rbMenudeo.Checked = false;
rbMayoreo.Checked = false;

57

}
}

chbDescuento.Checked = false;

Impresin del formulario, resuelto:


*Alta

58

*Venta (Menudeo)

59

*Mensaje de la Venta

*Venta (Mayoreo y descuento)


60

61

*Mensaje de la Venta

*Baja

62

Practica 12 Programa de Herencia (Cajero y Vendedor)


Problemtica:
Realizar un programa el cual el cliente pueda Ingresar todos sus datos el Nombre, Edad y
Sexo, el cual seleccionar el tipo de Empleado ( Si es Vendedor o Cliente), el cual si
selecciona Cajero mostrar su pago por da y la fecha de ingreso, el cual calculo el sueldo
diario por mes y una prima vacacional, la cual depende de la antigedad del empleado, si
el empleado tiene la antigedad menor de 12 (Solo tiene el 10), si es mayor o igual a 12 y
menor o igual a 24 (Solo tiene el 30) y si es mayor a 24 (Solo tiene el 50)
Diagrama de clase de Empleado

Diagrama de clase de Vendedor

Diagrama de clase
Cajero

Cdigo de la clase:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace Clase_Herencia
{
public class Empleado
{
public String nombre { get; set; }
public int edad { get; set; }

63

de

public String sexo { get; set; }


public Empleado()
{
nombre = "";
edad = 0;
sexo = "";
}
public Empleado(String n, int e, String s)
{
nombre = n;
edad = e;
sexo = s;
}
public virtual double Sueldo()
{
return 0;
}
}
public class Cajero : Empleado
{
public double Pago_diario { get; set; }
public int Antiguedad { get; set; }

public Cajero()
: base()
{
Pago_diario = 0;
Antiguedad = 0;
}
public Cajero(String n, int e, String s, double pd, int a)
: base(n, e, s)
{
Pago_diario = pd;
Antiguedad = a;
}
public override double Sueldo()
{
double sueldo = 0;
return sueldo = Pago_diario * 30;
}
public double Prima_Vacacional()
{
double prima = 0;
if (Antiguedad < 12)
prima = ((Sueldo() * 10) / 100);
else
if (Antiguedad >= 12 && Antiguedad <= 24)
prima = ((Sueldo() * 30) / 100);
else
if (Antiguedad > 24)
prima = ((Sueldo() * 50) / 100);
return prima;
}

64

public class Vendedor : Empleado


{
public int Num_ventas { get; set; }

public Vendedor()
: base()
{
Num_ventas = 0;
}
public Vendedor(String n, int e, String s, int nv)
: base(n, e, s)
{
Num_ventas = nv;
}
public override double Sueldo()
{
double sueldo = 0;
if (Num_ventas <= 5000)
sueldo = ((Num_ventas * 10) / 100);
else
if (Num_ventas > 5000)
sueldo = ((Num_ventas * 15) / 100);
return sueldo;
}
public String Mensaje()
{
String mensaje = "";
return mensaje = nombre + " Tu sueldo es de: $" + Sueldo();
}

Cdigo del formulario:


using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;

65

using System.Windows.Forms;
using Clase_empleados_herencia;
namespace Formulario_herencia
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void rbCajero_CheckedChanged(object sender, EventArgs e)
{
gpbCajero.Enabled = true;
gpbVendedor.Enabled = false;
}
private void rbVendedor_CheckedChanged(object sender, EventArgs e)
{
gpbVendedor.Enabled = true;
gpbCajero.Enabled = false;
}
private void btnCalcular_Click(object sender, EventArgs e)
{
Cajero OBJ = new Cajero();
Vendedor OBJ2 = new Vendedor();
if (rbCajero.Checked)
{
OBJ.nombre = txtNombre.Text;
OBJ.edad = Convert.ToInt32(txtEdad.Text);
OBJ.sexo = txtSexo.Text;
OBJ.Pago_diario = Convert.ToDouble(txtPagodia.Text);
MessageBox.Show(" Fecha de ingreo del empleado: " +
msFechaingreso.SelectionStart.ToShortDateString());
OBJ.Antiguedad = ((msFechaingreso.SelectionStart.Month - DateTime.Now.Month)
+ 12 * (msFechaingreso.SelectionStart.Year - DateTime.Now.Year)) * -1;
MessageBox.Show(" Su sueldo es de: $" + OBJ.Sueldo());
MessageBox.Show(" Prima vacacional es de: $" + OBJ.Prima_Vacacional());
}
else
if (rbVendedor.Checked)
{
OBJ2.nombre = txtNombre.Text;
OBJ2.edad = Convert.ToInt32(txtEdad.Text);
OBJ2.sexo = txtSexo.Text;
OBJ2.Num_ventas = Convert.ToInt32(txtMontoventa.Text);
MessageBox.Show(OBJ2.Mensaje());
}
}

66

Impresin del formulario, resuelto:

*Tipo de Empleado (Cajero)

67

*Fecha de Ingreso

*Sueldo Base
Vacacional

*Prima

68

*Tipo de Empleado (Vendedor)

*Sueldo Base

69

Practica 13: Herencia, Ejecutivo y Secretaria


Problemtica:
Realizar un programa el cual dependiendo a Tipo de Empleado (Ejecutivo o Secretario),
Ingresando los datos del usuario que es el Nombre, Edad, Sueldo, Compensacin (En
caso de Ejecutivo), calcular su Sueldo final con compensacin
Diagrama de clase:

Cdigo de la clase:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace Clase_herencia
{
public class Empleado
{
public string nombre { get; set; }
public int edad { get; set; }
public double sueldo { get; set; }
public Empleado()
{
nombre = "";
edad = 0;
sueldo = 0;
}
public Empleado(string n, int e, double s)
{

70

nombre = n;
edad = e;
sueldo = s;

}
public virtual void Incremento(int p)
{
sueldo = sueldo + (sueldo * p / 100);
}
}
public class Ejecutivo : Empleado
{
public double compensacion { get; set; }
public Ejecutivo(string n, int e, double s, double c)
: base(n, e, s)
{
compensacion = c;
}
public Ejecutivo()
: base()
{
compensacion = 0;
}

public override void Incremento(int p)


{
sueldo = sueldo + (sueldo * (p + 5) / 100);
}
public void sueldo_final()
{
sueldo = sueldo + compensacion;
}

public class Secretaria : Empleado


{

public override void Incremento(int p)


{
sueldo = sueldo + (sueldo * (p + 2) / 100);
}

Cdigo del formulario:


using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Threading.Tasks;

71

using System.Windows.Forms;
using Clase_herencia;
namespace Formulario_sueldo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label6_Click(object sender, EventArgs e)
{
}
private void rbSecretaria_CheckedChanged(object sender, EventArgs e)
{
txtCompensacin.Enabled = false;
}
private void rbEjecutivo_CheckedChanged(object sender, EventArgs e)
{
txtCompensacin.Enabled = true;
}
private void btnCalcular_Click(object sender, EventArgs e)
{
Ejecutivo obj1 = new Ejecutivo();
Secretaria obj2 = new Secretaria();
if (rbEjecutivo.Checked)
{
obj1.nombre = txtNombre.Text;
obj1.edad = Convert.ToInt32(txtEdad.Text);
obj1.sueldo = Convert.ToDouble(txtSueldo.Text);
obj1.compensacion = Convert.ToDouble(txtCompensacin.Text);
obj1.Incremento(5);
obj1.sueldo_final();
lblTotal.Text = obj1.sueldo.ToString();

}
else
{
obj2.nombre = txtNombre.Text;
obj2.edad = Convert.ToInt32(txtEdad.Text);
obj2.sueldo = Convert.ToDouble(txtSueldo.Text);
obj2.Incremento(5);
lblTotal.Text = obj2.sueldo.ToString();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}

72

Impresin del formulario, resuelto:

73

Practica 14: Herencia 5


Problemtica:
Realice las clases que se muestran arriba, la clase base Persona tiene 4
atributos y 3 mtodos:

Categora: sta depende de la antigedad, si tiene entre 0 y 5 aos


entonces la persona tiene media plaza, si tiene mas de 5 aos se le
asigna plaza completa.
Calcula_aguinaldo y Prima_vacaciona: stos mtodos no tendrn
implementado nada, solo return 0; ya que stos se implementarn en
cada una de sus clases derivadas ( POLIMORFISMO )

La clase docente ( derivada ) tiene adems de los atributos de la clase base


Persona dos mas: Horas_trabajadas y Salario_hora, los mtodos :

Sueldo_mensual: Se calcula suponiendo que trabaja 8 horas diarias.


Calcula_aguinaldo: Son 40 das.
Prima_vacacional: Son 25 dias.

La clase Administrativo ( derivada ) tiene adems de los atributos de la clase


base Persona dos mas: Salario_diario y puesto, los mtodos :

Calcula_aguinaldo: Es el 20% de su salario mensual


Prima_vacacional: Depende del puesto: si es secretaria se le dan 10
das, si es jefe de departamento 15, si es subdirector 20 y director 30.

Diagrama de clase:
74

Cdigo
de la
clase:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
{
public class Persona
{
public String
public int Edad { get; set; }
public String Direccion { get; set; }
public int Antiguedad { get; set; }

Clase_persona

Nombre { get; set; }

public Persona()
{
Nombre = "";
Edad = 0;
Direccion = "";
Antiguedad = 0;
}
public Persona(String n, int e, String d, int a)
{
Nombre = n;
Edad = e;
Direccion = d;
Antiguedad = a;
}
public String categoria()
{
if (Antiguedad > 0 && Antiguedad <= 5)
return "Media plaza";
else
return "Plaza completa";
}
public virtual double calcular_aguinaldo()
{
return 0;
}
public virtual double prima_vacacional()
{

75

return 0;

}
public class Docente : Persona
{
public int horas_trabajadas { get; set; }
public double salario_hora { get; set; }
public Docente()
: base()
{
horas_trabajadas = 0;
salario_hora = 0;
}
public Docente(String n, int e, String d, int a, int ht, double sd)
: base(n, e, d, a)
{
horas_trabajadas = ht;
salario_hora = sd;
}
public double sueldo_mensual()
{
return horas_trabajadas * salario_hora * 20;
}
public override double calcular_aguinaldo()
{
return sueldo_mensual() * 2;
}
public override double prima_vacacional()
{
return horas_trabajadas * salario_hora * 25;
}
}
public class Administrativo : Persona
{
public double salario_diario { get; set; }
public String puesto { get; set; }
public Administrativo()
: base()
{
salario_diario = 0;
puesto = "";
}
public Administrativo(String n, int e, String d, int a, double sd, String p)
: base(n, e, d, a)
{
salario_diario = sd;
puesto = p;
}
public override double calcular_aguinaldo()
{
return salario_diario * 30 * 0.20;
}
public override double prima_vacacional()
{

76

switch (puesto)
{
case "Secretaria": return salario_diario * 10;
case "Jefe de Departamento": return salario_diario * 15;
case "Subdirector": return salario_diario * 20;
case "Director": return salario_diario * 30;
default: return 0;
}
}

public class Arreglo_docentes


{
private Docente[] arr_docentes;
private int pos = 0, tam;
public Docente[] Arr_docentes
{ get { return arr_docentes; } }
public int Pos
{ get { return pos; } }
public Arreglo_docentes()
{
arr_docentes = new Docente[5];
tam = 5;
}
public Arreglo_docentes(int t)
{
arr_docentes = new Docente[t];
tam = t;
}
public String llenar(Docente d)
{
String mensajito = "";
if (pos >= tam)
mensajito = "Sobrepasaste el arreglo!!";
else
{
arr_docentes[pos] = d;
pos++;
}
return mensajito;
}
public String Categoria(int p)
{
return arr_docentes[p].categoria();
}
public double SueldoMensual(int p)
{
return arr_docentes[p].sueldo_mensual();
}
public double Aguinaldo(int p)
{
return arr_docentes[p].calcular_aguinaldo();
}
public double Prima(int p)
{
return arr_docentes[p].prima_vacacional();

77

public class Arreglo_administrativo


{
private Administrativo[] arr_administrativo;
private int pos = 0, tam;
public Administrativo[] Arr_administrativo
{ get { return arr_administrativo; } }
public int Pos
{ get { return pos; } }
public Arreglo_administrativo()
{
arr_administrativo = new Administrativo[5];
tam = 5;
}
public Arreglo_administrativo(int t)
{
arr_administrativo = new Administrativo[t];
tam = t;
}
public String llenar(Administrativo d)
{
String mensajito = "";
if (pos >= tam)
mensajito = "Sobrepasaste el arreglo!!";
else
{
arr_administrativo[pos] = d;
pos++;
}
return mensajito;
}
public String Categoria(int a)
{
return arr_administrativo[a].categoria();
}
public double Aguinaldo(int a)
{
return arr_administrativo[a].calcular_aguinaldo();
}
public double Prima(int a)
{
return arr_administrativo[a].prima_vacacional();
}
}

Cdigo del formulario:


using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;

78

using
using
using
using
using

System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
Herencia_Persona5;

namespace Herencia_5
{
public partial class Form1 : Form
{
ARREGLO_ADMINISTRATIVO objadministrativos;
ARREGLOS_DOCENTES objdocentes;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
cmbPuesto.Items.Add("Secretaria");
cmbPuesto.Items.Add("Jefe de departamento");
cmbPuesto.Items.Add("Subdirector");
cmbPuesto.Items.Add("Director");
rbDocente.Checked = true;
gpbAdministrativos.Enabled = false;
}
private void rbDocente_CheckedChanged(object sender, EventArgs e)
{
gpbAdministrativos.Enabled = false;
gpbDocentes.Enabled = true;
}
private void rbAdministrativo_CheckedChanged(object sender, EventArgs e)
{
gpbAdministrativos.Enabled = true;
gpbDocentes.Enabled = false;
}
private void btnLimpiar_Click(object sender, EventArgs e)
{
txtNombre.Text = "";
txtDireccion.Clear();
txtHoratrabajadas.Clear();
txtSalariodiario.Clear();
txtSalariohora.Clear();
nudEdad.Value = 18;
nudAntiguedad.Value = 0;
lblAguinaldo.Text = "__________";
lblCategoria.Text = "___________";
lblPrimavacacional.Text = "___________";
lblSueldomensual.Text = "__________";
rbDocente.Checked = true;
gpbAdministrativos.Enabled = false;

79

gpbDocentes.Enabled = true;

private void btnSiguiente_Click(object sender, EventArgs e)


{
DOCENTE objDocente = new DOCENTE();
ADMINISTRATIVO objAdministrativo = new ADMINISTRATIVO();
String nombre = txtNombre.Text;
int edad = Convert.ToInt32(nudEdad.Value);
String direccion = txtDireccion.Text;
int antiguedad = Convert.ToInt32(nudAntiguedad.Value);
ListViewItem item;
if (rbDocente.Checked)
{
int HT = Convert.ToInt32(txtHoratrabajadas.Text);
double SH = Convert.ToDouble(txtSalariohora.Text);
objDocente = new DOCENTE(nombre, edad, direccion, antiguedad, HT, SH);
String m = objdocentes.Llenar(objDocente);
if (m == "")
{
lblAguinaldo.Text = objdocentes.Aguinaldo(objdocentes.Pos - 1).ToString();
lblCategoria.Text = objdocentes.Categoria(objdocentes.Pos - 1);
lblPrimavacacional.Text = objdocentes.Prima(objdocentes.Pos - 1).ToString();
lblSueldomensual.Text = objdocentes.Sueldo_mensual(objdocentes.Pos 1).ToString();
item = lvConcentrado.Items.Add("Docentes");
item.SubItems.Add(txtNombre.Text);
item.SubItems.Add(edad.ToString());
item.SubItems.Add(antiguedad.ToString());
item.SubItems.Add(objDocente.Categoria());
item.SubItems.Add(objDocente.Calcular_Aguinaldo().ToString());
item.SubItems.Add(objDocente.Prima_vacacional().ToString());
item.SubItems.Add(lblSueldomensual.Text);
}
else
MessageBox.Show(m);
}
else
{
double sd = Convert.ToDouble(txtSalariodiario.Text);
String p = cmbPuesto.Text;
objAdministrativo.Nombre = nombre;
objAdministrativo.Edad = edad;
objAdministrativo.Direccion = direccion;
objAdministrativo.salario_diario = sd;
objAdministrativo.puesto = p;
objAdministrativo.Antiguedad=antiguedad;
String m=objadministrativos.Llenar(objAdministrativo);
if (m == "")
{
lblAguinaldo.Text = objadministrativos.Aguinaldo(objadministrativos.Pos 1).ToString();
lblCategoria.Text = objadministrativos.Categoria(objadministrativos.Pos - 1);

80

lblPrimavacacional.Text = objadministrativos.Prima(objadministrativos.Pos 1).ToString();


item = lvConcentrado.Items.Add("Administrativos");
item.SubItems.Add(txtNombre.Text);
item.SubItems.Add(edad.ToString());
item.SubItems.Add(antiguedad.ToString());
item.SubItems.Add(objAdministrativo.Categoria());
item.SubItems.Add(objAdministrativo.Calcular_Aguinaldo().ToString());
item.SubItems.Add(objAdministrativo.Prima_vacacional().ToString());
item.SubItems.Add(lblSueldomensual.Text);
}
else
MessageBox.Show(m);
}
}
private void btnNumerodeempleados_Click(object sender, EventArgs e)
{
objdocentes = new ARREGLOS_DOCENTES(Convert.ToInt32(txtNuempleados.Text));
objadministrativos = new
ARREGLO_ADMINISTRATIVO(Convert.ToInt32(txtNuempleados.Text));
}
}
}

Impresin del formulario, resuelto:

81

Practica 15: Excepciones


Problemtica:

82

Realizar un programa el cual se utilice un MenuStrip el cual enlace 3


formularios, en el primero de que el programa indique cual fue el nmero que
el usuario ingreso, el segundo una divisin de dos nmeros y la tercera y un
arreglo el cual pida el nombre y la edad de un numero n de usuarios el cual al
generarlo del promedio de todas las edades que se han ingresado
Diagrama de clase:

Cdigo de la clase:
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Windows.Forms;

namespace Exepciones
{
class ALUMNOS
{
private int[] edad;
private String[] nombre;
private int tamao;
public ALUMNOS()
{
edad = new int[10];
nombre = new String[10];
tamao = 10;
}
public ALUMNOS(int tam)
{
edad = new int[tam];

83

nombre = new String[tam];


tamao = tam;

}
public int[] Edad
{
get { return edad; }
}
public String[] Nombre
{
get { return nombre; }
}
public int Tamao
{
get { return tamao; }
}
public double Promedio()
{
double pro = 0;int i=0;
do
{
pro += edad[i] / tamao;
i++;
} while (i < tamao);
return pro;
}
public bool Llenar(int t, int e, String n)
{
try
{
edad[t] = e;
nombre[t] = n;
return true;
}
catch (Exception)
{
MessageBox.Show("El arreglo esta SATURADO!!!");
return false;
}
}

Cdigo del formulario:


*Form1
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;

84

namespace Exepciones
{
public partial class frmPrincipal : Form
{
public frmPrincipal()
{
InitializeComponent();
}
private void divicionToolStripMenuItem_Click(object sender, EventArgs e)
{
fmrDivision ventana = new fmrDivision();
ventana.MdiParent = this;
ventana.Show();
}
private void ejercicio1ToolStripMenuItem_Click(object sender, EventArgs e)
{
fmrejercicio1 ventana = new fmrejercicio1();
ventana.MdiParent = this;
ventana.Show();
}
private void arreglosToolStripMenuItem_Click(object sender, EventArgs e)
{
fmrArreglos ventana = new fmrArreglos();
ventana.MdiParent = this;
ventana.Show();
}
private void frmPrincipal_Load(object sender, EventArgs e)
{
}

*Primera Prueba
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;

namespace Exepciones
{
public partial class fmrejercicio1 : Form
{
public fmrejercicio1()
{
InitializeComponent();
}

85

private void btnAceptar_Click(object sender, EventArgs e)


{
//Manejo de exepciones
try
{
//Aqui se coloca las exepciones que se desea probar
//y que pudiera causar algun error
int i;
i = Convert.ToInt32(txtNumero.Text);
MessageBox.Show("El numero que escribistes fue: " + i);
}
catch (FormatException)
{
//Semaneja la exepcion o error que pudiera ocurrir en el bloque try
MessageBox.Show("No se acptan letras!!");
txtNumero.Text = "";
txtNumero.Focus();

}
catch (OverflowException)
{
MessageBox.Show("Pusiste un numero grande !!");
txtNumero.Text = "";
txtNumero.Focus();
}
catch (Exception error )
{
MessageBox.Show("Error innesperado"+error);
txtNumero.Text = "";
txtNumero.Focus();
}
finally
{
//Este bloque se ejecuta siempre !!
MessageBox.Show("Esto se ejecuta siempre");
}

private void fmrejercicio1_Load(object sender, EventArgs e)


{
}

*Ejemplo de divisiones
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;

86

namespace Exepciones
{
public partial class fmrDivision : Form
{
public fmrDivision()
{
InitializeComponent();
}
private void btnDividir_Click(object sender, EventArgs e)
{
int x, y;
double res;
try
{
x = Convert.ToInt32(txtNumero1.Text);
y = Convert.ToInt32(txtNumero2.Text);
res = (double)x / y;
MessageBox.Show(" El resultado de la divicin es:" + res);
}
catch (OverflowException)
{
MessageBox.Show("Pusiste un numero grande !!");
txtNumero1.Text = "";
txtNumero2.Text = "";
txtNumero2.Focus();
}
catch (FormatException)
{
MessageBox.Show("No se acepta la letras !!");
txtNumero1.Text = "";
txtNumero2.Text = "";
txtNumero2.Focus();
}
catch (DivideByZeroException)
{
MessageBox.Show(" Division entre cero !!");
txtNumero1.Text = "";
txtNumero2.Text = "";
txtNumero2.Focus();
}
catch (Exception)
{
MessageBox.Show(" Error general ");
}
}
private void fmrDivision_Load(object sender, EventArgs e)
{
}

*Arreglo y clases
using System;

87

using
using
using
using
using
using
using

System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;

namespace Exepciones
{
public partial class fmrArreglos : Form
{
ALUMNOS obj;
int t = 0;
public fmrArreglos()
{
InitializeComponent();
}
private void btnGuardar_Click(object sender, EventArgs e)
{
try
{
if (obj.Llenar(t, Convert.ToInt32(txtEdad.Text), txtNombre.Text))
{
t++;
MessageBox.Show(" Elemento guardado... ");
txtEdad.Text = "";
txtNombre.Clear();
txtNombre.Focus();
}
}
catch(Exception error)
{
MessageBox.Show(error.Message);
}
}
private void btnTamo_Click(object sender, EventArgs e)
{
obj = new ALUMNOS(Convert.ToInt32(txtNoalumnos.Text));
MessageBox.Show("Se dimension el arreglo"+txtNoalumnos);
}
private void btnPromedio_Click(object sender, EventArgs e)
{
MessageBox.Show(" El promedio de edad fue: " + obj.Promedio());
}
private void fmrArreglos_Load(object sender, EventArgs e)
{
}

88

Impresin del formulario, resuelto:

89

90

91

92

Practica 16: Control de Empleado


Problemtica:
Realizar un programa el cual use un TabControl, en su primer pestaa que se pueda
ingresar la alta del empleado, la segunda la consulta del empleado que se dio de alta y la
tercera mostrar todos los empleados, en la alta el usuario debe ingresar su Nombre,
Edad, Sexo, Fecha de ingreso, Puesto, Agregar una fotografa y que cuando se d a
agregar empleado se imprima su Sueldo Base, cuantos aos sabticos tiene, Su tipo de
prstamo, y el monto de prstamo
Diagrama de clase:

Cdigo de la clase:
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Empleado
{
public class EMPLEADO
{
public String Nombre { get; set; }
public int Edad { get; set; }
public String Sexo { get; set; }

93

public DateTime Fecha_ingreso { get; set; }


public String Puesto { get; set; }
public String Foto { get; set; }
public EMPLEADO()
{
Nombre = "";
Edad = 0;
Sexo = "";
Fecha_ingreso = System.DateTime.Now;
Puesto = "Tecnico de Apoyo";
Foto = "";
}
public EMPLEADO(String n,int e,String s,DateTime d, String p, String f)
{
Nombre = n;
Edad = e;
Sexo = s;
Fecha_ingreso = d;
Puesto = p;
Foto = f;
}
public double Sueldo_base()
{
switch (Puesto)
{
case "Presidente": return 50000;
case "Abogado": return 30000;
case "Ingeniero en Sistemas": return 20000;
case "Tecnico de Apoyo": return 10000;
default: return 0;
}
}
public int Ao_Sabatico()
{
switch (Puesto)
{
case "Presidente": return 3;
case "Abogado": return 2;
case "Ingeniero en Sistemas": return 1;
case "Tecnico de Apoyo": return 0;
default: return 0;
}
}
public String Tipo_prestamo()
{
switch (Puesto)
{
case "Presidente": return "Especial";
case "Abogado": return "Ordinario";
case "Ingeniero en Sistemas": return "Normal";
case "Tecnico de Apoyo":
DateTime FechaInicial=Fecha_ingreso;
DateTime FechaFinal = System.DateTime.Now;
//Formula para calcular el tiempo
int diferencia=(FechaInicial.Month - FechaFinal.Month) + (12 * (FechaFinal.Year
- FechaInicial.Year));

94

if (diferencia > 6)
return "Normal";
else
return "No tienes derecho";
default: return "Sin Prestamo";

}
}
public double Monto_Prestamo()
{
if (Tipo_prestamo().Equals("Especial"))
return 60000;
else
if (Tipo_prestamo().Equals("Ordinario"))
return 30000;
else
if (Tipo_prestamo().Equals("Normal"))
return 10000;
else
return 0;
}
}
public class ARREGLOS_EMPLEADO
{
private EMPLEADO[] arr_empleados;
int pos = 0,tam;
public EMPLEADO[] Arr_empleados
{
get { return arr_empleados; }
}
public int Pos
{
get{return pos;}
}
public ARREGLOS_EMPLEADO()
{
arr_empleados = new EMPLEADO[5];
tam = 5;
}
public ARREGLOS_EMPLEADO(int t)
{
arr_empleados = new EMPLEADO[t];
tam = t;
}
public void Inicializar_elemento(int p)
{
arr_empleados[p] = new EMPLEADO();
}
public String Llenar(int p,String n, int e, String s, DateTime d, String pt,String fto)
{
String m = "";
if (p < tam)
{
arr_empleados[p].Nombre = n;
arr_empleados[p].Edad = e;

95

arr_empleados[p].Sexo = s;
arr_empleados[p].Fecha_ingreso = d;
arr_empleados[p].Puesto = pt;
arr_empleados[p].Foto = fto;
}
else
m = " SATURADO!!";
return m;
}
public String Tipo_prestamo(int p)
{
return arr_empleados[p].Tipo_prestamo();
}
public double Sueldo_base1(int p)
{
return arr_empleados[p].Sueldo_base();
}
public double Monto_prestamo(int p)
{
return arr_empleados[p].Monto_Prestamo();
}
public int Sabatico(int p)
{
return arr_empleados[p].Ao_Sabatico();
}

public EMPLEADO Buscar(String nom, int ni)


{
for (int i = 0; i < ni; i++)
{
if (nom.Equals(arr_empleados[i].Nombre))
return arr_empleados[i];
}
return null;
}

Cdigo del formulario:


using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.Windows.Forms;
Empleado;

namespace Empleados
{
public partial class Form1 : Form
{
ARREGLOS_EMPLEADO Objetos;

96

int numE = 0;
String fotito = "";
public Form1()
{
InitializeComponent();
}
private void label10_Click(object sender, EventArgs e)
{
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
cmbPuesto.Items.Add("Presidente");
cmbPuesto.Items.Add("Abogado");
cmbPuesto.Items.Add("Ingeniero en Sistemas");
cmbPuesto.Items.Add("Tecnico de Apoyo");
Objetos = new ARREGLOS_EMPLEADO();
}
private void btnLimpiar_Click(object sender, EventArgs e)
{
txtNombre.Text = "";
nudEdad.Value = 0;
rbFemenino.Checked = false;
rbMasculino.Checked = false;
dtpFechaIngreso.Value = DateTime.Now;
cmbPuesto.Text = "";
lblAosabatico.Text = "_______";
lblSuldobase.Text = "_______";
lblMontoprestamo.Text = "_______";
lblTipoprestamo.Text = "_______";
picFoto.Image = null;
}
private void btnAgregarEmpleado_Click(object sender, EventArgs e)
{
if (numE < 5)
{
int edad = Convert.ToInt32(nudEdad.Value);
String sexo;
if (rbFemenino.Checked == true)
sexo = rbFemenino.Text;
else
sexo = rbMasculino.Text;
DateTime fi;
fi = dtpFechaIngreso.Value.Date;
String puesto;
puesto = cmbPuesto.Text;
Objetos.Inicializar_elemento(numE);

97

String mensaje = Objetos.Llenar(numE, txtNombre.Text, edad, sexo, fi,


puesto,fotito);
cmbNombreselec.Items.Add(txtNombre.Text);
lblSuldobase.Text = Objetos.Sueldo_base1(numE).ToString();
lblAosabatico.Text = Objetos.Sabatico(numE).ToString();
lblMontoprestamo.Text = Objetos.Monto_prestamo(numE).ToString();
lblTipoprestamo.Text = Objetos.Tipo_prestamo(numE);
lstNombre.Items.Add(txtNombre.Text);
lstSexo.Items.Add(sexo);
lstPuesto.Items.Add(puesto);
lstSueldoBase.Items.Add(Objetos.Sueldo_base1(numE));
lstListaIngreso.Items.Add(fi);
numE++;
fotito = "";
}
}
private void btnAgregarFotografia_Click(object sender, EventArgs e)
{
Image a;
ofdFoto.Title = "Selecciona una foto del empleado";
ofdFoto.Title = "imagenes jpg(*.hpg)|*.jpg| Imagenes gif (*gif)|*.gif";
if (ofdFoto.ShowDialog() == DialogResult.OK)
{
a = Image.FromFile(ofdFoto.FileName);
fotito = ofdFoto.FileName;
picFoto.Image = a;
}
}
private void cmbNombreselec_SelectedIndexChanged(object sender, EventArgs e)
{
EMPLEADO obj = new EMPLEADO();
obj = Objetos.Buscar(cmbNombreselec.Text,numE);
ListViewItem item;
lvConcentrado.Items.Clear();
item = lvConcentrado.Items.Add(cmbNombreselec.Text);
item.SubItems.Add(obj.Edad.ToString());
item.SubItems.Add(obj.Sexo);
item.SubItems.Add(obj.Puesto);
item.SubItems.Add(obj.Sueldo_base().ToString());
item.SubItems.Add(obj.Fecha_ingreso.ToShortDateString());
Image a;
if (obj.Foto.Equals(""))
{
MessageBox.Show(" Persona no tiene imagen para mostrar");
picFotosem.Image = null;
}
else
{
a = Image.FromFile(obj.Foto);
picFotosem.Image = a;
}
}

98

Impresin del formulario, resuelto:

99

100

Conclusin
Anteriormente no se tena la menor idea que sera tan complicado usar los formularios ya
que era un medio muy desconocido, ya que se manejaba un entorno muy diferente, pero
con la realizacin de los trabajos se fue mejorando y entendiendo el cmo manejar esta
plataforma.
Siguiendo con cada uno de los pasos que se estableci en la introduccin desde la
creacin de un diagrama de clases hasta la finalizacin de una aplicacin (Formulario).
Gracias a la participacin, se pudo entender el funcionamiento que tiene la creacin de
dichas clases para probarlas a un formulario, aunque an hay mucho esfuerzo por poder
entender algn cdigo que se establecen una aplicacin (Formulario).

101

102

You might also like