Sei sulla pagina 1di 43

UNIVERSIDAD PARA EL DESARROLLO ANDINO

Anti hatun yachay wasi iskay simi yachachiypi umalliq

FACULTAD DE CIENCIAS E INGENIERÍA

ESCUELA PROFESIONAL: INGENIERÍA INFORMÁTICA

 CURSO : Lenguaje de Programacion I

 DOCENTE : Ing. Agripino Quispe Ramos

 CICLO :V

 ALUMNNO : CHOQUE ESCOBAR, Cliver

LIRCAY - HUANCAVELICA

2017
EJEMPLO 1

Sumatoria de Dos Numeros

Desarrollar un programa que consiste aprender a utilizar TextBox que nos permita
introducir numero decimal para realizar una sumatoria de dos numeros. Para lo cual
ud. Debe utilizar las siguientes herramientas como:

INSERTAR

4 Label

4 TextBox

1 GroupBox

2 Button

Boton Calcular

private void button1_Click(object sender, EventArgs e)


{
try
{
double a, b, suma;
a = double.Parse(textBox1.Text);
b = double.Parse(textBox2.Text);
suma = (a + b);
textBox3.Text = textBox1.Text + "+" + textBox2.Text;
textBox4.Text = suma.ToString();
}
catch (Exception ex)
{
MessageBox.Show("solo se permiten numeros: " + "\n excepcion:
" + ex.Message);
textBox1.Focus();
return;
}
}

Botón Limpiar
private void button2_Click_1(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox1.Focus();
}

EJEMPLO 2

Calculadora Elemental

Diseñe en el lenguaje C# una calculadora elemental que permita hacer las


operaciones matemáticas como: +,-,*,/. Para lo cual ud. Debe utilizar las
siguientes herramientas como:

INSERTAR

2 Label

3 TextBox

2 GroupBox

6 Button

Boton Suma

private void button3_Click(object sender, EventArgs e)


{
if (string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("falta ingresar n°1");
textBox1.Focus();
return;
}
if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("falta ingresar n°2");
textBox2.Focus();
return;
}
label1.Text = "+";
int A, B, SUMA;
A = int.Parse(textBox1.Text);
B = int.Parse(textBox2.Text);
SUMA = (A + B);
textBox3.Text = SUMA.ToString();
}

Botón Resta

private void button4_Click(object sender, EventArgs e)


{
if (string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("falta ingresar n°1");
textBox1.Focus();
return;
}
if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("falta ingresar n°2");
textBox2.Focus();
return;
}
label1.Text = "-";
int A, B, RESTA;
A = int.Parse(textBox1.Text);
B = int.Parse(textBox2.Text);
RESTA = (A - B);
textBox3.Text = RESTA.ToString();
}

Botón Multiplicar

private void button5_Click(object sender, EventArgs e)


{
if (string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("falta ingresar n°1");
textBox1.Focus();
return;
}
if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("falta ingresar n°2");
textBox2.Focus();
return;
}
label1.Text = "*";
int A, B, PRODUCTO;
A = int.Parse(textBox1.Text);
B = int.Parse(textBox2.Text);
PRODUCTO = (A * B);
textBox3.Text = PRODUCTO.ToString();
}

Botón División

private void button6_Click(object sender, EventArgs e)


{
if (string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("falta ingresar n°1");
textBox1.Focus();
return;
}
if (string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("falta ingresar n°2");
textBox2.Focus();
return;
}
label1.Text = "/";
double A, B, DIVISION;
A = int.Parse(textBox1.Text);
B = int.Parse(textBox2.Text);
DIVISION = (A / B);
textBox3.Text = DIVISION.ToString();
}

Botón Cerrar

private void button2_Click(object sender, EventArgs e)


{
Close();
}

Botón Nuevo

private void button1_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox1.Focus();
}

EJEMPLO 3

Calcular Mayor Número

Realizar una aplicación al ingresar dos números enteros que devuelva el número
mayor, para lo cual aplicar la estructura if, y debe utilizar las siguientes
herramientas como:

INSERTAR

3 Label
3 TextBox

3 Button

Boton Calcular

private void button2_Click(object sender, EventArgs e)


{
try
{
int a, b;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
if (a > b)
{
textBox3.Text = a.ToString();
}
if (b > a)
{
textBox3.Text = b.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show("solo se permiten numeros: " + "\n excepcion: " +
ex.Message);
}
}

Botón Nuevo

private void button1_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox1.Focus();
}

Botón Cerrar

private void button3_Click(object sender, EventArgs e)


{
Close();
}
EJEMPLO 4

Programa de Ventas

Debe utilizar las siguientes herramientas como:

INSERTAR

5 Label

5 TextBox

1 GroupBox

3 Button

Boton Calcular

private void button1_Click(object sender, EventArgs e)


