Wednesday, December 10, 2008

EJEMPLOS DE FICHEROS Y FLUJOS

EJEMPLO 1

using System;
using System.IO;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public class CEscribirBytes
{

public static void Main(string[] args)
{
FileStream fs = null;
byte[] buffer = new byte[81];
int nbytes = 0, car;

try
{
//Crear un flujo hacia el fichero texto.txt
fs = new FileStream("C:\\Datos\\texto.txt", FileMode.Create, FileAccess.Write);
Console.WriteLine("Escriba el texto que desea almacenar en el fichero:");
while ((car = Console.Read()) != '\r' && nbytes < buffer.Length)
{
buffer[nbytes] = (byte)car;
nbytes++;
}

//Escribir la linea de texto en el fichero
fs.Write(buffer, 0, nbytes);
}
catch (IOException e)
{
Console.WriteLine("Error: " + e.Message);

}
Console.ReadLine();
}
}
}
}




EJEMPLO 2

using System;
using System.IO;
using System.Text;

namespace ConsoleApplication1
{
public class CLeerBytes
{
public static void Main(string[] args)
{
FileStream fe = null;
char[] cBuffer = new char[81];
byte[] bBuffer = new byte[81];
int nbytes;
try
{
// Crear un flujo desde el fichero texto.text
fe = new FileStream("C:\\Datos\\texto.txt", FileMode.Open, FileAccess.Read);
//Leer del fichero un linea de texto
nbytes = fe.Read(bBuffer, 0, 81);
//Crear un objeto string con el texto leido
Array.Copy(bBuffer, cBuffer, bBuffer.Length);
String str = new String(cBuffer, 0, nbytes);
// Mostrar el texto leido
Console.WriteLine(str);
}
catch (IOException e)
{
Console.WriteLine("Error: " + e.Message);
}
finally
{
//Cerrar el fichero
if (fe != null) fe.Close();
}
Console.ReadLine();
}
}
}


EJEMPLO 3

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


namespace ConsoleApplication1
{
public class CEscribirCars
{
static void Main(string[] args)
{
StreamWriter sw = null;
string str;
try
{
//Crar un flujo hacia el fichero doc.txt
sw = new StreamWriter("C:\\Datos\\doc.txt");
Console.WriteLine("Escriba las lineas de texto a almacenar en el fichero.\n" + "Finalice cada linea pulsando la tecla .\n" + "Para finalizar solo pulse la tecla .\n");
//Leer la linea de la entrada estandar
str = Console.ReadLine();
while (str.Length != 0)
{
//Escribir la linea leida en el fichero
sw.WriteLine(str);
//Leer la linea siguiente
str = Console.ReadLine();
}
}
catch (IOException e)
{
Console.WriteLine("Error:" + e.Message);
}
finally
{
if (sw != null) sw.Close();
}




}
}
}


EJEMPLO 4

using System;
using System.IO;

public class CLeerCars
{
public static void Main(string[] args)
{
StreamReader sr = null;
String str;

try{
//Crear un flujo desde el fichero doc.txt
sr = new StreamReader("C:\\Datos\\doc.txt");
// Leer del fichero una linea de texto
str = sr.ReadLine();
while (str != null)
{
// Mostrar la linea leida
Console.WriteLine(str);
// Leer la linea siguiente
str = sr.ReadLine();
}
}
catch(IOException e)
{
Console.WriteLine("Error: " + e.Message);
}
finally
{
// cerrar el fichero
if (sr != null) sr.Close();
}
Console.ReadLine();
}
}

CLASES FILE, DIRECTORY Y PATH

ESTAS CLASES SOPORTAN MANIPULACION DEL NOMBRE DE UN FICHERO O DE UN DIRECTORI QUE PUEDE EXISTIR EN EL SISTEMA DE FICHEROS DE LA MAQUINA, POR LO TANTO, SUS METODOS PERMITIRAN INTERROGAR AL SISTEMA SOBRE TODAS LAS CARACTERISTICAS DE ESE FICHERO O DIRECTORIO. TODOS LOS METODOS DE ESTAS CLASES SON STATIC PARA QUE PUEDAN SER INVOCADOS SIN NECESIDAD DE QUE EXISTA UN OBJETO DE ELLAS.

