
Class Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Herencia
{
class Program
{
static void Main(string[] args)
{
classBase CB = new classBase();
classDerivada CD = new classDerivada();
Console.Write("Ingresa el valor de a: ");
CD.a = int.Parse(Console.ReadLine());
Console.Write("Ingresa el valor de b: ");
CD.b = int.Parse(Console.ReadLine());
Console.Write("Ingresa el valor de c: ");
CD.c = int.Parse(Console.ReadLine());
CD.ImprimirSuma();
CD.Imprimir_Producto();
Console.WriteLine("El dato mayor es: {0}",CD.Mayor());
Console.WriteLine("El dato menor es: {0}", CD.Menor());
CD.Imprimir_Intervalo();
Console.ReadKey();
}
}
}
ClassBase:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Herencia
{
public class classBase
{
public int a;
public int b;
public void Imprimir_ab()
{
Console.WriteLine("a={0}, b={1}", a, b);
}
}
}
ClassDerivada:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Herencia
{
public class classDerivada:classBase
{
public int c;
public void Imprimir_c()
{
Console.WriteLine("c= {0}", c);
}
public void ImprimirSuma()
{
Console.WriteLine("\nLa Suma de {0}+{1}+{2} es: {3}",a,b,c, (a + b + c));
}
public void Imprimir_Producto()
{
Console.WriteLine("El Producto de {0}*{1}*{2} es: {3}",a,b,c, (a * b * c));
}
public int Mayor()
{
if (a > b && a > c)
{
return a;
}
else if (b > a && b > c)
{
return b;
}
else if (c > a && c > b)
{
return c;
}
else
{
return a;
}
}
public int Menor()
{
if (a < b && a < c)
{
return a;
}
else if (b < a && b < c)
{
return b;
}
else if (c < a && c < b)
{
return c;
}
else
return a;
}
public void Imprimir_Intervalo()
{
Console.WriteLine("La diferencia entre {0} y {1} es: {2}",Mayor(),Menor(),(Mayor()-Menor()));
}
}
}
No hay comentarios:
Publicar un comentario