lunes, 9 de marzo de 2009

Practica Voltios


Class Arreglo:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practica_Voltios
{
class Arreglo
{
double[] vector;
//int i = 0;

public Arreglo()
{
vector = new double[10];
}
public Arreglo(int n)
{
vector = new double[n];
}

public void asignarDato(int j, double dato)
{
vector[j] = dato;
}

public double obtenerDato(int j)
{
return vector[j];
}
}
}
Class Program
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practica_Voltios
{
class Program
{
static void Main(string[] args)
{

Arreglo Corriente = new Arreglo();
Arreglo Resistencia = new Arreglo();
Arreglo Voltios = new Arreglo();
int i;

Console.WriteLine("**********Corriente**********\n");
for ( i = 0; i < 10; i++)
{
Console.Write("Captura el valor de Corriente {0}: ", i+1);
Corriente.asignarDato(i,double.Parse(Console.ReadLine()));
}

Console.WriteLine("\n**********Resistencia**********\n");
for (i = 0; i < 10; i++)
{
Console.Write("Captura el valor de Resistencia {0}: ", i + 1);
Resistencia.asignarDato(i, double.Parse(Console.ReadLine()));
}

Console.WriteLine("\nCorriente\tResistencia\tVoltios\n");
for (i = 0; i < 10; i++)
{
Console.WriteLine(" {0}\t x \t {1}\t =\t {2} ",Corriente.obtenerDato(i) ,Resistencia.obtenerDato(i), (Corriente.obtenerDato(i) * Resistencia.obtenerDato(i)));
}

Console.ReadLine();
}
}
}

miércoles, 4 de marzo de 2009

Practica Varianza

Class Arreglo:

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

namespace WindowsFormsApplication1
{
class Arreglo
{
double[] vector;
int i = 0;

public Arreglo()
{
vector = new double[10];
}
public Arreglo(int n)
{
vector = new double[n];
}

public void asignarDato(int j, double dato)
{
vector[j] = dato;
}

public double obtenerDato(int j)
{
return vector[j];
}

public double obtenerPromedio(int N)
{
double suma1 = 0.0;
for (i = 0; i < N; i++)
{
suma1 = suma1 + vector[i];
}
return suma1 / N;
}
public double Varianza(int n)
{
double sumatotal = 0.0;
double p = obtenerPromedio(n);
for (i = 0; i < n; i++)
{
sumatotal = sumatotal + Math.Pow((vector[i] - p), 2);

}
return sumatotal / (n - 1);
}
}
}


Class Form:

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

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Arreglo X;
int cantidad,i;
public Form1()
{
InitializeComponent();
i = 0;
}

private void tbCantidad_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter))
{
cantidad = int.Parse(tbCantidad.Text);
X = new Arreglo(cantidad);
tbDatos.Enabled = true;
tbDatos.Focus();
tbCantidad.Enabled = false;

}
}

private void Form1_Load(object sender, EventArgs e)
{

lbNum.Text = Convert.ToString(i+1);
tbCantidad.Focus();
tbDatos.Enabled = false;
}

private void tbDatos_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == Convert.ToChar(Keys.Enter))
{
if (i {

X.asignarDato(i, (double.Parse(tbDatos.Text)));
if (i < (cantidad - 1))
{
i++;
lbNum.Text = Convert.ToString(i + 1);

}
else
{
tbDatos.Enabled = false;

}

}
tbDatos.Clear();

}
}

private void btCalculos_Click(object sender, EventArgs e)
{
for (int j = 0; j < cantidad; j++)
{
lbxCalculos.Items.Add("Dato "+(j+1)+" : "+X.obtenerDato(j));
}

lbxCalculos.Items.Add("Promedio: "+X.obtenerPromedio(cantidad));
lbxCalculos.Items.Add("Varianza: " + X.Varianza(cantidad));
}


}
}