sábado, 22 de noviembre de 2008

examen 2 consola

using System;
using System.Collections.Generic;
using System.Text;

namespace Examen_2
{
class Estudiante
{
public int estudiante;
float[] calificacion;
int suma;

public Estudiante()
{
suma = 0;
calificacion = new float[5];
estudiante = 0;
}
public void identificacion()
{
Console.WriteLine("Numero de identificacion del alumno:");
estudiante = int.Parse(Console.ReadLine());
}
public void calificaciones()
{
for (int r = 0; r < 5; r++)
{
Console.WriteLine("Calificacion {0}:", r + 1);
calificacion[r] = int.Parse(Console.ReadLine());
suma = suma + (int)calificacion[r];
}
}
public void Promedio()
{
double Prom;
Prom = (double)suma / 5;
Console.WriteLine("El promedio es de: {0}", Prom);
}
class Program
{
static void Main(string[] args)
{
Estudiante e = new Estudiante();

e.identificacion();
e.calificaciones();
e.Promedio();
Console.ReadLine();
}
}
}
}


miércoles, 5 de noviembre de 2008

examen 1 consola

using System;
using System.Collections.Generic;
using System.Text;

namespace Aplicacion_Consola_
{

class ArregloUnidimensional
{
object[] Lista;
public ArregloUnidimensional(int D)
{
Lista = new object[D];
}
public void asignarDato(int Indice, object dato)
{
Lista[Indice] = dato;
}
public object obtenerDato(int Indice)
{
return Lista[Indice];
}
public object[] lista
{
get { return Lista; }
set { Lista = value; }
}
}
class ArregloBidimensional
{
object[,] Matriz;

public ArregloBidimensional(int N, int d)
{
Matriz = new object[N, d];

}
public void asignarDato(int nom, int plan, object dato)
{
Matriz[nom, plan] = dato;
}
public object obtenerDato(int nom, int plan)
{
return Matriz[nom, plan];
}
public object[,] matriz
{
get { return Matriz; }
set { Matriz = value; }
}

}
class Program
{
static void Main(string[] args)
{
object datoNombre;
int suma = 0;
Console.Write("Introduce el numero de Plantas: ");
int Numero = int.Parse(Console.ReadLine());
Console.Write("introduce el numero de Dias a evaluar: ");
int Dias = int.Parse(Console.ReadLine());
ArregloBidimensional B = new ArregloBidimensional(Numero, Dias + 1);
ArregloUnidimensional nom = new ArregloUnidimensional(Numero);
int I, J, datoProd = 0;
for (I = 0; I < Numero; I++)
{
Console.Write("Nombre de la Planta {0}: ", I + 1);
datoNombre = Console.ReadLine();
nom.asignarDato(I, datoNombre);
suma = 0;
for (J = 0; J < Dias; J++)
{
Console.Write("Produccion de los dias: {0} :", J + 1);
datoProd = int.Parse(Console.ReadLine());
B.asignarDato(I, J, datoProd);
suma = suma + datoProd;
}
B.asignarDato(I, J, suma);
}
int mayor = 0;
int renglon = 0;
for (I = 0; I < Numero; I++)
{
suma = (int)B.obtenerDato(I, Dias);
if (suma > mayor)
{
mayor = (int)B.obtenerDato(I, Dias);
renglon = I;
}
}
Console.WriteLine("\n\nEl numero de Planta con mayor produccion es {0}", renglon + 1);
Console.WriteLine("Nombre de la Planta: {0} ", nom.obtenerDato(renglon));
Console.WriteLine("Total de la produccion es {0}", mayor);

for (
I= 0; I < Numero; I++)
{
Console.WriteLine("\n\nNo de Plantas {0}:", I + 1);
Console.WriteLine("Nombre de la Planta {0}:", nom.obtenerDato(I));
Console.WriteLine("Total de la produccion :{0} ", B.obtenerDato(I,Dias));

}
Console.ReadLine();

}
}
}


Practica 7visual

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 FrmEjercicio7 : Form
{


int[,] Matriz;
string[] Nombres;
int R, C;
int M, N;

public FrmEjercicio7()
{
InitializeComponent();
R = C = 0;
M = N = 0;
}

private void button1_Click(object sender, EventArgs e)
{
M = int.Parse(textBox1.Text);
N = int.Parse(textBox2.Text);
Nombres = new string[M];
Matriz = new int[M, N + 1];
textBox1.Enabled = false;
textBox2.Enabled = false;
button1.Enabled = false;
textBox3.Text = (R + 1).ToString();
textBox4.Text = (C + 1).ToString();

textBox5.Focus();


}

private void button2_Click(object sender, EventArgs e)
{
if (R < M && C < N)
{
Matriz[R, C] = int.Parse(textBox5.Text);
Nombres[R] = textBox6.Text;
C++;
textBox6.Enabled = false;


if (C == N)

{
C = 0;
R++;
textBox6.Enabled = true;
textBox6.Clear();
}
if (R != M)
{
textBox3.Text = (R + 1).ToString();
textBox4.Text = (C + 1).ToString();
textBox5.Clear();

textBox5.Focus();

}
else
{
textBox3.Enabled = false;
textBox4.Enabled = false;
textBox5.Enabled = false;
textBox6.Enabled = false;
MessageBox.Show("Todos los datos fueron introducidos");
}
}
}

private void button3_Click(object sender, EventArgs e)
{
int Suma = 0;
listBox1.Items.Add("No. Estacion Responsable Produccion");
for (R = 0; R < M; R++)
{
Suma = 0;

for (C = 0; C < N; C++)
{
Suma += Matriz[R, C];
}
Matriz[R, C] = Suma;
}
for (R = 0; R < M; R++)
{
listBox1.Items.Add((R + 1).ToString() + " " + Nombres[R] + " " + Matriz[R, N].ToString());

}
}

}
}