PARA REFEIRNOS A UN FICHERO O UN DIRECTORIO, LO MAS SNCILLO ES FORMAR UN STRING A PARTIR DE SU NOMBRE AL QUE PODEMOS AÑADIR OPCIONALMENTE SU RUTA DE ACCESO.

FLUJOS

LOS FLUJOS SON OBJETOS INTERMEDIARIOS ENTRE EL PROGRAMA Y EL ORIGEN DE LA INFORMACION, DE TAL FORMA EL PROGRAMA LEERE O ESCRIBIRA SOBRE EL FLUJO SIN SABER DONDE PUEDE IR LA INFORMACION. PARA PODER REALIZAR ESTAS ACCIONES SE EMPLEAN CLASES YA DISEÑADAS POR LA BIBLIOTECA.NET PARA PODER LEER O ESCRIBIR POR EJEMPLO EXISTE FILESTREAM,STREAMWRITER,BINARYREADER Y BINARYWRITER.


LOS FLUJOS PUEDEN SER ESCRITOS O LEIDOS DE UN FICHERO CARACTER A CARACTER EN UN FORMATO PORTABLE UTILIZANDO FLUJOS DE LAS CLASES STREAMWRITER Y STREAMREADER
EN UN

Practica 11 VISUAL VARIAS FORMAS




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

namespace chaviuxprograma
{
class circulo
{double radio;
public circulo(double rad)
{
radio = rad;
}

public circulo()
{
radio = 1;
}
public double Radio
{
get{return radio ;}
set{radio = value ;}
}

public double area()
{
return Math.PI * Math.Pow(radio,2);
}

public double perimetro()
{
return 2 * Math.PI * radio;
}


}
}
class rectangulo
{
double ancho, largo;

public rectangulo (double anc, double lar)
{
ancho = anc;
largo = lar;
}

public rectangulo()
{
ancho = 1;
largo = 1;
}

public double Largo
{
get{return largo;}
set{largo = value;}
}
public double Ancho
{
get{return ancho;}
set{ancho = value;}

}

public double area()
{
return largo * ancho;
}

public double perimetro()
{
return 2 * (largo + ancho);
}

}
class triangulo
{
double lado1, lado2, lado3;

public triangulo (double lad1,double lad2,double lad3)
{
lado1 = lad1;
lado2 = lad2;
lado3 = lad3;
}

public triangulo()
{
lado1 = 1;
lado2 = 1;
lado3 = 1;
}

public double Lado1
{
get {return lado1;}
set{lado1 = value;}
}

public double Lado2
{
get {return lado2;}
set{lado2 = value;}
}

public double Lado3
{
get {return lado3;}
set{lado3 = value;}
}

public double area()
{
return Math.Sqrt(((lado1 + lado2 + lado3) / 2) * (((lado1 + lado2 + lado3) / 2) - lado1) * (((lado1 + lado2 + lado3) / 2) - lado2) * (((lado1 + lado2 + lado3) / 2) - lado3));
}
public double perimetro()
{
return lado1 + lado2 + lado3;
}
public double Altura()
{
return (Lado1 + lado2 + lado3) / 3;
}


}

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

namespace chaviuxprograma
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form f2 = new Form2();
f2.Show();
}

private void button2_Click(object sender, EventArgs e)
{
Form f3 = new Form3();
f3.Show();
}

private void button3_Click(object sender, EventArgs e)
{
Form f4 = new Form4();
f4.Show();
}

private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

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

namespace chaviuxprograma
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
label1.Text = "Circulo";

}