{
double n1, n2, subtotal, igv, total;
n1 = double.Parse(textBox1.Text);
n2 = double.Parse(textBox2.Text);
subtotal = n1 * n2;
textBox3.Text = subtotal.ToString();
igv = subtotal * 18 / 100;
textBox4.Text = igv.ToString();
total = subtotal + igv;
textBox5.Text = total.ToString();
}

Botón Nuevo

private void button2_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox1.Focus();
}

Botón Cerrar

private void button3_Click(object sender, EventArgs e)


{
Close();
}

EJEMPLO 5

Calculadora

Debe utilizar las siguientes herramientas como:

INSERTAR

1 TextBox

19 Button

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace sumatoria_de_2_numeros
{
public partial class CALCULADORA : Form
{
public CALCULADORA()
{
InitializeComponent();
}
//Numeros de la calculadora
bool secuencia = true, punto = true;
string operacion;
double numero1, numero2, resultado, Signos;

Botón Uno

private void btn1_Click(object sender, EventArgs e)


{
if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "1";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "1";
}
}

Botón Dos

private void btn2_Click(object sender, EventArgs e)


{

if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "2";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "2";
}
}

Botón Tres

private void btn3_Click(object sender, EventArgs e)


{
if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "3";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "3";
}
}

Botón Cuatro

private void btn4_Click(object sender, EventArgs e)


{
if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "4";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "4";
}
}

Botón Cinco

private void btn5_Click(object sender, EventArgs e)


{
if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "5";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "5";
}
}
Botón Seis

private void btn6_Click(object sender, EventArgs e)


{
if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "6";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "6";
}
}
Botón Siete

private void btn7_Click(object sender, EventArgs e)


{
if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "7";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "7";
}
}
Botón Ocho

private void btn8_Click(object sender, EventArgs e)


{
if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "8";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "8";
}
}

Botón Nueve

private void btn9_Click(object sender, EventArgs e)


{
if (secuencia == true)
{
Pantalla.Text = "";
Pantalla.Text = "9";
secuencia = false;
punto = true;
}
else
{
Pantalla.Text = Pantalla.Text + "9";
}
}

Botón Cero

private void btnCero_Click(object sender, EventArgs e)


{
if (Pantalla.Text == "0")
{
return;
}
else
if (secuencia == true)
{
Pantalla.Text = "0";
}
else
{
Pantalla.Text = Pantalla.Text + "0";
}
//FIN NUMEROS DE LA CALCULADORA
//inicio de botones de operacion
}

Botón Suma
private void btnMaS_Click(object sender, EventArgs e)
{
operacion = "+";
numero1 = double.Parse(Pantalla.Text);
secuencia = true;
if (operacion == "+")
{
Pantalla.Text = Pantalla.Text + "+";
}
}

Botón Menos

private void btnMenos_Click(object sender, EventArgs e)


{
operacion = "-";
numero1 = double.Parse(Pantalla.Text);
secuencia = true;
}

Botón Por

private void btnPor_Click(object sender, EventArgs e)


{
operacion = "*";
numero1 = double.Parse(Pantalla.Text);
secuencia = true;

Botón División

private void btnDivision_Click(object sender, EventArgs e)


{
operacion = "/";
numero1 = double.Parse(Pantalla.Text);
secuencia = true;
}

Botón Raíz

private void btnRaizCuadrada_Click(object sender, EventArgs e)


{
numero1 = double.Parse(Pantalla.Text);
resultado = Math.Sqrt(numero1);
Pantalla.Text = resultado.ToString();
secuencia = true;
//BOTON IGUAL
}

Botón Igual

private void btnIgual_Click(object sender, EventArgs e)


{
numero2 = double.Parse(Pantalla.Text);
if (operacion == "+")
{
resultado = numero1 + numero2;
Pantalla.Text = resultado.ToString();
secuencia = true;
}
if (operacion == "-")
{
resultado = numero1 - numero2;
Pantalla.Text = resultado.ToString();
secuencia = true;
}

if (operacion == "*")
{
resultado = numero1 * numero2;
Pantalla.Text = resultado.ToString();
secuencia = true;
}
if (operacion == "/")
{
resultado = numero1 / numero2;
Pantalla.Text = resultado.ToString();
secuencia = true;
}
//INICIO DE LAS OPERACIONES ESPERCIALES
}

Botón Cerrar

private void btnBorrar_Click(object sender, EventArgs e)


{
Pantalla.Text = "0";
numero1 = 0;
numero2 = 0;
secuencia = true;
punto = true;
}

Botón Signo

private void signo_Click(object sender, EventArgs e)


{
Signos = double.Parse(Pantalla.Text);
Signos = Signos - (Signos * 2);
Pantalla.Text = Signos.ToString();
}

Botón Punto
private void btnPunto_Click(object sender, EventArgs e)
{
if (punto == true)
{
Pantalla.Text = Pantalla.Text + ".";
punto = false;
}
else
{
return;
}
secuencia = false;
}
}
}
EJEMPLO 6

Mayor y Menor de Tres Números

