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

Practica 6 visual



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

namespace Ejercicio_47
{
public partial class frmEjercicio47 : Form
{
public frmEjercicio47()
{
InitializeComponent();
}
//Declaracion de variables globales y arreglo
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();
}

private void lblDespliegue_Click(object sender, EventArgs e)
{

}

private void txttabla_TextChanged(object sender, EventArgs e)
{

}
}
}

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

}
}
}

private void frmPrograma3_Load(object sender, EventArgs e)
{

}

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

}

}

Wednesday, October 22, 2008

Practica 6 consola

Programa en C# para seleccionar los valores en un arreglo 4 por 5 en números enteros en orden ascendente y que almacene los valores seleccionados en un arreglo unidimensional llamado ordenar.


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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,] m = new int[4, 5];
int[] ordenar = new int[20];
int i, j, r, c, p, me, k = 0;
Console.WriteLine("introduce los datos");
for (i = 0; i < 4; i++)
{
for (j = 0; j < 5; j++)
{

Console.Write("m[{0},{1}]:", i, j);
m[i, j] = int.Parse(Console.ReadLine());
}
}
for (p = 1; p <= 20; p++)
{
me = m[0, 0];
r = 0;
c = 0;
for (i = 0; i < 4; i++)
{
for (j = 0; j < 5; j++)
{
if (m[i, j] < me)
{
me = m[i, j];
r = i;
c = j;
}
}
}
ordenar[k] = me;
m[r, c] = 9999;
k++;
}

Console.WriteLine("elementos ordenados de la matriz ordenada");
for (k=0;k<20;k++)
{
Console.Write("{0,4}", ordenar[k]);
}
Console.ReadLine();
}



}
}

Thursday, October 16, 2008

Practica 5 Consola

Escribir un programa interactivo en C# que acepte como entrada cada nombre de estudiante y sus calificaciones, determinar la nota media de cada estudiante y escribir a continuación el nombre del estudiante, las notas de los exámenes y la media calculada.
Considere lo más general el problema, el usuario debe determinar el número de alumnos y el número de calificaciones que registra.



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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n, m, r, c;
double suma = 0;
string[] nombres;
double[,] notas;
Console.WriteLine("\nPrograma que indicas cuantos alumnos vas a introducir y sus calificaciones ");

Console.Write("\nintroduce el numero de alumnos registrados: ");
n = int.Parse(Console.ReadLine());

Console.Write("Introduce el numero de calificaciones a registrar por alumnnos: ");
m = int.Parse(Console.ReadLine());

nombres = new string[n];
notas = new double[n, m];
Console.WriteLine("Introduce los siguientes datos");

for (r = 0; r < n; r++)
{
Console.WriteLine("Nombre Alumno {0}", r + 1);
nombres[r] = Console.ReadLine();

for (c = 0; c < m; c++)
{
Console.WriteLine("Calificacion{0}", c + 1);
notas[r, c] = double.Parse(Console.ReadLine());
}
}
Console.WriteLine("Nombre Alumno Calificaciones Promedio");
;

for (r = 0; r < n; r++)
{
Console.Write("{0}", nombres[r]);
suma = 0.0;
for (c = 0; c < m; c++)
{
Console.Write("\t{0}", notas[r, c]);
suma = suma + notas[r, c];
}
Console.WriteLine("\t\t\t {0}", suma / m);
}
Console.WriteLine("dar intro para salir");
Console.ReadLine();
}
}
}

Practica 4 Visual





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 frmPractica4a : Form
{
rectangulo rect;
circulo circ;
Triangulo trian;
public frmPractica4a()
{

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

}

}

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





}

Monday, October 13, 2008

Practica 1 Visual





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

namespace Practica_1
// DIAZ CABALLERO JOSE SALVADOR
//PRACTICA 1
//PROGRAMA QUE CAPTURAS N NUMEROS Y SACAS EL MAYOR, MENOR Y DIFERENCIA