private void button1_Click(object sender, EventArgs e)
{
circulo ci = new circulo();

ci.Radio = double.Parse(textBox1.Text);
listBox1.Items.Add("Dato ingresado:" + ci.Radio);
listBox1.Items.Add("\n");
listBox1.Items.Add("\nArea =" + ci.area().ToString());
listBox1.Items.Add("\n");
listBox1.Items.Add("\nPerimetro = " + ci.perimetro().ToString());
textBox1.Focus();
textBox1.Clear();



}

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

Tuesday, December 2, 2008

examen 3 era unidad

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

namespace EXAMEN_3ERA_UNIDAD
{

public class PUNTO
{
public int x1, x2, y1, y2;
public PUNTO() { }

public PUNTO(int x1, int x2, int y1, int y2)
{
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
public virtual double area()
{
return 0;

}
public virtual double distancia()
{

return 0;

}
public class CIRCULO : PUNTO
{
public int X1, X2, Y1, Y2;
public double radio;
public CIRCULO()
{
}



public CIRCULO(int x1, int x2, int y1, int y2)
: base(x1, x2, y1, y2)
{
X1 = x1;
X2 = x2;
Y1 = y1;
Y2 = y2;
}
public void Radio(double radio)
{
this.radio = radio;
}


public override double distancia()
{
return Math.Sqrt((Math.Pow((X2 - X1), 2)) + (Math.Pow((Y2 - Y1), 2)));
//Math.Sqrt((X2 - X1)* 2 + (Y2 -Y1)* 2);
}


public override double area()
{

return Math.PI * Math.Pow(radio, 2);
}



}

}
}

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

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

double radio;


Console.Write("Introduce x1: ");
int x1=Int32.Parse(Console.ReadLine());

Console.Write("Introduce x2: ");
int x2=Int32.Parse(Console.ReadLine());

Console.Write("Introduce y1: ");
int y1=Int32.Parse(Console.ReadLine());

Console.Write("Introduce y2: ");
int y2=Int32.Parse(Console.ReadLine());
PUNTO p = new PUNTO(x1, x2, y1, y2);
CIRCULO circ2 = new CIRCULO();
CIRCULO circ = new CIRCULO();

Console.Write("Captura Radio x1y1: ");
double radio1 = Double.Parse(Console.ReadLine());
circ2.Radio(radio1);
Console.Write("Captura Radio x2y2: ");
radio = Double.Parse(Console.ReadLine());
circ.Radio(radio);

Console.WriteLine("\nel area del circulo x1y1 : {0}", circ.area());
Console.WriteLine("\nel area del circulo x1y1 : {0}", circ2.area());
Console.WriteLine("\nla distancia de estos circulos por las rectas x1y1 y y1y2 es : {0}", circ.distancia());
Console.ReadLine();

}
}
}

Friday, November 21, 2008

EXAMEN 2 CONSOLA

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

class Estudiante
{
public int identificador;
float[] calificaciones;
int total;


public Estudiante()
{
total = 0;
calificaciones = new float[5];
identificador = 0;


}
public void noidentificacion()
{
Console.WriteLine("introduce el numero de identificacion");
identificador = Convert.ToInt16(Console.ReadLine());
}
public void calificacion()
{
for (int i = 0; i < 5; i++)
{
Console.WriteLine("introduce la Calificacion {0}:", i+1);
calificaciones[i] = Convert.ToSingle(Console.ReadLine());
total=total+(int)calificaciones[i];
}
}
public void Promedio()
{
double prom;
prom=(double)total/5;
Console.WriteLine("el promedio es: {0}", prom);
}



}


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

namespace examen_2
{
class Program
{
static void Main(string[] args)
{
Estudiante est = new Estudiante();

est.noidentificacion();
est.calificacion();
est.Promedio();
Console.ReadLine();
}
}
}

Friday, October 31, 2008

EXAMEN CONSOLA, VISUAL Y DIAGRAMA




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


int[,] Matriz;
string[] Nombres;
int R, C;
int M, N,renglon;
int mayor = 0;

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

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

txtproduccion.Focus();


}

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


if (C == N)