Practica 6visual

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

namespace Ejercicio_6
{
public partial class FrmEjercicio6 : Form
{
public FrmEjercicio6()
{
InitializeComponent();
}

int[,] num = new int[4, 5];
int[] ordenar = new int[20];
int ren = 0;
int col = 0;
int p, i, m, r, c, j, k,me;
private void cmdtabla_Click(object sender, EventArgs e)
{

cmdnum.Enabled = true;
cmdtabla.Enabled = false;

//creacion de tabla aleatoria
Random aleatorio = new Random();

for (ren = 0; ren < 4; ren++)
{
for (col = 0; col < 5; col++)
{
num[ren, col] = aleatorio.Next(50);

txttabla.Text = txttabla.Text + num[ren, col] + "\t";
}
txttabla.Text = txttabla.Text + "\r\n";
}

}

private void cmdnum_Click(object sender, EventArgs e)
{
txttabla.Clear();
lblDespliegue.Visible = true;

for (p = 1; p <= 20; p++)
{
me = num[0, 0];
r = 0;
c = 0;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 5; j++)
{
if (num[i, j] < me)
{
me = num[i, j];
r = i;
c = j;
}
}
}
ordenar[k] = me;
num[r, c] = 9999;
k++;

}

for (k = 0; k < 20; k++)
{
txttabla.Text = txttabla.Text + ordenar[k].ToString() + ", ";
}

}

private void cmdLimpiar_Click(object sender, EventArgs e)
{
cmdtabla.Enabled = true;
cmdnum.Enabled = false;
lbltabla.Visible = true;
lblDespliegue.Visible = false;
txttabla.Text = "";
txttabla.Clear();

}

private void cmdSalir_Click(object sender, EventArgs e)
{
Close();
}

}
}

Practica 5visual

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

namespace Practica5_visual
{
public partial class FrmEjercicio5 : Form
{
public FrmEjercicio5()
{
InitializeComponent();
}
int NumA = 0, NumC = 0, R = 0, C = 0;
int Suma = 0,b=0;
string[] Nombres;
int[,] Calificaciones;
double[] Promedio;

private void cmdCapturar_Click(object sender, EventArgs e)
{





if (R < NumA)
{
if (b == 0)
{
Nombres[R] = txtNombre.Text;
lstNombres.Items.Add(Nombres[R].ToString());
txtNombre.Enabled = false;
b = 1;
}
if (C < NumC)
{
txtCalificaciones.Enabled = true;
Calificaciones[R, C] = System.Int16.Parse(txtCalificaciones.Text);
txtNota.Text=txtNota.Text.ToString()+","+Calificaciones[R,C].ToString()+"\t";
txtCalificaciones.Clear();
txtCalificaciones.Focus();
C++;

if (C == NumC)
{
txtNota.Text = txtNota.Text + "\r\n";
txtNombre.Enabled = true;
txtNombre.Clear();
txtNombre.Focus();
R++;
b = 0;
C = 0;
}

}

}



if (R == NumA)
{
txtNombre.Enabled = false;
txtCalificaciones.Enabled = false;
for (R = 0; R < NumA; R++)
{

Suma = 0;
for (C = 0; C < NumC; C++)
{
Suma = Suma + Calificaciones[R, C];

}
Promedio[R] = Suma / NumC;
lstPromedio.Items.Add(Promedio[R].ToString());
}

}

}





private void cmdLimpiar_Click(object sender, EventArgs e)
{
txtCalificaciones.Clear();
txtNombre.Clear();
txtNumA.Enabled = true;
txtNumC.Enabled = true;
lstNombres.Items.Clear();
lstPromedio.Items.Clear();
txtNota.Clear();
txtNumA.Clear();
txtNumC.Clear();
txtNumA.Focus();
}

private void cmdCap_Click(object sender, EventArgs e)
{
NumA = System.Int16.Parse(txtNumA.Text);
NumC = System.Int16.Parse(txtNumC.Text);
txtNumA.Enabled = false;
txtNumC.Enabled = false;

Nombres = new string[NumA];
Calificaciones = new int[NumA, NumC];
Promedio = new double[NumA];
}
}
}


Practica 4visual

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

