jueves, 25 de noviembre de 2010

Programa de clases

Recuerde que al crear la clase debe ir proyect(proyecto) despues add class(agregar clase) y al solicitar el nombre de operaciones_arit .


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

namespace practica_11_2
{
class operaciones_arit
{
int operando1;
int operando2;
public operaciones_arit(int n1, int n2)
{
operando1 = n1;
operando2 = n2;
}
public operaciones_arit()
{
operando1 = 0;
operando2 = 0;
}
public void introducir_op1(int num1)
{
operando1 = num1;
}
public void introducir_op2(int num2)
{
operando2 = num2;
}
public int obtener_op1()
{
return operando1;
}
public int obtener_op2()
{
return operando2;
}
public int sumar()
{
return operando1 + operando2;
}
public int restar()
{
return operando1 - operando2;
}
public int multiplicar()
{
return operando1 * operando2;
}
public int dividir()
{
if (operando2 != 0)
{
return operando1 / operando2;
}
else
{
return -1;
}
}

public int mayor()
{
if (operando1 >= operando2)
{
return operando1;
}
else
{
return operando2;
}
}
public int menor()
{
if (operando1 <= operando2)
{
return operando1;
}
else
{
return operando2;
}
}

}
}



La class Program es la siguiente:

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

namespace practica_11_2
{
class Program
{
static void Main(string[] args)
{
int numero1 = 0, numero2 = 0, suma=0;
Console.Write("Operando 1 =? ");
numero1 = int.Parse(Console.ReadLine());
Console.Write("Operando 2 =? ");
numero2 = int.Parse(Console.ReadLine());
operaciones_arit p1 = new operaciones_arit(numero1, numero2);
suma = p1.sumar();
Console.WriteLine("La suma de " + p1.obtener_op1() + " + " + p1.obtener_op2() + "=" + suma);
Console.WriteLine("El dato mayor es " + p1.mayor());
operaciones_arit a1 = new operaciones_arit();
a1.introducir_op1(10);
a1.introducir_op2(numero1);
Console.WriteLine("La suma de " + a1.obtener_op1() + " + " + a1.obtener_op2() + " = " + a1.sumar());
Console.WriteLine("El dato mayor es : " + a1.mayor());
Console.WriteLine("El dato menor es : " + a1.menor());
operaciones_arit tercerobjeto = new operaciones_arit(33, 67);
Console.WriteLine("La multiplicacion de " + tercerobjeto.obtener_op1() + " * " + tercerobjeto.obtener_op2() + " = " + tercerobjeto.multiplicar());
Console.ReadKey();



}
}
}

No hay comentarios:

Publicar un comentario