Из абстрактного класса в интерфейс - C#
Формулировка задачи:
Здравствуйте. Не могли бы вы, пожалуйста, помочь с задачей.
Нужно вместо абстрактного класса определить и использовать интерфейс. В интерфейс включить также свойства, связанные с соответствующими данными классов.
Вот код программы с абстрактным классом:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Выберите что вы хотите сделать \n1)найти окружность \n2)найти треугольник ");
int v = Convert.ToInt32(Console.ReadLine());
if (v == 1)
{
krug s = new krug();
s.Круг();
s.vavodtochki();
}
if (v == 2)
{
treugolnic p = new treugolnic();
p.treygolnic();
p.vavodtreygolnica();
}
}
}
abstract public class figura
{
public int x;
public int q;
public int w;
public int u;
public int l;
public double y;
}
public class krug : figura
{
public void Круг()
{
Console.WriteLine("Радиус круга ");
this.x = Convert.ToInt32(Console.ReadLine());
this.y = Math.PI * Math.Pow(x, 2);
}
public void vavodtochki()
{
Console.Write("радиус круга равен {0:f2} ", y);
Console.ReadLine();
}
}
public class treugolnic : krug
{
public void treygolnic()
{
Console.WriteLine("Ведите a");
this.q = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Ведите h");
this.w = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Ведите l");
this.l = Convert.ToInt32(Console.ReadLine());
this.u = q + w + l;
}
public void vavodtreygolnica()
{
Console.WriteLine("{0} равен периметр треугольника ", u);
Console.ReadLine();
}
}
}Решение задачи: «Из абстрактного класса в интерфейс»
textual
Листинг программы
public interface IFigura
{
int X { get; set; }
int Q { get; set; }
int W { get; set; }
int U { get; set; }
int L { get; set; }
double Y { get; set; }
}