namespace Prcatica4a_Visual
{

public partial class FrmEjercicio4 : Form
{
rectangulo rect;
circulo circ;
Triangulo trian;
public FrmEjercicio4()
{

rect = new rectangulo();
circ = new circulo();
trian = new Triangulo();
InitializeComponent();
txtanchorect.Text = "0";
txtlargorect.Text = "0";
}

private void cmdcalculo_Click(object sender, EventArgs e)
{

int opc=0;
opc = System.Int32.Parse(txtopcion.Text);


if (opc == 1)
{
txtlargorect.Visible = true;
txtanchorect.Visible = true;
lbllargo.Visible = true;
lbl12.Visible = true;
lblbase.Visible = true;
lblradio.Visible = true;
lblaltura.Visible = true;
txtanchorect.Focus();
rect.Ancho= Double.Parse(txtanchorect.Text);
rect.Largo = Double.Parse(txtlargorect.Text);


lblareas.Text = "Area = " +rect.area().ToString();
lblperimetros.Text = "Perimetro= " + rect.perimetro().ToString();

}
else if (opc == 2)
{

txtanchorect.Visible = true;
txtlargorect.Visible = true;
txtlargorect.Focus();
lblbase.Visible = true;
lbllargo.Visible = true;
trian.altura = Double.Parse(txtanchorect.Text);
trian.basetrieangulo = Double.Parse(txtlargorect.Text);
lblareas.Text = "El area del triangulo es: " + trian.areatriangulo().ToString();
}
else if (opc == 3)
{

txtlargorect.Focus();
lblradio.Visible = true;
txtlargorect.Visible = true;
circ.Radio = Double.Parse(txtlargorect.Text);
lblareas.Text = "El area del Circulo es: " + circ.Area().ToString();
lblperimetros.Text = "La circuferencia es: " + circ.Circunferencia().ToString();
}
else
{
MessageBox.Show("Tu opcion no esta en el menu....elige bien");
txtopcion.Focus();
txtopcion.Clear();

}

}


}
}

Practica 3visual

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 FrmEjercicio3 : Form
{
int Ceconomica = 10;
int i = 0;
int I = 10;
int[] avion = new int[30];
int Primerac = 0;
public FrmEjercicio3()
{
InitializeComponent();
}

private void cmdAvion_Click_1(object sender, EventArgs e)
{
if (PrimeraClase.Checked)
{
if (Primerac < 10)
{

label2.ForeColor = System.Drawing.Color.Green;
label2.Text="Asiento # "+ (i+ 1)+ " Primera Clase";

avion[Primerac] = 1;
Primerac++;
i++;

}

else
{
MessageBox.Show("Primera Clase Llena \n\nSi decea seleccione la opcion de Clase economica");
PrimeraClase.Enabled = false;
PrimeraClase.Checked = false;

}

}



if (Claseconomica.Checked)
{

if (Ceconomica < 30)
{

label3.ForeColor = System.Drawing.Color.Green;
label3.Text="Asiento # " + (I + 1) + " Clase Economica";
avion[Ceconomica] = 1;
Ceconomica++;
I++;


}

else
{


MessageBox.Show("Clase Economica Llena \n\nSi decea seleccione la opcion de Primera clase");
Claseconomica.Enabled = false;
Claseconomica.Checked = false;

}
}

}
}
}



Practica 2visual

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
{
double[] corriente;
double[] resistencia;
double[] potencia;
int i;
double total;
public Form1()
{
corriente = new double[10];
potencia = new double[10];
resistencia = new double[10] { 26, 40, 44, 50, 66, 89, 10, 32, 5, 18 };

i = 0;
total=0.0;
InitializeComponent();
lboxDesplegar.Items.Add("Corriente Resistencia Potencia ");
}


private void cmdAceptar_Click(object sender, EventArgs e)
{
if (i < 10)
{
corriente[i] = double.Parse(textBox1.Text);
potencia[i] = resistencia[i] * Math.Pow(corriente[i], 2);
total += potencia[i];
lboxDesplegar.Items.Add(corriente[i].ToString() + " " + resistencia[i] + " " + potencia[i]); textBox1.Clear();
textBox1.Focus();
i++;
}

else
{

lboxDesplegar.Items.Add(" Total potencia =" + total); MessageBox.Show("excede los 10 datos"); i = 0;
textBox1.Clear();
textBox1.Enabled = false;
}
}
}
}


martes, 4 de noviembre de 2008

Practica 1visual

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 FrmEjercicio1 : Form
{
double[] corriente;
double[] resistencia;
double[] potencia;
int I;

public FrmEjercicio1()
{
corriente = new double[10];
potencia = new double[10];
I =0;

InitializeComponent();
}

private void cmdAceptar_Click(object sender, EventArgs e)
{
if (I < 10)
{
corriente[I] = double.Parse(textBox1.Text);
lbDesplegar.Items.Add(corriente[I].ToString());
textBox1.Clear();
textBox1.Focus();

I = I + 1;
}
else
{
MessageBox.Show("Solo aceptan 10 datos");
}


}
}
}