martes, 27 de enero de 2009

implementacion windows practica 1


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

namespace WindowsApplication1
{
public partial class Form1 : Form
{
int[] Elementos;
int i,suma,promedio;
public Form1()
{
InitializeComponent();
Elementos = new int[10];
i = suma=promedio=0;
lbSalida.Items.Add("Lista valores");
}

private void btAceptar_Click(object sender, EventArgs e)
{
if (i < 10)
{
Elementos[i] = int.Parse(tbDato.Text);
suma=suma + Elementos[i];
lbSalida.Items.Add(Elementos[i]);
i++;
tbDato.Clear();
tbDato.Focus();
}
else
{
MessageBox.Show("Los 10 datos fueron aceptados");
tbDato.Clear();
tbDato.Enabled = false;
btAceptar.Enabled = false;
}


}

private void btDesplegar_Click(object sender, EventArgs e)
{
int n = 0;
promedio=suma /10;
lbSalida.Items.Add("El promedio es "+promedio);
lbSalida.Items.Add("valores mayores o iguales a "+ promedio);
for (i = 0; i < 10; i++)
{
if (Elementos[i] >= promedio)
{
n++;
lbSalida.Items.Add(Elementos[i]);
}
}
lbSalida.Items.Add("El numero de elementos es " + n);
}

private void btLimpiar_Click(object sender, EventArgs e)
{
lbSalida.Items.Clear();
tbDato.Enabled = true;
btAceptar.Enabled = true;
i = 0;
}
}
}

No hay comentarios: