namespace ConsoleApplication10
{
class Pryamoyg
{
private double x1;
private double y1;
private double x2;
private double y2;
private double x3;
private double y3;
private double x4;
private double y4;
private bool Proverka()
{
double k1, k2, g, k3, k4;
bool p = false;
k1 = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
k2 = Math.Sqrt(((x3 - x2) * (x3 - x2)) + ((y3 - y2) * (y3 - y2)));
k3 = Math.Sqrt(((x4 - x3) * (x4 - x3)) + ((y4 - y3) * (y4 - y3)));
k4 = Math.Sqrt(((x1 - x4) * (x1 - x4)) + ((y1 - y4) * (y1 - y4)));
g = Math.Sqrt(((x3 - x1) * (x3 - x1)) + ((y3 - y1) * (y3 - y1)));
if ((g == Math.Sqrt(k1 * k1 + k2 * k2)) & (g == Math.Sqrt(k3 * k3 + k4 * k4)))
{
p = true;
}
return p;
}
public void Ploshad()
{
if (Proverka() == true)
{
double r1, r2, S;
r1 = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
r2 = Math.Sqrt(((x3 - x2) * (x3 - x2)) + ((y3 - y2) * (y3 - y2)));
S = r1 * r2;
Console.WriteLine("Площадь: {0}", S);
}
else
{
Console.WriteLine("eto ne pryamoyg");
}
}
public void Perim()
{
if (Proverka() == true)
{
double r1, r2, P;
r1 = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
r2 = Math.Sqrt(((x3 - x2) * (x3 - x2)) + ((y3 - y2) * (y3 - y2)));
P = (r1 + r2) * 2;
Console.WriteLine("Периметр: {0}", P);
}
else
{
Console.WriteLine("eto ne pryamoyg");
}
}
class Kvadrat
{
private double x1;
private double y1;
private double x2;
private double y2;
private double x3;
private double y3;
private double x4;
private double y4;
public Kvadrat(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
this.x1 = x1;
this.x4 = x4;
this.x2 = x2;
this.x3 = x3;
this.y1 = y1;
this.y2 = y2;
this.y3 = y3;
this.y4 = y4;
}
private bool Proverka()
{
double k1, k2, g, k3, k4;
bool p = false;
k1 = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
k2 = Math.Sqrt(((x3 - x2) * (x3 - x2)) + ((y3 - y2) * (y3 - y2)));
k3 = Math.Sqrt(((x4 - x3) * (x4 - x3)) + ((y4 - y3) * (y4 - y3)));
g = Math.Sqrt(((x3 - x1) * (x3 - x1)) + ((y3 - y1) * (y3 - y1)));
k4 = Math.Sqrt(((x1 - x4) * (x1 - x4)) + ((y1 - y4) * (y1 - y4)));
if ((g == Math.Sqrt(k1 * k1 + k2 * k2)) & (k1 == k2) & (k1 == k3) & (k1 == k4))
{
p = true;
}
return p;
}
public void Ploshad()
{
if (Proverka() == true)
{
double r1, r2, S;
r1 = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
r2 = Math.Sqrt(((x3 - x2) * (x3 - x2)) + ((y3 - y2) * (y3 - y2)));
S = r1 * r2;
Console.WriteLine("Площадь: {0}", S);
}
else
{
Console.WriteLine("eto ne kvadr");
}
}
public void Perim()
{
if (Proverka() == true)
{
double r1, r2, P;
r1 = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
r2 = Math.Sqrt(((x3 - x2) * (x3 - x2)) + ((y3 - y2) * (y3 - y2)));
P = (r1 + r2) * 2;
Console.WriteLine("Периметр: {0}", P);
}
else
{
Console.WriteLine("eto ne kvadr");
}
}
class Romb
{
private double x1;
private double y1;
private double x2;
private double y2;
private double x3;
private double y3;
private double x4;
private double y4;
public Romb(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
{
this.x1 = x1;
this.x4 = x4;
this.x2 = x2;
this.x3 = x3;
this.y1 = y1;
this.y2 = y2;
this.y3 = y3;
this.y4 = y4;
}
private bool Proverka()
{
double k1, k2, g, k3, k4;
bool p = false;
k1 = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
k2 = Math.Sqrt(((x3 - x2) * (x3 - x2)) + ((y3 - y2) * (y3 - y2)));
k3 = Math.Sqrt(((x4 - x3) * (x4 - x3)) + ((y4 - y3) * (y4 - y3)));
g = Math.Sqrt(((x3 - x1) * (x3 - x1)) + ((y3 - y1) * (y3 - y1)));
k4 = Math.Sqrt(((x1 - x4) * (x1 - x4)) + ((y1 - y4) * (y1 - y4)));
if ((k1 == k2) & (k1 == k3) & (k1 == k4))
{
p = true;
}
return p;
}
public void Ploshad()
{
if (Proverka() == true)
{
double r1, r2, S;
r1 = Math.Sqrt(((x3 - x1) * (x3 - x1)) + ((y3 - y1) * (y3 - y1)));
r2 = Math.Sqrt(((x4 - x2) * (x4 - x2)) + ((y4 - y2) * (y4 - y2)));
S = (r1 * r2) / 2;
Console.WriteLine("Площадь: {0}", S);
}
else
{
Console.WriteLine("eto ne romb");
}
}
public void Perim()
{
if (Proverka() == true)
{
double r1, P;
r1 = Math.Sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
P = r1 * 4;
Console.WriteLine("Периметр: {0}", P);
}
else
{
Console.WriteLine("eto ne romb");
}
}
}
class Trapecia
{
public double x1;
public double y1;
public double x2;
public double y2;
public double x3;
public double y3;
public double x4;
public double y4;
public void Ploshad()
{
double a1, h1, S1, a2, h2, S2, a3, h3, S3, a4, h4, S4, S;
a1 = x2 - x1;
h1 = Math.Abs(y1 + (y2 - y1) / 2);
S1 = a1 * h1;
a2 = x3 - x2;
h2 = Math.Abs(y2 + (y3 - y2) / 2);
S2 = a2 * h2;
a3 = x4 - x3;
h3 = Math.Abs(y3 + (y4 - y3) / 2);
S3 = a3 * h3;
a4 = x1 - x4;
h4 = Math.Abs(y4 + (y1 - y4) / 2);
S4 = a4 * h4;
S = S1 + S2 + S3 + S4;
Console.WriteLine("Площадь: {0}", S);
}
}
class Paral
{
public double x1;
public double y1;
public double x2;
public double y2;
public double x3;
public double y3;
public double x4;
public double y4;
}
class Krug
{
public double r;
public const double Pi = Math.PI;
public void Ploshad()
{
double S;
S = Pi * (r * r);
Console.WriteLine("Площадь : {0}", S);
}
public void DlinaO()
{
double L;
L = 2 * Pi * r;
Console.WriteLine("Длина окружностти : {0}", L);
}
}
Это не просьба сделать за меня работу, а просто показать, как уменьшить код. Программа, вводим координаты и получаем в итоге ответ, но она огромна, пока читаю тему наследования, но до конца не понимаю, как уменьшить объем кода? Хотя бы часть с переменными x/y?
*часть программы удалена из-за ограничения в 10 тысяч символов