Desarrolle un pequeño programa de los 3 números Dados, de lo cual imprimir el


número mayor y menor. Para lo cual ud. Debe utilizar las siguientes herramientas
como:

INSERTAR

5 Label

5 TextBox

3 Button

Botón Calcular

private void button2_Click_1(object sender, EventArgs e)


{try
{
int a, b, c;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = int.Parse(textBox3.Text);
if (a > b && a > c)
{
textBox4.Text = a.ToString();
}
else
if (b > a && b > c)
{
textBox4.Text = b.ToString();
}
else
{
textBox4.Text = c.ToString();
}

if (a < b && a < c)


{
textBox5.Text = a.ToString();
}
else
if (b < a && b < c)
{
textBox5.Text = b.ToString();
}
else
{
textBox5.Text = c.ToString();
}
}
catch(Exception ex)
{
MessageBox.Show("solo se permiten numeros:" +"\nException:"+ ex.Message);
}
}

Botón Nuevo

private void button1_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox1.Focus();
}

Botón Cerrar
private void button3_Click(object sender, EventArgs e)
{
Close();
}

EJEMPLO 7

Promedio

Desarrollar un programa para controlar el promedio de las tres notas de la


Universidad. El Programa debe sacar automáticamente el puntaje, y el promedio y
si el promedio es menor que 10 debe mostrar desaprobado y si el promedio es mayor
que 10 debe mostrar aprobado. Para lo cual ud. Debe utilizar las siguientes
herramientas como:

INSERTAR

6 Label

6 TextBox

3 Button

Botón Calcular

private void button2_Click(object sender, EventArgs e)


{
double n1, n2, n3, pr,punt;
n1 = double.Parse(textBox1.Text);
n2 = double.Parse(textBox2.Text);
n3 = double.Parse(textBox3.Text);
punt = (n1 + n2 + n3);
pr = (n1 + n2 + n3) / 3.0;
textBox4.Text = punt.ToString();
textBox5.Text = pr.ToString();
if (pr > 10)
{
textBox6.Text = "APROBADO";
}
else
{
textBox6.Text = "DESAPROBADO";
}
}

Botón Nuevo

private void button1_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox6.Clear();
textBox1.Focus();
}

Botón Salir

private void button3_Click(object sender, EventArgs e)


{
Close();
}

EJEMPLO 8

Vocal

Desarrollar un programa que dado un carácter determinar si el vocal o no es vocal


utilizar estructura if….else. Para lo cual ud. Debe utilizar las siguientes
herramientas como:

INSERTAR

2 Label

2 TextBox

3 Button

Botón Verificar

private void button2_Click(object sender, EventArgs e)


{
string vocal = Convert.ToString(textBox1.Text);

if ((vocal == "A") || (vocal == "E") || (vocal == "I") || (vocal ==


"O") || (vocal == "U")||(vocal == "a") || (vocal == "e") || (vocal == "i") ||
(vocal == "o") || (vocal == "u"))
{
textBox2.Text="vocal";
}
else
{
textBox2.Text = "no esvocal";
}

}
Botón Nuevo

private void button1_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
}

Botón Cerrar

private void button3_Click(object sender, EventArgs e)


{
Close();
}

EJEMPLO 9

Par O Impar

Desarrollar un programa que dado un carácter determinar si el número es par o impar


utilizar estructura if….else. Para lo cual ud. Debe utilizar las siguientes
herramientas como:

INSERTAR

2 Label

2 TextBox

3 Button

Botón Verificar

private void button2_Click(object sender, EventArgs e)


{
int a = int.Parse(textBox1.Text);
if(a%2==0)
{
textBox2.Text=("par");
}
else
{
textBox2.Text = ("impar");
}
}

Botón Nuevo

private void button1_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
}

Botón Cerrar

private void button3_Click(object sender, EventArgs e)


{
Close();
}

CIUDADES

{
int a;
string b, resultado;
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToString(textBox2.Text);
if (((a >= 18) && (a <= 35) && (b == "masculino")))
{
resultado = "Arequipa";
textBox3.Text = Convert.ToString(resultado);
}

if (((a >= 36) && (a <= 75) && (b == "masculino")))


{
resultado = "Cuzco";
textBox3.Text = Convert.ToString(resultado);
}

if (((a >= 75) && (b == "masculino")))


{
resultado = "Iquitos";
textBox3.Text = Convert.ToString(resultado);
}

if (((a >= 18) && (a <= 35) && (b == "femenino")))


{
resultado = "Arequipa";
textBox3.Text = Convert.ToString(resultado);
}

if (((a >= 36) && (a <= 75) && (b == "fnemenio")))


{
resultado = "Cuzco";
textBox3.Text = Convert.ToString(resultado);
}

if (((a >= 75) && (b == "femenino")))


{
resultado = "Iquitos";
textBox3.Text = Convert.ToString(resultado);
}
}

CONTROL DE REGISTRO DE DOCUMENTO

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