{
public partial class frmPractica1 : Form
{
public frmPractica1()
{
InitializeComponent();
}
// Declaracion de variables Globales
int N,mayor = 0, menor = 999, Dif;

int i = 0;
private void cmdCa_Click(object sender, EventArgs e)
{

N = System.Int16.Parse(txtrep.Text);
txtrep.Focus();
cmdCa.Visible = false;
cmdMayor.Visible = true;


}
private void cmdMayor_Click(object sender, EventArgs e)
{

// Asignacion de valores a las variables

lstCap.Items.Add(System.Int32.Parse(txtCap.Text));
txtCap.Focus();
txtCap.Clear();
i++;
if (i == N)
{
txtCap.Visible = false;
label1.Visible = false;
cmdMayor.Visible = false;
txtrep.Focus();
}
}

private void cmdmenor_Click(object sender, EventArgs e)
{
int emax;

for (i = 0; i < N; i++)
{
emax = System.Int16.Parse(lstCap.Items[i].ToString());
// El numero mayor
if (emax > mayor)

mayor = emax;


lblMayor.Text = "El mayor es: " + mayor.ToString();

// El numero menor
if (emax < menor)

menor = emax;

lblMenor.Text = "El menor es: " + menor.ToString();

// La diferiencia entre el mayor y el menor
Dif = mayor - menor;

lbldes.Text = "La diferencia es: " + Dif.ToString();

}
}

private void lstCap_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void cmdlimpiar_Click(object sender, EventArgs e)
{
txtrep.Focus();
txtCap.Clear();
lstCap.Items.Clear();
txtCap.Visible = true;
label1.Visible = true;
cmdMayor.Visible = true;
lblMayor.Text = "";
lblMenor.Text = "";
lbldes.Text = "";
cmdCa.Visible = true;
txtrep.Clear();


}

private void frmPractica1_Load(object sender, EventArgs e)
{

}

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






}
}

Practica 4 Consola

Hacer un programa en C# para crear una clase de rectángulo,clase círculo, clase de triángulo para calcular el área y perímetro de cada figura.

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