{
C = 0;
R++;
txtplantan.Enabled = true;
txtplantan.Clear();
}
if (R != M)
{
txtnplanta.Text = (R + 1).ToString();
textBox4.Text = (C + 1).ToString();
txtproduccion.Clear();

txtproduccion.Focus();

}
else
{
txtnplanta.Enabled = false;
textBox4.Enabled = false;
txtproduccion.Enabled = false;
txtplantan.Enabled = false;
MessageBox.Show("Todos los datos fueron introducidos");
}
}
}

private void button3_Click(object sender, EventArgs e)
{
int Suma = 0;
lstagregar.Items.Add("No.Planta Planta Produccion semanal");
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++)
{
lstagregar.Items.Add((R + 1).ToString() + " " + Nombres[R] + " " + Matriz[R, N].ToString());

}
for (R = 0; R < M; R++)
{
Suma = Matriz[R, N];
if (Suma > mayor)
{
mayor = Matriz[R, N];
renglon = R;
}
}
lblNumplant.Text=" El numero de Planta con mayor produccion es:"+ (renglon + 1);
lblNombplant.Text="Nombre de la Planta:" + Nombres[renglon];
lblMayorprod.Text="Total de la produccion es:"+ mayor;
}

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


}
}







DIAGRAMA DE FLUJO DE EXAMEN








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

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

string[] nombres = new string[8];
int[,] produccion = new int[8, 7];
int suma=0;
int mayor = 0;
int mayor_planta=0;
Console.WriteLine("Examen");


for (int i = 0; i < 8; i++)
{


Console.Write("Captura nombre de la planta {0} ",i+1);
nombres[i] = Console.ReadLine();
}

for ( int j=0; j<8;j++){
Console.Clear();
Console.WriteLine("Planta {0}", nombres[j]);
for (int a = 0; a < 7; a++)
{


Console.Write("Captura la produccion dia {0} :", a + 1);
produccion[j, a] = System.Int32.Parse(Console.ReadLine());
}
Console.Clear();

}
//for (int i = 0; i < 8; i++)
//{
// Console.Write("{0}", nombres[i]);
//}
for (int j = 0; j < 8; j++)
{

suma = 0;
for (int a = 0; a < 7; a++)
{

Console.WriteLine("dia{0} produccion {1}", a + 1, produccion[j, a]);
suma = suma + produccion[j, a];
}

Console.WriteLine("\nProduccion total de planta {0} : {1} ", nombres[j], suma);
produccion[j,6]=suma;

}
Console.ReadLine();
Console.Clear();


mayor=0;
for (int j = 0; j < 8; j++)
{
if( produccion[j,6] < mayor){
mayor = produccion[j, 6];
mayor_planta=j;
}
}

Console.WriteLine("La planta con mayor produccion es {0}", nombres[mayor_planta]);
Console.ReadLine();
Console.WriteLine("Presione Intro para salir");

}
}
}

EXAMEN CONSOLA

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

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

string[] nombres = new string[8];
int[,] produccion = new int[8, 7];
int suma=0;
int mayor = 0;
int mayor_planta=0;
Console.WriteLine("Examen");


for (int i = 0; i < 8; i++)
{


Console.Write("Captura nombre de la planta {0} ",i+1);
nombres[i] = Console.ReadLine();
}

for ( int j=0; j<8;j++){
Console.Clear();
Console.WriteLine("Planta {0}", nombres[j]);
for (int a = 0; a < 7; a++)
{


Console.Write("Captura la produccion dia {0} :", a + 1);
produccion[j, a] = System.Int32.Parse(Console.ReadLine());
}
Console.Clear();

}
//for (int i = 0; i < 8; i++)
//{
// Console.Write("{0}", nombres[i]);
//}
for (int j = 0; j < 8; j++)
{

suma = 0;
for (int a = 0; a < 7; a++)
{

Console.WriteLine("dia{0} produccion {1}", a + 1, produccion[j, a]);
suma = suma + produccion[j, a];
}

Console.WriteLine("\nProduccion total de planta {0} : {1} ", nombres[j], suma);
produccion[j,6]=suma;

}
Console.ReadLine();
Console.Clear();