namespace sumatoria_de_2_numeros
{
public partial class Comtrol_de_Registro_de_Documento : Form
{
public Comtrol_de_Registro_de_Documento()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)


{
int numero = int.Parse(textBox1.Text);
String empresa = textBox2.Text;
DateTime fecha = dateTimePicker1.Value;
int an = DateTime.Today.Year - fecha.Year;
String condicion="";
if (an<=5) condicion="Habilitado";
if (an<=5) condicion="Inahabilitado";
ListViewItem mostrar=new ListViewItem(numero.ToString());
mostrar.SubItems.Add(fecha.ToString("d"));
mostrar.SubItems.Add(empresa);
mostrar.SubItems.Add(an.ToString());
mostrar.SubItems.Add(condicion);
listView1.Items.Add(mostrar);
}

private void button1_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
}
}
}

CONTROL DE PAGO DE LOS EMPLEADOS

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

namespace sumatoria_de_2_numeros
{
public partial class Control_de_pago_de_empleados : Form
{
double sueldo = 0;
public Control_de_pago_de_empleados()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
comboBox1.Text = "(seleccione)";
textBox1.Clear();
textBox1.Focus();
}
private void label5_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult r = MessageBox.Show("estas seguro salir?", "UDEA",
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);if (r == DialogResult.Yes)
this.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
String categoria = comboBox1.Text;
if (categoria == "JEFE") sueldo = 3500;
if (categoria == "ADMINISTRATIVO") sueldo = 2500;
if (categoria == "TECNICO") sueldo = 1700;
if (categoria == "OPERARIO") sueldo = 1000;
label6.Text = sueldo.ToString("C");
}
private void label8_Click(object sender, EventArgs e)
{

private void Control_de_pago_de_empleados_Load(object sender, EventArgs


e)
{
label8.Text = DateTime.Today.Date.ToString("d");
}

private void button2_Click(object sender, EventArgs e)


{
String empleado = textBox1.Text;
String categ = comboBox1.Text;
double descuento = 0;
if (sueldo > 2500) descuento = sueldo * (12.5 / 100);
double neto = sueldo - descuento;
ListViewItem lista = new ListViewItem(empleado);
lista.SubItems.Add(categ);
lista.SubItems.Add(sueldo.ToString("c"));
lista.SubItems.Add(descuento.ToString("c"));
lista.SubItems.Add(neto.ToString("c"));
listView1.Items.Add(lista);
button1_Click(sender, e);
}
}
}
ESTACION DEL AÑO

private void numericUpDown1_ValueChanged(object sender, EventArgs e)


{
int mes;
mes = int.Parse(numericUpDown1.Text);
switch(mes)
{
case 1 : case 2 : case 3 :
textBox1.Text = ("verano");
break;
case 4 : case 5: case 6 :
textBox1.Text = ("otoño");
break;
case 7 : case 8: case 9 :
textBox1.Text = ("invierno");
break;
case 10 : case 11: case 12 :
textBox1.Text = ("primavera");
break;
default:
textBox1.Text=("no existe el numero");
break;
}
}
ESTADO CIVIL

private void button2_Click(object sender, EventArgs e)


{
string codigo, estadocivil;
codigo = Convert.ToString(textBox1.Text);
if (codigo == "0")
{
estadocivil = "Soltero";
textBox2.Text = Convert.ToString(estadocivil);
}
else
{
if (codigo == "1")
{
estadocivil = "Casado";
textBox2.Text = Convert.ToString(estadocivil);
}
else
{
if (codigo == "2")
{
estadocivil = "Divorciado";
textBox2.Text = Convert.ToString(estadocivil);
}
else
{
if (codigo == "3")
{
estadocivil = "Viudo";
textBox2.Text = Convert.ToString(estadocivil);
}
else
{
MessageBox.Show("solo se permiten numeros de 0 a 3");
}
}
}
}
}

TRABAJADOR POR UTILIDAD

private void button2_Click(object sender, EventArgs e)


{
int a;
string b, resultado;
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToString(textBox2.Text);
if ((a >= 0) && (a <= 2) && (b == "administrador"))
{
resultado = "2000";
textBox3.Text = Convert.ToString(resultado);
}
if ((a >= 3) && (a <= 5) && (b == "administrador"))
{
resultado = "2500";
textBox3.Text = Convert.ToString(resultado);
}
if ((a >= 6) && (a <= 8) && (b == "administrador"))
{
resultado = "3000";
textBox3.Text = Convert.ToString(resultado);
}
if ((a > 8) && (b == "administrador"))
{
resultado = "4000";
textBox3.Text = Convert.ToString(resultado);
}

if ((a >= 0) && (a <= 2) && (b == "contador"))


{
resultado = "1500";
textBox3.Text = Convert.ToString(resultado);
}
if ((a >= 3) && (a <= 5) && (b == "contador"))
{
resultado = "2000";
textBox3.Text = Convert.ToString(resultado);
}
if ((a >= 6) && (a <= 8) && (b == "contador"))
{
resultado = "2500";
textBox3.Text = Convert.ToString(resultado);
}
if ((a > 8) && (b == "contador"))
{
resultado = "3500";
textBox3.Text = Convert.ToString(resultado);
}

if ((a >= 0) && (a <= 2) && (b == "empleado"))


{
resultado = "1000";
textBox3.Text = Convert.ToString(resultado);
}
if ((a >= 3) && (a <= 5) && (b == "empleador"))
{
resultado = "1500";
textBox3.Text = Convert.ToString(resultado);
}
if ((a >= 6) && (a <= 8) && (b == "empleado"))
{
resultado = "2000";
textBox3.Text = Convert.ToString(resultado);
}
if ((a > 8) && (b == "empleado"))
{
resultado = "1500";
textBox3.Text = Convert.ToString(resultado);
}
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox1.Focus();
}
private void button3_Click(object sender, EventArgs e)
{
Close();
}

