Logo Studenta

Calculadora Programacion Orientada a Eventos

¡Estudia con miles de materiales!

Vista previa del material en texto

PRACTICA 1 UNIDAD 2 
A) PLANTEAMIENTO: 
Diseñar interfaz gráfica y programa en C Sharp que simule el funcionamiento de 
Una calculadora estándar. Ver interfaz gráfica propuesta. 
B) INTERFAZ GRAFICA: 
 (Sin entrada de datos). 
(La pantalla de datos fue puesta con el comando 
ReadOnly en True). 
 
 
 
 
 
CORRIDA 1: SACAR LA RAIZ CUADRADA DE 80 
(1- Se ingresa la cantidad; 80) (2- Se hace click en el boton raiz cuadra y después imprime 
el resultado) 
 
 
 
 
 
 
CORRIDA 2: SACAR LA SENO DE 147 (2- Se clickea en el boton “sin”) 
(1- Se ingresa el numero; 
147) 
 
 
 
 
 
 
CORRIDA 3: REALIZACION DE UNA MULTIPLICACIÓN SENCILLA. 
(1- Se ingresa primer dato) (2- Se presiona botón de multiplicar y se ingresa el 
siguiente 
dato) 
 
 
 
 
 
(3- Se presiona el botón “enter” y posteriormente se imprime el resultado) 
 
 
 
 
 
 
 
 
B) CODIGO EN C#: 
namespace Practica1_U2_Calculadora 
{ 
 public partial class Form1 : Form 
 { 
 public Form1() 
 { 
 InitializeComponent(); 
 } 
 double Valor1 = 0.0, Valor2 = 0.0, resultado; 
 string Signo 
 private void Numero_Cero_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "0"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "0"; 
 } 
 } 
 private void Numero_Uno_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "1"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "1"; 
 } 
 } 
 private void Numero_Dos_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "2"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "2"; 
 } 
 } 
 private void Numero_Tres_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "3"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "3"; 
 } 
 } 
 private void Numero_Cuatro_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "4"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "4"; 
 } 
 } 
 private void Numero_Cinco_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "5"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "5"; 
 } 
 } 
 private void Numero_Seis_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "6"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "6"; 
 } 
 } 
 private void Numero_Siete_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "7"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "7"; 
 } 
 } 
 private void Numero_Ocho_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "8"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "8"; 
 } 
 } 
 private void Numero_Nueve_Click(object sender, EventArgs e) 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "8"; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "9"; 
 } 
 } 
 private void btn_Multiplicar_Click(object sender, EventArgs e) 
 { 
 Valor1 = double.Parse(txt_Display.Text); 
 txt_Display.Text = Valor1.ToString("n2"); 
 txt_Display.Clear(); 
 Signo = "X"; 
 } 
 private void btn_Restar_Click(object sender, EventArgs e) 
 { 
 Valor1 = double.Parse(txt_Display.Text); 
 txt_Display.Text = Valor1.ToString("n2"); 
 txt_Display.Clear(); 
 Signo = "-"; 
 } 
 private void btn_Sumar_Click(object sender, EventArgs e) 
 { 
 Valor1 = double.Parse(txt_Display.Text); 
 txt_Display.Text = Valor1.ToString("n2"); 
 txt_Display.Clear(); 
 Signo = "+"; 
 } 
 private void btn_Calcular_Click(object sender, EventArgs e) 
 { 
 Valor2 = double.Parse(txt_Display.Text); 
 double Suma = 0.0, Multiplicar = 0.0, Restar = 0.0, Dividir, x2; 
 if (Signo == "X") 
 { 
 Multiplicar = Valor1 * Valor2; 
 txt_Display.Text = Multiplicar.ToString("n2"); 
 } 
 if (Signo == "-") 
 { 
 Restar = Valor1 - Valor2; 
 txt_Display.Text = Restar.ToString("n2"); 
 } 
 if (Signo == "+") 
 { 
 Suma = Valor1 + Valor2; 
 txt_Display.Text = Suma.ToString("n2"); 
 } 
 if (Signo == "/") 
 { 
 Dividir = Valor1 / Valor2; 
 txt_Display.Text = Dividir.ToString("n2"); 
 } 
 
 
 } 
 
 private void btn_Dividir_Click(object sender, EventArgs e) 
 { 
 Valor1 = double.Parse(txt_Display.Text); 
 txt_Display.Text = Valor1.ToString("n2"); 
 txt_Display.Clear(); 
 Signo = "/"; 
 } 
 
 private void btn_Punto_Click(object sender, EventArgs e) 
 { 
 if (txt_Display.Text.Contains(".")) 
 { 
 } 
 else 
 { 
 if (Valor2 > 0) 
 { 
 txt_Display.Clear(); 
 txt_Display.Text = txt_Display.Text + "."; 
 Valor2 = 0; 
 } 
 else 
 { 
 txt_Display.Text = txt_Display.Text + "."; 
 } 
 } 
 } 
 private void btn_Clear_Click(object sender, EventArgs e) 
 { 
 txt_Display.Clear(); 
 Valor1 = 0.0; 
 Valor2 = 0.0; 
 } 
 
 private void btn_Reducir_Click(object sender, EventArgs e) 
 { 
 if (txt_Display.Text.Length == 1) 
 txt_Display.Text = "0"; 
 else 
 txt_Display.Text = txt_Display.Text.Substring(0, 
 txt_Display.Text.Length - 1);} 
 private void btn_Raiz_Click(object sender, EventArgs e) 
 { 
 Valor1 = double.Parse(txt_Display.Text); 
 resultado = Math.Sqrt(Valor1); 
 txt_Display.Text = resultado.ToString("n2"); 
 resultado = 0; 
 } 
 
 private void btn_tan_Click(object sender, EventArgs e) 
 { 
 Valor1 = double.Parse(txt_Display.Text); 
 resultado = Math.Tan(Valor1); 
 txt_Display.Text = resultado.ToString("n2"); 
 resultado = 0; 
 } 
 
 private void btn_sin_Click(object sender, EventArgs e) 
 { 
 Valor1 = double.Parse(txt_Display.Text); 
 resultado = Math.Sin(Valor1); 
 txt_Display.Text = resultado.ToString("n2"); 
 resultado = 0; 
 } 
 
 private void btn_cos_Click(object sender, EventArgs e) 
 { 
 Valor1 = double.Parse(txt_Display.Text); 
 resultado = Math.Cos(Valor1); 
 txt_Display.Text = resultado.ToString("n2"); 
 resultado = 0; 
 } 
 } 
 }

Continuar navegando

Otros materiales