mayor=0;
for (int j = 0; j < 8; j++)
{
if( produccion[j,6] < mayor){
mayor = produccion[j, 6];
mayor_planta=j;
}
}

Console.WriteLine("La planta con mayor produccion es {0}", nombres[mayor_planta]);
Console.ReadLine();
Console.WriteLine("Presione Intro para salir");

}
}
}

Thursday, October 30, 2008

Practica 5 Visual





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 frmPractica5visual : Form
{
public frmPractica5visual()
{
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];
}

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

private void frmPractica5_Load(object sender, EventArgs e)
{

}




}
}

Practica 8 consola

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

namespace Aplicacion_consola_tres_dimensionaes
{
class Program
{
static void Main(string[] args)
{
double[, ,] compañía;
int numS, noDep, dias;
Console.Write("Introduce el número de sucursales: ");
numS = int.Parse(Console.ReadLine());
Console.Write("Introduce el número de departamentos: ");
noDep = int.Parse(Console.ReadLine());
Console.Write("Introduce el número de dias : ");
dias = int.Parse(Console.ReadLine());
compañía = new double[numS, noDep, dias];
int p, s, t;
for (p = 0; p < numS; p++)
{
Console.WriteLine("Sucursal {0}: ", p + 1);
for (s = 0; s < noDep; s++)
{
Console.WriteLine("Departamento {0}: ", s + 1);
for (t = 0; t < dias; t++)
{
Console.Write(" dia {0}: ", t + 1);
compañía[p, s, t] = double.Parse(Console.ReadLine());
}
}
}
double suma = 0.0;
for (p = 0; p < numS; p++)
{
suma = 0.0;
for (s = 0; s < noDep; s++)
{
suma = 0.0;
for (t = 0; t < dias; t++)
{
suma += compañía[p, s, t];

}
Console.WriteLine("venta total por sucursal:{0}", suma);
}
Console.WriteLine(" No de Sucursal: {0} ", p + 1);
Console.WriteLine(" Venta Total es : {0} ", suma);
}

Console.ReadLine();

}
}
}

diagrama de flujo de practica 9

diagrama de flujo de practica 4

diagrama de flujo de practica 1

Practica 9 consola

Programa que capturas el numero de grupos, alumnos por cada grupo y calificaciones por alumno....para al ultimo sacar el promedio de cada alumno de cada grupo.



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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int ng=0,nalu=0,mat=0;
int suma=0;
double promedio=0;



Console.Write("Practica 9");
Console.Write("\n\n\nCaptura numero de grupos: ");
ng = System.Int32.Parse(Console.ReadLine());
Console.Write("\nCaptura numero de alumnos: ");
nalu = System.Int32.Parse(Console.ReadLine());
Console.Write("\nCaptura numero de materias por alumnos: ");
mat = System.Int32.Parse(Console.ReadLine());

int[, ,] kodex = new int[ng, nalu, mat];


for(int g=0; g < ng ; g++)
{
for(int a=0; a< nalu; a++)
{
Console.Clear();
Console.WriteLine("Calificaciones de los alumnos del grupo {0}", g + 1);
for(int m=0;m < mat;m++)
{


Console.Write("\nintroduce calificacion {0} de alumno {1}: ", m+1,a+1);
kodex[g, a, m] = System.Int16.Parse(Console.ReadLine());

}
}
}

for (int g=0; g < ng;g++){
Console.WriteLine("\nPromedios de los alumnos del grupo {0}", g + 1);
for(int a=0;a < nalu;a++){


suma = 0;
for(int m=0;m < mat;m++){

suma=suma+kodex[g,a,m];
}

promedio = suma / mat;

Console.WriteLine("promedio de alumno {0}: {1} ", a + 1, promedio);
}
}
Console.Write("\nPRESIONE INTRO PARA SALIR");
Console.ReadLine();


}
}
}

Diagrama de flujo de practica 6