EJEMPLO 1

Una empresa de estacionamiento de autos de Lircay necesita un programa que permita


controlar el registro de los autos que diariamente ingresan al estacionamiento.
Los datos que necesita registrar el personal de control son el número de placa de
los autos, la hora de inicio y la hora de salida de los autos.

Usted se debe tener en cuenta los siguientes:

DIAS COSTO POR DIA

DOMINGO S/. 2.00

LUNES A JUEVES S/. 4.00

VIERNES A SABADO S/. 7.00

 Al inicio de programa debe mostrar la fecha actual, así como el costo por
hora según el día.
 La cantidad de horas que el vehículo se encuentra en el estacionamiento
resulta de la diferencia entre la hora de salida e inicio.
 El importe resulta del producto de la cantidad de hora de estacionamiento y
el costo por día.
 El botón registrar muestra el número de placa, fecha, hora de inicio, hora
final, cantidad de horas de estacionamiento, la tarifa según el criterio y
el importe a pagar por el cliente en un control de list viem.
private void diferencia(DateTime fecha_ini, DateTime fecha_fin, ref TimeSpan
dias)
{
dias = fecha_fin - fecha_ini;

BOTON REGISTRAR

private void button2_Click(object sender, EventArgs e)


{
DateTime fecha_ini = new DateTime();
DateTime fecha_fin = new DateTime();
TimeSpan dias = new TimeSpan();

fecha_ini = Convert.ToDateTime(textBox2.Text);
fecha_fin = Convert.ToDateTime(textBox3.Text);
this.diferencia(fecha_ini, fecha_fin, ref dias);
label9.Text = dias.Hours.ToString() + "." + dias.Minutes.ToString();

string placa = textBox1.Text;


string inicio = textBox2.Text;
string final = textBox3.Text;
string fecha = label8.Text;
double tarifa =Convert.ToDouble( label7.Text);
double interbalo=Convert.ToDouble (label9.Text );
double importe=tarifa *interbalo;
string thoras = label9.Text;

ListViewItem lista = new ListViewItem(placa);


lista.SubItems.Add(fecha);
lista.SubItems.Add( inicio);
lista.SubItems.Add(final);
lista.SubItems.Add(thoras);
lista.SubItems.Add(tarifa.ToString ("C"));
lista.SubItems.Add(importe .ToString ("C"));
listView1.Items.Add(lista);
button1_Click(sender, e);

private void Form1_Load(object sender, EventArgs e)


{
label8.Text = DateTime.Today.Date.ToString("d");
string a;
DateTime diahora = DateTime.Now;
a = diahora.DayOfWeek.ToString();
switch (a)
{
case "Monday":
case "Tuesday":
case "Wednesday":
case "Thursday":
label7.Text = ("4.00");
break;
case "Friday":
case "Saturday":
label7.Text = ("7.00");
break;
case "Sunday":
label7.Text = ("2.00");
break;
case "Lunes":
case "Martes":
case "Miércoles":
case "Jueves":
label7.Text = ("4.00");
break;
case "Viernes":
case "Sábado":
label7.Text = ("7.00");
break;
case "Domingo":
label7.Text = ("2.00");
break;
}
}

BOTON SALIR

private void button3_Click(object sender, EventArgs e)


{
Close();
}

EJEMPLO 2
El docente de la asignatura de lenguaje de programación I de la Universidad para
el Desarrollo Andino, necesita tener un control de registro de notas de sus
estudiantes. El docente registra tres evaluaciones hasta el examen de medio curso
según las normas de la escuela profesional y los promedia eliminando la nota baja
que el estudiante haya obtenido; es decir se promedian las dos notas más altas.
Para lo cual usted debe implementar una aplicación que permita mostrar la nota
menor, el promedio y la condición de los estudiantes.
La condición considera APROBADO a los estudiantes cuyo promedio sea mayor o igual
10.66, caso contrario se considera DESAPROBADO.
Se debe tener en cuenta los siguientes:
 Utilizar estructura if doble visto en la clase.
 Validar ingreso de los valores en los controles.
 Opción de ingreso de notas solamente debe aceptar registrar notas de 0 hasta
20 en enteros.
 Mostrar el registro de los estudiantes en herramienta List View.
 Los botones deben funcionar perfectamente sin ningún error.
 Diseñar interfaz gráfica de usuario de la siguiente manera:

private void Form2_Load(object sender, EventArgs e)


{
label4.Text = DateTime.Today.Date.ToString("d");
}

BOTON REGISTRAR

private void button2_Click(object sender, EventArgs e)


{
string condicion;
string est = textBox1.Text;
int ta = int.Parse(textBox2.Text);
int pc = int.Parse(textBox3.Text);
int pe = int.Parse(textBox4.Text);
string fecha = label4.Text;
int pr, r;

if ((((ta >= 0) && (ta <= 20) && (pc >= 0) && (pc <= 20) && (pe
>= 0) && (pe <= 20))))
if (ta < pc && ta < pe)
{
r = ta;
pr = (pc + pe) / 2;
}
else if (pc < pe)
{
r = pc;
pr = (ta + pe) / 2;
}
else
{
r = pe;
pr = (ta + pc) / 2;
}
else
{
MessageBox.Show("ingrese el notas de 1 al 20"); return;
}
ListViewItem lista = new ListViewItem(textBox1.Text);
lista.SubItems.Add(label4.Text);
lista.SubItems.Add(textBox2.Text);
lista.SubItems.Add(textBox3.Text);
lista.SubItems.Add(textBox4.Text);
listView1.Items.Add(lista);

if (ta < pc && ta < pe)


{
lista.SubItems.Add(ta.ToString());
}
if (pc < ta && pc < pe)
{
lista.SubItems.Add(pc.ToString());
}
if (pe < ta && pe < pc)
{
lista.SubItems.Add(pe.ToString());
}

lista.SubItems.Add(pr.ToString());

if(pr>=10.6)
{
condicion = "APROBADO";
lista.SubItems.Add(condicion.ToString());
}
else
{
condicion = "DESAPROBADO";
lista.SubItems.Add(condicion.ToString());
}
}

BOTON SALIR

private void button3_Click(object sender, EventArgs e)


{
Close();
}

BUCLE FOR

private void button1_Click(object sender, EventArgs e)


{
int x, n, suma = 0;
listBox1.Items.Clear();
n = int.Parse(textBox1.Text);
for (x=1; x<=n;x++)
{
suma = x;
listBox1.Items.Add("N;" + x);
}
}
private void button2_Click(object sender, EventArgs e)
{
int x, n, suma = 0;
listBox1.Items.Clear();
n = int.Parse(textBox1.Text);
for (x = 1; x <= n; x++)
{
suma = x;
listBox1.Items.Add("Nº: " + x);
}
listBox1.Items.Add("..............");
listBox1.Items.Add("suma total es: " + suma);
}

BUCLE WHILE

private void button2_Click(object sender, EventArgs e)


{
if (String.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("falta ingresar numero");
textBox1.Focus();
return;
}
int x = 1, n;
listBox1.Items.Clear();
n = int.Parse(textBox1.Text);
while (x<=n)
{

listBox1.Items.Add("Nº: " + x);


x++;
}
}
private void button3_Click(object sender, EventArgs e)
{
int x = 1, n, suma = 0;
listBox1.Items.Clear();
n = int.Parse(textBox1.Text);
while (x<=n)
{
suma += x;
listBox1.Items.Add("Nº: " + x);
x++;
}
listBox1.Items.Add("..............");
listBox1.Items.Add("suma total es: " + suma);
}

DO WHILE

private void button2_Click(object sender, EventArgs e)


{
if (String.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("falta ingresar numero");
textBox1.Focus();
return;
}
try
{
int x = 1, n;
n = Convert.ToInt32(textBox1.Text);

if (n < 0)
MessageBox.Show(" ingresar numeros positivos");
do
{
listBox1.Items.Add("Nº: " + x);
x++;
}
while (x <= n);
}
catch
{
MessageBox.Show("solo ingresar numeros: ");
}

}
private void button3_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("falta ingresar numero");
textBox1.Focus();
return;
}
int x = 1, n, suma = 0;
n = Convert.ToInt32(textBox1.Text);
do
{
suma += x;
x++;
}
while (x <= n);
listBox1.Items.Add("..........");
listBox1.Items.Add("suma total es: " + suma);
}
private void button1_Click(object sender, EventArgs e)
{
Close();
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Clear();
listBox1.Text = "";
textBox1.Focus();
}

