static void Main(string[] args) { int flag = 0; int a, b, c, d, e; while (flag != -1) { Console.Write("Elegir: \n 1-Triángulo \n 2-Rectángulo \n 3-Cuadrado \n (-1)-Salir \n"); flag = int.Parse(Console.ReadLine()); Console.WriteLine("Ingresar valores de lados: "); switch (flag) { case 1: a = int.Parse(Console.ReadLine()); b = int.Parse(Console.ReadLine()); c = int.Parse(Console.ReadLine()); Console.WriteLine("Ingresar base y altura : "); d = int.Parse(Console.ReadLine()); e = int.Parse(Console.ReadLine()); Triángulo triangulo = new Triángulo(a, b, c, d, e); Console.WriteLine("Área: " + triangulo.Area() + " Perímetro: " + triangulo.Perimetro()); break; case 2: a = int.Parse(Console.ReadLine()); b = int.Parse(Console.ReadLine()); Rectángulo rectangulo = new Rectángulo(a, b); Console.WriteLine("Área: " + rectangulo.Area() + " Perímetro: " + rectangulo.Perimetro()); break; case 3: a = int.Parse(Console.ReadLine()); Cuadrado cuadrado = new Cuadrado(a); Console.WriteLine("Área: " + cuadrado.Area() + " Perímetro: " + cuadrado.Perimetro()); break; } } }
private void BtnCalcular_Click(object sender, EventArgs e) { int opcion = cbFiguras.SelectedIndex; switch (opcion) { case 0: if (txtLado1.Text != String.Empty) { Formas.Cuadrado cuadrado = new Formas.Cuadrado(Convert.ToDouble(txtLado1.Text)); resArea.Text = Convert.ToString(cuadrado.calcularArea()); resPerimetro.Text = Convert.ToString(cuadrado.calcularPerimetro()); } else { MessageBox.Show("Debe digitar el valor solicitado."); } break; case 1: if (txtLado1.Text != String.Empty && txtLado2.Text != String.Empty) { Formas.Rectangulo rectangulo = new Formas.Rectangulo(Convert.ToDouble(txtLado1.Text), Convert.ToDouble(txtLado2.Text)); resArea.Text = Convert.ToString(rectangulo.calcularArea()); resPerimetro.Text = Convert.ToString(rectangulo.calcularPerimetro()); } else { MessageBox.Show("Debe digitar el valor solicitado."); } break; case 2: if (txtLado1.Text != String.Empty && txtLado2.Text != String.Empty && txtLado3.Text != String.Empty && txtLado4.Text != String.Empty) { Formas.Triangulo triangulo = new Formas.Triangulo(Convert.ToDouble(txtLado1.Text), Convert.ToDouble(txtLado2.Text), Convert.ToDouble(txtLado3.Text), Convert.ToDouble(txtLado4.Text)); resArea.Text = Convert.ToString(triangulo.calcularArea()); resPerimetro.Text = Convert.ToString(triangulo.calcularPerimetro()); } else { MessageBox.Show("Debe digitar el valor solicitado."); } break; case 3: if (txtLado1.Text != String.Empty) { Formas.Circulo circulo = new Formas.Circulo(Convert.ToDouble(txtLado1.Text)); resArea.Text = Convert.ToString(circulo.calcularArea()); resPerimetro.Text = Convert.ToString(circulo.calcularPerimetro()); } else { MessageBox.Show("Debe digitar el valor solicitado."); } break; default: break; } }