miércoles, 9 de noviembre de 2016

Otro ejemplo de Interfaces en C#.

/*
 * Created by SharpDevelop.
 * User: manuel
 * Date: 08/11/2016
 * Time: 02:29 p. m.
 */
using System;

namespace Examen2
{
   
    public interface Interface1
    {
        double CalculoVoltaje(double R, double I);
       
    }
}


/*
 * Created by SharpDevelop.
 * User: manuel
 * Date: 08/11/2016
 * Time: 02:30 p. m.
 */
using System;

namespace Examen2
{
   
    public interface Interface2:Interface1
    {
        double CalculoResistencia(double V, double I);
       
    }
}

/*
 * Created by SharpDevelop.
 * User: manuel
 * Date: 08/11/2016
 * Time: 02:32 p. m.
 */
 
using System;

namespace Examen2
{
   
    public class CalculosElectronicos:Interface2
    {
        public double V, R, I;
       
        public CalculosElectronicos()
        {
        }
       
        double Interface1.CalculoVoltaje(double r, double i){
            this.R = r;
            this.I = i;
            this.V = this.R*this.I;
           
            return this.V;
        }
       
         double Interface2.CalculoResistencia(double v, double i){
            this.V = v;
            this.I = i;
           
            this.R = this.V/this.I;
           
            return this.R;
        }
    }
}

/*
 * Created by SharpDevelop.
 * User: manuel
 * Date: 08/11/2016
 * Time: 02:27 p. m.
 */
using System;

namespace Examen2
{
    class Program
    {
        public static void Main(string[] args)
        {
            Interface2 cal = new CalculosElectronicos();
           
           
            Console.WriteLine("R = 3 ohms, I = 4 amps y V = {0} volts", cal.CalculoVoltaje(3,4));
            Console.WriteLine("V = 3 volts, I = 4 amps y R = {0} ohms", cal.CalculoResistencia(3,4));
           
           
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}

No hay comentarios:

Publicar un comentario