ALQUILER DE HABITACION

private void Button2_Click(object sender, EventArgs e)


{
if(String.IsNullOrEmpty(MaskedTextBox1.Text))
{
MessageBox.Show("FALTA INGRESAR DIAS... "," AGRIPINO");
MaskedTextBox1.Focus();
return;

}
//CAPTURAR DATOS
String habitacion=ComboBox1.Text;
int dias=int.Parse(MaskedTextBox1.Text);
// asignacion de costo
double costo=0;
switch(habitacion)
{
case "SIMPLE":costo=30; break;
case "DOBLE":costo=50; break;
case "MATRIMONIAL":costo=120; break;
case "PRESIDENCIAL":costo=300; break;
}
//realizando calculos
DateTime fechas=DateTime.Parse(Label3.Text);
double importe=costo*dias;
double descuento =0;
if (dias <= 5)
descuento = 0;
else if (dias > 5 && dias <= 10)
descuento = 00.05 * importe;
else if (dias > 10 && dias <= 30)
descuento = 0.1 * importe;
else if (dias > 30)
descuento = 0.2 * importe;
double neto = importe - descuento;
//registrar datos
ListViewItem filas = new ListViewItem(habitacion);
filas.SubItems.Add(fechas.ToString("d"));
filas.SubItems.Add(costo.ToString("0.00"));
filas.SubItems.Add(dias.ToString());
filas.SubItems.Add(importe.ToString("0.00"));
filas.SubItems.Add(descuento.ToString("0.00"));
filas.SubItems.Add(neto.ToString("0.00"));
ListView1.Items.Add(filas);
int i=0;
int csimple=0, cdoble=0, cmatri=0,cpres=0;
double tsimple=0,tdoble=0,tmatri=0,tpres=0;
do {
string tipo = ListView1.Items[i].SubItems[0].Text;
switch(tipo)
{
case "SIMPLE":
csimple+=int.Parse( ListView1.Items[i].SubItems[3].Text);
tsimple+= double.Parse(
ListView1.Items[i].SubItems[6].Text);
break;
case "DOBLE":
cdoble+= int.Parse(
ListView1.Items[i].SubItems[3].Text);
tdoble+= double.Parse( ListView1.Items[i].SubItems[6].Text);
break;
case"MATRIMONIAL":
cmatri+=int.Parse(
ListView1.Items[i].SubItems[3].Text);
tmatri+= double.Parse( ListView1.Items[i].SubItems[6].Text);
break;
case"PRISIDENCIAL":
cpres+=int.Parse(
ListView1.Items[i].SubItems[3].Text);
tpres+= double.Parse( ListView1.Items[i].SubItems[6].Text);
break;
}
i++;
} while(i<ListView1.Items.Count);
//registrar resumen de datos
ListView2.Items.Clear();
string[] elementosfila=new string[3];
ListViewItem row;
elementosfila[0]="HABITACION SIMPLE";
elementosfila[1]=csimple.ToString();
elementosfila[2]=tsimple.ToString("c");
row=new ListViewItem (elementosfila);
ListView2.Items.Add(row);

elementosfila[0]="HABITACION DOBLE";
elementosfila[1]=cdoble.ToString();
elementosfila[2]=tdoble.ToString("c");
row=new ListViewItem (elementosfila);
ListView2.Items.Add(row);

elementosfila[0]="HABITACION MATRIMONIAL";
elementosfila[1]=cmatri.ToString();
elementosfila[2]=tmatri.ToString("c");
row=new ListViewItem (elementosfila);
ListView2.Items.Add(row);

elementosfila[0]="HABITACION PRESIDENCIAL";
elementosfila[1]=cpres.ToString();
elementosfila[2]=tpres.ToString("c");
row=new ListViewItem (elementosfila);
ListView2.Items.Add(row);
}

