martes, 2 de diciembre de 2008

examen 3 consola

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

namespace ConsoleApplication1
{
public class PUNTO
{
protected double x;
protected double y;
public PUNTO()
{
x = 0;
y = 0;
}
public double X
{
get { return x; }
set { x = value; }
}
public double Y
{
get { return y; }
set { y = value; }
}
public virtual double area()
{
return 0;
}
public double distancia(double x1, double y1, double x2, double y2)
{
return Math.Sqrt((Math.Pow((x2 - x1), 2)) + (Math.Pow((y2 - y1), 2)));
}
}
public class circulo : PUNTO
{
double radio;
public circulo()
{
radio = 0;
x = 0;
y = 0;
}
public double Radio
{
get { return radio; }
set { radio = value; }
}
public override double area()
{
return Math.PI*(Math.Pow(radio, 2));
}
}
}


class Program
{
static void Main(string[] args)
{
circulo c1 = new circulo();
Console.WriteLine("Introduce los datos del circulo 1");
Console.Write("X: ");
c1.X = double.Parse(Console.ReadLine());
Console.Write("Y: ");
c1.Y = double.Parse(Console.ReadLine());
Console.Write("Radio: ");
c1.Radio = double.Parse(Console.ReadLine());
circulo c2 = new circulo();
Console.WriteLine("\nIntroduce los datos del circulo 2");
Console.Write("X: ");
c2.X = double.Parse(Console.ReadLine());
Console.Write("Y: ");
c2.Y = double.Parse(Console.ReadLine());
Console.Write("Radio: ");
c2.Radio = double.Parse(Console.ReadLine());
Console.WriteLine("\nResultado");
Console.WriteLine("Area circulo 1: {0}", c1.area());
Console.WriteLine("Area circulo 2: {0}", c2.area());
Console.WriteLine("Distancia entre los puntos: {0}", c1.distancia(c1.X, c1.Y, c2.X, c2.Y));
Console.ReadLine();
}
}
}


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();

}

}


}
}