namespace Practica4a
{
class Rectangulo
{
double largo, ancho;
public Rectangulo(double w, double h)
{
ancho = w;
largo = h;
}
public Rectangulo()
{
ancho = 1;
largo = 1;
}
public double area()
{
return largo * ancho;
}
public double perimetro()
{
return 2 * (largo + ancho);
}
public double Ancho
{
get { return ancho; }
set { ancho = value; }
}
public double Largo
{
get { return largo; }
set { largo = value; }
}
}
class Triangulo
{

double Altura;
double Base;

public Triangulo(double h, double b)
{
Altura = h;
Base = b;
}
public Triangulo()
{
Altura = 0;
Base = 0;
}
public double areatriangulo()
{
return (Base * Altura) / 2;
}
public double altura
{
get { return Altura; }
set { Altura = value; }
}
public double basetrieangulo
{
get { return Base; }
set { Base = value; }
}
}
class circulo
{
double radio;

public circulo(double r)
{
radio = r;
}
public circulo()
{
radio = 1;
}
public double Area()
{
return Math.PI * Math.Pow(radio, 2);
}
public double Circunferencia()
{
return Math.PI * radio * 2;
}
public double Radio
{
get { return radio; }
set { radio = value; }
}
}






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

int opcion = 0;
char opc;
do{
Console.WriteLine("\nPROGRAMA QUE CALCULA AREA DE CIERTAS FIGURAS GEOMETRICAS");
Console.WriteLine("\nELIJA LA OPCION QUE DESEA HACER");

Console.WriteLine("\nSI DESEA SACAR AREA Y PERIMETRO DE RECTANGULO TECLEE 1");
Console.WriteLine("\nSI DESEA SACAR AREA Y DE UN TRIANGULO TECLEE 2");
Console.WriteLine("\nSI DESEA SACAR AREA Y CIRCUNFERENCIA DE UN CIRCULO TECLEE 3");
Console.Write("\nQue opcion elije:");
opcion = int.Parse(Console.ReadLine());


if (opcion == 1)
{
Console.Clear();
Console.WriteLine("CALCULO DEL AREA Y PERIMETRO DE UN RECTANGULO");
double L1, A1;
Console.WriteLine("\n\nDatos de un rectangulo ");
Console.Write("\n\nIntroduce el largo de un rectangulo : ");
L1 = double.Parse(Console.ReadLine());
Console.Write("Introduce el ancho de un rectangulo : ");
A1 = double.Parse(Console.ReadLine());
Rectangulo tresRect = new Rectangulo(A1, L1);

Console.WriteLine("\n ancho={0},largo={1} ", tresRect.Ancho, tresRect.Largo);
Console.WriteLine("\nArea={0} , perimetro= {1} ", tresRect.area(), tresRect.perimetro());


Console.ReadLine();


}
else if (opcion == 2)
{
Console.Clear();
Console.WriteLine("CALCULO DEL AREA DE UN TRIANGULO");
double base1, altura1;
Console.WriteLine("\n\nDatos del Triangulo ");
Console.Write("\n\nIntroduce la base de un Triangulo : ");
base1 = double.Parse(Console.ReadLine());
Console.Write("\n\nIntroduce la altura del Triangulo : ");
altura1 = double.Parse(Console.ReadLine());
Triangulo untriangulo = new Triangulo(altura1, base1);
Console.WriteLine("\nbase={0}, altura={1}", untriangulo.basetrieangulo, untriangulo.altura);
Console.WriteLine("\n Area={0} ", untriangulo.areatriangulo());

Console.ReadLine();
}
else if (opcion == 3)
{
Console.Clear();
Console.WriteLine("CALCULO DEL AREA Y CIRCUFERENCIA DE UN CIRCULO");
double Radio1;
Console.WriteLine("\n\nDatos del Circulo ");
Console.Write("\n\nIntroduce el radio del Circulo : ");
Radio1 = double.Parse(Console.ReadLine());
circulo uncirculo = new circulo(Radio1);
Console.WriteLine("\n Radio={0}", uncirculo.Radio);
Console.WriteLine("\n Area={0}, circuferencia={1}", uncirculo.Area(), uncirculo.Circunferencia());

Console.ReadLine();

}
else
{
Console.Clear();

Console.WriteLine("OPCION INCORRECTA.");
}

Console.WriteLine("Si desea continuar presione 's'");
opc = char.Parse(Console.ReadLine());

Console.Clear();



}


while (opc == 's' || opc == 'S') ;

}
}
}

Practica 3 diagrama de flujo

Practica 3 Consola

Una pequeña aerolínea acaba de comprar una computadora para su nuevo sistema automático de reservaciones. A usted se le ha pedido que programe el nuevo sistema. Usted debe escribir un programa que asigne los asientos, en cada vuelo, del único avión de la aerolínea (capacidad : 30 asientos).
su programa debe desplegar el siguiente menú de alternativas:
digite 1 para primera clase
digite 2 para económico

Si la persona digita 1, su programa debe asignar un asiento en la sección de primera clase (asientos del 1 al 10). Si la persona digita 2, su programa debe asignar un asiento en la sección económica (asientos 11 al 30). Su programa debe imprimir un pase de abordar que indique el número de asiento de la persona y si está en la sección de primera clase o en la sección económica del avión.
Utilice un arreglo con un solo subíndice para presentar los asientos del avión. Inicialice en cero todos los elementos del arreglo para indicar que todos los asientos estan vacíos.Mientras se asigna cada asiento, el valor de los elemntos correspondientes del arreglo se establece en 1, para indicar que el asiento ya no está disponible.
Por supuesto, su programa nunca debe asignar un asiento que ya está asignado. Cuando la sección de primera clase esta llena, su programa debe preguntar a la persona que se le coloque en la sección económica ( y viceversa).
Si acepta, entonces haga la asignación apropiada del asiento. Si no acepta, entonces despliegue el mensaje "el siguiente vuelo parte en tres horas".


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