private void Button3_Click(object sender, EventArgs e)


{
ListView1.Items.Clear();
ListView2.Items.Clear();
}

private void Button1_Click(object sender, EventArgs e)


{
MaskedTextBox1.Text = "";
ComboBox1.Text = "";
ComboBox1.Focus();
}

private void button4_Click(object sender, EventArgs e)


{
Close();
}

private void Alquiler_de_Habitacion_Load(object sender, EventArgs e)


{
{
Label3.Text = DateTime.Today.Date.ToString("d");
Label10.Text = DateTime.Now.ToString("hh:mm:ss");
}

BUCLE FOR
private void button1_Click(object sender, EventArgs e)
{
int x, n, suma = 0;
listBox1.Items.Clear();
n = int.Parse(textBox1.Text);
for (x = 1; x <= n; x++)
{
suma = x;
listBox1.Items.Add("N;" + x);
}
}

private void button2_Click(object sender, EventArgs e)


{
int x, n, suma = 0;
listBox1.Items.Clear();
n = int.Parse(textBox1.Text);
for (x = 1; x <= n; x++)
{
suma += x;
listBox1.Items.Add("Nº: " + x);
}
listBox1.Items.Add("..............");
listBox1.Items.Add("suma total es: " + suma);
}

TABLA DE MULTIPLICAR

private void button1_Click(object sender, EventArgs e)


{
int x, n, mult = 0;
listBox1.Items.Clear();
n = int.Parse(textBox1.Text);
for (x = 1; x <= 12; x++)
{
mult = x;
listBox1.Items.Add(mult +"* " + n+"=" +x);
}
}
SUMA DE 1 HASTA N NUMEROS

private void button1_Click(object sender, EventArgs e)


{
int x, n, suma = 0;
listBox1.Items.Clear();
n = int.Parse(textBox1.Text);
for (x = 1; x <= n; x++)
{
suma = suma + x;
if(checkBox1.Checked==true)
{
listBox1.Items.Add("sumado:" + x + "suma parcial:" + suma);

}
}
listBox1.Items.Add("sumatoria total es:" + suma);
}

INCREMENTO DE VALORES
private void button1_Click(object sender, EventArgs e)
{
int n,a, b, c, d;
a = int.Parse(textBox1.Text);
b = int.Parse(textBox2.Text);
c = int.Parse(textBox3.Text);
listBox1.Items.Clear();
listBox1.Items.Add("n°:" + a);
for (n= a; n<b-1; n=n+c)
{
d = n + c;
listBox1.Items.Add("n°:" + d);
}
}

ADMINISTRACION DE PRODUCTOS
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(comboBox1.Text);
}