Diagrama de flujo de practica 8

Wednesday, October 29, 2008

Practica 7 Consola

Programa que capturas el numero de estaciones cualesquieras y sus meses, capturando el responsable de cada estacion y su produccion, por ultimo desplegara la produccion de cada estacion y cual es la mas productiva..






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

namespace Aplicacion_Consola_Estaciones_de_trabajo
{

class ArregloUnidimensional
{
object[] lista;
public ArregloUnidimensional(int n)
{
lista = new object[n];
}
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 M, int N)
{
Matriz = new object[M, N];

}
public void asignarDato(int reng, int col, object dato)
{
Matriz[reng, col] = dato;
}
public object obtenerDato(int reng, int col)
{
return Matriz[reng, col];
}
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 estaciones : ");
int num = int.Parse(Console.ReadLine());
Console.Write("introduce el numero de meses a evaluar: ");
int meses = int.Parse(Console.ReadLine());
ArregloBidimensional B = new ArregloBidimensional (num, meses + 1);
ArregloUnidimensional nom = new ArregloUnidimensional (num);
int r, c, datoProd = 0;
for (r = 0; r < num; r++)
{
Console.Write("Nombre del responsable de la estacion {0}: ", r + 1);
datoNombre = Console.ReadLine();
nom.asignarDato(r, datoNombre);
suma = 0;
for (c = 0; c < meses; c++)
{
Console.Write("Produccion del mes {0} :", c + 1);
datoProd = int.Parse(Console.ReadLine());
B.asignarDato(r, c, datoProd);
suma = suma + datoProd;
}
B.asignarDato(r, c, suma);
}
int mayor = 0;
int renglon = 0;
for (r = 0; r < num; r++)
{
suma = (int)B.obtenerDato(r, meses);
if (suma > mayor)
{
mayor = (int)B.obtenerDato(r, meses);
renglon = r;
}
}
Console.WriteLine("\n\nEl numero de estacion con mayor produccion es {0}", renglon + 1);
Console.WriteLine("Nombre del responsable {0} ", nom.obtenerDato(renglon));
Console.WriteLine("Total de la produccion es {0}", mayor);

for (r = 0; r < num; r++)
{
Console.WriteLine("\n\nNo de estacion {0}", r + 1);
Console.WriteLine("Responsable {0}", nom.obtenerDato(r));
Console.WriteLine("Total de la produccion :{0} ", B.obtenerDato(r, meses));

}
Console.ReadLine();

}
}
}

Practica 7 Visual




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


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

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

private void button1_Click(object sender, EventArgs e)
{
M = int.Parse(txtestaciones.Text);
N = int.Parse(txtnmeses.Text);
Nombres = new string[M];
Matriz = new int[M, N + 1];
txtestaciones.Enabled = false;
txtnmeses.Enabled = false;
cmdaceptar.Enabled = false;
txtnestacion.Text = (R + 1).ToString();
txtnumeromeses.Text = (C + 1).ToString();

txtproduccion.Focus();


}

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


if (C == N)

{
C = 0;
R++;
txtresponsable.Enabled = true;
txtresponsable.Clear();
}
if (R != M)
{
txtnestacion.Text = (R + 1).ToString();
txtnumeromeses.Text = (C + 1).ToString();
txtproduccion.Clear();

txtproduccion.Focus();

}
else
{
txtnestacion.Enabled = false;
txtnumeromeses.Enabled = false;
txtproduccion.Enabled = false;
txtresponsable.Enabled = false;
MessageBox.Show("Todos los datos fueron introducidos");
}
}
}

private void button3_Click(object sender, EventArgs e)
{
int Suma = 0;
lstagregar.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++)
{
lstagregar.Items.Add((R + 1).ToString() + " " + Nombres[R] + " " + Matriz[R, N].ToString());

}
}

private void frmPractica7_Load(object sender, EventArgs e)
{

}




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

}
}

Diagrama de flujo de practica 7

Diagrama de flujo de practica 5