namespace practica3
{
class arreglo
{
int[] datos;
int i, cPrimera, cEconomico;
public arreglo(int n)
{
datos = new int[n];
for (i = 0; i < 30; i++)
{
datos[i] = 0;
}
i = cPrimera = 0;
cEconomico = 10;
}
public void EstablecerDato(int j)
{
datos[j] = 1;
}
public int obtnerDato(int j)
{
return datos[j];
}
public int[] Datos
{
get { return datos; }
set { datos = value; }
}
public int I
{
get { return i; }
set { i = value; }
}
public int Cprimera
{
get { return cPrimera; }
set { cPrimera = value; }
}
public int Ceconomico
{
get { return cEconomico; }
set { cEconomico = value; }
}
}
class Program
{
public static void Main(string[] args)
{
int opcion;
char opc;
arreglo avion = new arreglo(30);
do
{
Console.Clear();
Console.WriteLine("\nBIENVENIDOS A AEROLINEAS VIUX ");
Console.WriteLine("\n CONTAMOS CON DOS TIPOS DE CLASES Y SON LAS SIGUIENTES....");


Console.WriteLine("\nPor favor, digite 1 para Premier ");
Console.WriteLine("\nPor favor digite 2 para normal");
Console.Write("\nque opcion desea ");
opcion = int.Parse(Console.ReadLine());

if (opcion == 1)
{
if (avion.Cprimera < 9)
{
avion.EstablecerDato(avion.Cprimera);
Console.WriteLine("\nNo de asiento {0}", avion.Cprimera + 1);
Console.WriteLine("pase de abordar clase premier");
avion.Cprimera++;
}
else
{
Console.WriteLine("Primera clase no tiene asientos disponibles");
Console.WriteLine("Desea en clase para pobres (s/n): ");
opc = char.Parse(Console.ReadLine());
if (opc == 's' || opc == 'S')
{
if (avion.Ceconomico < 30)
{
avion.EstablecerDato(avion.Ceconomico);
Console.WriteLine("\nNo de asiento {0}", avion.Ceconomico + 1);
Console.WriteLine("\npase de abordar clase normal");
avion.Ceconomico++;
}
}
else
{ Console.WriteLine("el siguiente vuelo parte en tres horas"); }
}
}
else
{
if (opcion == 2)
{
if (avion.Ceconomico < 29)
{
avion.EstablecerDato(avion.Ceconomico);
Console.WriteLine("No de asiento: {0} ", avion.Ceconomico + 1);
Console.WriteLine("pase de abordar de clase economica");
avion.Ceconomico++;
}
else
{
Console.WriteLine("Clase Economica no tiene asientos disponible ");
Console.WriteLine("desea en Primera clase (s/n) : ");
opc = char.Parse(Console.ReadLine());
if (opc == 's' || opc == 'S')
{
if (avion.Cprimera < 9)
{
avion.EstablecerDato(avion.Cprimera);
Console.WriteLine("No de asiento : {0} ", avion.Cprimera + 1);
Console.WriteLine("pase de abordar Primera clase");
avion.Cprimera++;
}
}
else
{
Console.WriteLine("el siguiente vuelo parte en tres horas");
}
}
}

else
{
Console.WriteLine("Presiono opcion equívocada");
}
}
Console.Write("deseas continuar (s/n) : ");
opc = char.Parse(Console.ReadLine());
}
while (opc == 'S' || opc == 's');


}
}
}

Thursday, September 25, 2008

diagrama de flujo de practica 2

Practica 2 VISUAL


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