private void button2_Click(object sender, EventArgs e)


{
if (listBox1.SelectedIndex >=0)
{
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.Remove(listBox2.SelectedItem);
}
}

private void button3_Click(object sender, EventArgs e)


{
listBox2.Items.AddRange(listBox1.Items);
listBox1.Items.Clear();
}

private void button4_Click(object sender, EventArgs e)


{
{
listBox1.Items.Add(listBox2.SelectedItem);
listBox2.Items.Remove(listBox1.SelectedItem);
}
}

private void button5_Click(object sender, EventArgs e)


{
listBox1.Items.AddRange(listBox2.Items);
listBox2.Items.Clear();
}

FUNCIONES TIPO FECHA

private void funciones_tipo_fecha_Load(object sender, EventArgs e)


{
textBox8.Text = "hoy es" + DateTime.Now.ToString("dd/MM/yyy") +
DateTime.Now.ToShortTimeString();
textBox8.Enabled = false;
}

private void button1_Click(object sender, EventArgs e)


{
string fecha;
fecha = Convert.ToString(textBox2.Text);
DateTime myDateTime=DateTime.Parse(fecha);
textBox3.Text = Convert.ToString(myDateTime.Day);
textBox4.Text = Convert.ToString(myDateTime.Month);
textBox5.Text = Convert.ToString(myDateTime.Year);

string a;
DateTime diahora = DateTime.Parse(fecha);
a = diahora.DayOfWeek.ToString();
switch(a)
{
case "Monday": textBox6.Text = ("lunes"); break;
case "Tuesday": textBox6.Text = ("martes"); break;
case "Wednesday": textBox6.Text = ("miercoles"); break;
case "Thusday": textBox6.Text = ("jueves"); break;
case "Friday": textBox6.Text = ("viernes"); break;
case "Saturday": textBox6.Text = ("sabado"); break;
case "Sunday": textBox6.Text = ("domingo"); break;
}
int m;
string mes;
m = Convert.ToInt32(textBox4.Text);
switch(m)
{
case 1: mes = " enero "; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 2: mes = " febrero "; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 3: mes = " marzo "; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 4: mes = " abril "; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 5: mes = " mayo "; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 6: mes = " junio "; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 7: mes = " julio "; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 8: mes = "agosto"; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 9: mes = " septiembre "; textBox7.Text = textBox6.Text + ","
+ textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 10: mes = " octubre "; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 11: mes = "noviembre"; textBox7.Text = textBox6.Text + "," +
textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
case 12: mes = " deciembre "; textBox7.Text = textBox6.Text + ","
+ textBox3.Text + "de" + mes + "de" + textBox5.Text;
break;
}
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
SISTEMA DE PEDIDOS

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

namespace WindowsFormsApplication2
{
public partial class sistema_de_pedidos : Form
{
public sistema_de_pedidos()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)


{

double precio, cantidad;


string producto;
int importe;
producto =Convert.ToString(textBox1.Text);
precio =Convert.ToDouble(numericUpDown1.Text);
cantidad = Convert.ToDouble(numericUpDown2.Text);
importe = Convert.ToInt32(precio * cantidad);
listBox1.Items.Add(producto);
listBox2.Items.Add(precio.ToString("0.00"));
listBox3.Items.Add(cantidad.ToString("0.00"));
listBox4.Items.Add(importe);

double s = 0;
foreach (object item in listBox4.Items)
{
s += Convert.ToDouble(item);
textBox2.Text=Convert.ToString(s);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = comboBox1.Text;
}

private void button4_Click(object sender, EventArgs e)


{
Close();
}

private void button3_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
listBox4.Items.Clear();
numericUpDown1.Text = ("0.00");
numericUpDown2.Text = ("0");

private void button1_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
listBox4.Items.Clear();
}
}
}

Potrebbero piacerti anche