lunes, 10 de mayo de 2010

practica11problema2 consola y visual

PSEUDOCODIGO

1.- Experimentos [4,7] double
R=0, C=0 int
Suma=0.0 double
For(R=0 to 3 step R=R+1)
{
Suma=0
Print "Introduce los ensayes del experimento ",(R+1)
For(C=0 to 5 step C=C+1)

{
Print "Ensaye", (C+1)
Read Experimentos [R,C]
Suma=Suma+Experimentos[R,C]

}
Experimentos [R,6]=Suma/6
}
Print "Reporte de Experimentos"
Print"Experimento R1 R2 R3 R4 R5 R6"
For(R=0 to 3 step R=R+1)
{
For(C=0 to 6 step C=C+1)
{Print R, Experimentos [R,C]}
}

CONSOLA

class Program
{
static void Main(string[] args)
{
double[,] experimentos = new double[4, 7];
int r = 0, c = 0;
double Suma;
for (r = 0; r < 4; r++)
{
Suma = 0;
Console.WriteLine("Introduce los ensayes del experimento: {0}", r + 1);
for (c = 0; c < 6; c++)
{
Console.WriteLine("ensaye {0}", c + 1);
experimentos [r,c]=double.Parse(Console.ReadLine());
Suma = Suma + experimentos[r, c];
}
experimentos[r, 6] = Suma / 6;
}
Console.WriteLine("\n EL REPORTE DE EXPERIMENTOS ");
Console.WriteLine("\nNo.Exp\tr1\tr2\tr3\tr4\tr5\tr6\tpromedio");
for (r = 0; r < 4; r++)
{
Console.WriteLine("");
Console.Write("{0}", r + 1);
for (c = 0; c < 7; c++)
{
Console.Write("\t{0}",experimentos[r, c]);
}
}
Console.ReadKey();
}
}
}


VISUAL


public partial class Form1 : Form
{
double[,] Experimentos = new double[4, 7];
int R,C;
double suma;
public Form1()
{
InitializeComponent();
R=0;
C = 0;
suma = 0;

}

private void button1_Click(object sender, EventArgs e)
{


if (R < 4)
{
if (C < 7)
{
Experimentos[R, C] = double.Parse(textBox1.Text);
label2.Text = "Experimentos [" + R.ToString() + "," + C.ToString() + "]:" + Experimentos[R, C].ToString();
suma = suma + Experimentos[R, C];
C ++;
textBox1.Clear();
textBox1.Focus();

}
else
{
R++;
C = 0;
Experimentos[R, 6] = suma / 6;

}

}
else
{
button1.Enabled = false;
textBox1.Enabled = false;
}

}




private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add("\n EL REPORTE DE EXPERIMENTOS ");
listBox1.Items.Add("\nNo.Exp\tR1\tR2\tR3\tR4\tR5\tR6\tPromedio");





listBox1.Items.Add("\t" + Experimentos[0, 0] + "\t" + Experimentos[0, 1] + "\t" + Experimentos[0, 2] + "\t" + Experimentos[0, 3] + "\t" + Experimentos[0, 4] + "\t" + Experimentos[0, 5] + "\t" + Experimentos[0, 6]);
listBox1.Items.Add("\t" + Experimentos[1, 0] + "\t" + Experimentos[1, 1] + "\t" + Experimentos[1, 2] + "\t" + Experimentos[1, 3] + "\t" + Experimentos[1, 4] + "\t" + Experimentos[1, 5] + "\t" + Experimentos[1, 6]);
listBox1.Items.Add("\t" + Experimentos[2, 0] + "\t" + Experimentos[2, 1] + "\t" + Experimentos[2, 2] + "\t" + Experimentos[2, 3] + "\t" + Experimentos[2, 4] + "\t" + Experimentos[2, 5] + "\t" + Experimentos[2, 6]);
listBox1.Items.Add("\t" + Experimentos[3, 0] + "\t" + Experimentos[3, 1] + "\t" + Experimentos[3, 2] + "\t" + Experimentos[3, 3] + "\t" + Experimentos[3, 4] + "\t" + Experimentos[3, 5] + "\t" + Experimentos[3, 6]);



}

private void button3_Click(object sender, EventArgs e)
{
textBox1.Focus();
textBox1.Clear();
listBox1.Items.Clear();
button1.Enabled = true;
textBox1.Enabled = true;
}

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

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

No hay comentarios:

Publicar un comentario