namespace practica_2_visual
{
public partial class frmpractica2visual : Form
{
public frmpractica2visual()
{
InitializeComponent();
}
double[] corriente = new double[10];
double[] resistencia = new double[10] { 26, 40, 44, 50, 66, 89, 10, 32, 5, 18 };
double[] potencia = new double[10];
int i = 0;
double total = 0;

private void cmdcorriente_Click(object sender, EventArgs e)
{ //DIAZ CABALLERO JOSE SALVADOR
//PROGRAMACION ORIENTADA A OBJETOS
//PROFESORA COLUNGA
// PRACTICA 2
//asigancion de valores a variables

corriente[i]= double.Parse(txtcorriente.Text);
lstcorriente.Items.Add(corriente[i].ToString());
txtcorriente.Clear();
txtcorriente.Focus();
i++;

// condicion para cuando termine el ciclo de capturar, cacula potencia y total y aguega a las listas datos
if ( i ==10){
txtcorriente.Enabled=false;
cmdcorriente.Enabled=false;

for( i=0; i<10; i++){

potencia[i]= resistencia[i] * (Math.Pow(corriente[i] , 2));

total=total+ potencia[i];

lstpotencia.Items.Add(potencia[i].ToString());
lstresistencia.Items.Add(resistencia[i].ToString());
}
lblTotal.Text= "el total es: "+ total.ToString();

}


}

private void cmdLimpiar_Click(object sender, EventArgs e)
{
cmdcorriente.Enabled = true;
txtcorriente.Enabled = true;
lstresistencia.Items.Clear();
lstcorriente.Items.Clear();
lstpotencia.Items.Clear();
txtcorriente.Focus();
lblTotal.Text = "";

}

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


}
}

Practica 2

Escriba un programa que almacene los siguientes valores en un arreglo llamado resistencia: 26,40,44,50,66,89,10,32,5,18 .El programa debe crear dos arreglos llamados corriente y potencia, los cuales deberán ser capaces de almacenar diez numeros de doble precision. Emplendo una gaza for y una instruccion de entrada de datos por el teclado, haga que el programa acepte diez números introducidos por el usuario en el arreglo corriente al ejecutar el programa, el cual debe almacenar en el arreglo potencia el producto de los valores correspondiente al cuadrado del arreglo corriente y del arreglo resistencia ( por ejemplo, potencia[i]=resistencia[i]* Math.Pow(corriente[i],2) y desplegar la siguiente salida:Resistencia Corriente Potencia


using System;
using System.Collections.Generic;
using System.Text;
namespace practica2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("el shaviux production.......... present");
int i;
double total = 0;
double[]corriente = new double[10];
double[] resistencia = new double[10] { 26, 40, 44, 50, 66, 89, 10, 32, 5, 18 };
double [] potencia = new double[10];
for (i = 0; i < 10; i++)
{
Console.Write(" \n Corriente {0} ", i + 1);
corriente[i] = double.Parse(Console.ReadLine());
potencia[i] = resistencia[i] * corriente[i];
total = total + potencia[i];
}
Console.WriteLine("\n\n Corriente Resistencia Potencia ");
for (i = 0; i < 10; i++)
{
Console.WriteLine("{0,6} {1,14} {2,10}", corriente[i], resistencia[i], potencia[i]);
}
Console.WriteLine("el total es:"+ total);
Console.WriteLine("Dar INTRO para salir");
Console.ReadLine();




}
}
}

PRACTICA 1

PRACTICA 1
Escriba un programa para introducir N numeros enteros en un arreglo llamado emax y encuentre el máximo valor introducido. El programa debe contener sólo una gaza y el máximo,minimo y diferencia, debe determinarse al introducir los valores de los elementos del arreglo
using System;
using System.Collections.Generic;
using System.Text;
namespace practica1
{
class Program
{
static void Main(string[] args)
{
{
int N, mayor = 0, menor = 99999999, diferencia=0;
Console.Write("Introduce la cantidad de valores enteros : ");
N = int.Parse(Console.ReadLine());
int[] emax = new int[N];
int i;
Console.WriteLine(" introduzca los {0} valores enteros ", N);
for (i = 0; i < N; i++)
{
Console.Write(" dato {0} : ", i + 1);
emax[i] = int.Parse(Console.ReadLine());
if (emax[i] > mayor)
{
mayor = emax[i];
}
if (emax[i] < menor)
{
menor = emax[i];
}
diferencia=mayor-menor;
}
Console.WriteLine("El dato mayor es : {0}", mayor);
Console.ReadLine();
Console.WriteLine("El dato menor es: {0}", menor);
Console.ReadLine();
Console.WriteLine("La diferencia del mayor al menor es de: {0}", diferencia);
Console.ReadLine();

}
}
}
}

Monday, September 22, 2008

Practicas

Bienvenidos a mi blog aqui es donde mostraré algunos trabajos y cosas sobre Programacion Orienta a Objetos