Sie sind auf Seite 1von 5

using System;

using System.Collections.Generic;
using System.Windows.Forms;

namespace WindowsApplication5
{
static class Program
{
/// <summary>
/// Punto de entrada principal para la aplicación.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
public class operaciones
{
double operando1;
double operando2;
double resultado;
public void SetSuma(double operando1, double operando2)
{
this.operando1 = operando1;
this.operando2 = operando2;
resultado = operando1 + operando2;
}
public void SetResta(double operando1, double operando2)
{
this.operando1 = operando1;
this.operando2 = operando2;
resultado = operando1 - operando2;
}
public void SetMulti(double operando1, double operando2)
{
this.operando1 = operando1;
this.operando2 = operando2;
resultado = operando1 * operando2;
}
public void SetDivi(double operando1, double operando2)
{
this.operando1 = operando1;
this.operando2 = operando2;
resultado = operando1 / operando2;
}

public void SetParEImpar(double operando1)


{
this.operando1 = operando1;
resultado = operando1 % 2;
}
public double GetResultado()
{
return resultado;
}
}
public class calcular
{
double operando1;
double operando2;
double resultado;
public void SetPorcentaje(double operando1, double operando2)
{
this.operando1 = operando1;
this.operando2 = operando2;
resultado = operando1 * operando2 / 100;
}
public double GetResultado()
{
return resultado;
}
}
public class calculo
{
double operando1;
double resultado;
int contador;
Boolean primo;

public void SetPrimo(double operando1)


{
this.operando1 = operando1;
contador = 2;
primo = true;
while ((primo) && (contador != operando1 ))
{
if(operando1 % contador == 0)
primo = false;
contador++;
}
}
public void SetFactorial(double operando1)
{
this.operando1 = operando1;
resultado = 1;
while (operando1 != 0)
{
resultado = resultado * operando1;
operando1--;
}
}
public double GetResultado()
{
return resultado;
}
public Boolean GetResultadoPrimo()
{
return primo;
}
}
}

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

namespace WindowsApplication5
{
public partial class Form1 : Form
{
double valor1;
double valor2;
double resultado;
Boolean primo;
operaciones operacion = new operaciones();
calcularoperaporc = new calcular ();
calculo calcPriFac = new calculo();

public Form1()
{
InitializeComponent();
}

private void btn_Suma_Click(object sender, EventArgs e)


{
valor1 = Convert.ToDouble (txt_Valor1.Text) ;
valor2 = Convert.ToDouble(txt_Valor2.Text);
operacion.SetSuma(valor1, valor2);
resultado = operacion.GetResultado();
txt_Resultado.Text = Convert.ToString(resultado);

private void btn_Multi_Click(object sender, EventArgs e)


{
valor1 = Convert.ToDouble(txt_Valor1.Text);
valor2 = Convert.ToDouble(txt_Valor2.Text);
operacion.SetMulti(valor1, valor2);
resultado = operacion.GetResultado();
txt_Resultado.Text = Convert.ToString(resultado);

private void btn_Divi_Click(object sender, EventArgs e)


{
valor1 = Convert.ToDouble(txt_Valor1.Text);
valor2 = Convert.ToDouble(txt_Valor2.Text);
if (valor2 == 0)
{
txt_Resultado.Text = "Operacion no se puede realizar
dividendo es igual a cero";
}
else
{
operacion.SetDivi(valor1, valor2);
resultado = operacion.GetResultado();
txt_Resultado.Text = Convert.ToString(resultado);
}

private void btn_Resta_Click(object sender, EventArgs e)


{
valor1 = Convert.ToDouble(txt_Valor1.Text);
valor2 = Convert.ToDouble(txt_Valor2.Text);
operacion.SetResta(valor1, valor2);
resultado = operacion.GetResultado();
txt_Resultado.Text = Convert.ToString(resultado);

private void Btn_Impar_Par_Click(object sender, EventArgs e)


{
valor1 = Convert.ToDouble(txt_Valor1.Text);
operacion.SetParEImpar(valor1);
double resultado = operacion.GetResultado();
if (resultado == 0)
{
txt_Resultado.Text = "Es numero Par";
}
else
{
txt_Resultado.Text = "Es numero Impar";
}

private void btn_Limpiar_Click(object sender, EventArgs e)


{
txt_Resultado.Text = "";
txt_Valor1.Text = "";
txt_Valor2.Text = "";
}

private void btn_Porce_Click(object sender, EventArgs e)


{
valor1 = Convert.ToDouble(txt_Valor1.Text);
valor2 = Convert.ToDouble(txt_Valor2.Text);
operaporc.SetPorcentaje (valor1, valor2);
resultado = operaporc.GetResultado();
txt_Resultado.Text = Convert.ToString(resultado);

private void btn_Primo_Click(object sender, EventArgs e)


{
if (valor1 > 1)
{

valor1 = Convert.ToDouble(txt_Valor1.Text);
calcPriFac.SetPrimo(valor1);
primo = calcPriFac.GetResultadoPrimo();

if (primo == false)
{
txt_Resultado.Text = "El Numero no es primo";
}
else
{
txt_Resultado.Text = "El Numero es primo";
}
}
else
{
txt_Resultado.Text = "El numero no puede calcularse si es
primo";
}

private void btn_Factorial_Click(object sender, EventArgs e)


{
valor1 = Convert.ToDouble(txt_Valor1.Text);
if (valor1 >= 1)
{
calcPriFac.SetFactorial(valor1);
resultado = calcPriFac.GetResultado();
txt_Resultado.Text = Convert.ToString(resultado);
}
else
{
txt_Resultado.Text = "El valor no se puede calcular
el factorial";
}

}
}

Sony W 35 486.000 24 cuotas quincenales

Das könnte Ihnen auch gefallen