//clasa punct in plan
class punct2d
{
protected double x, y;
//proprietati
public double X
{
set { x = value; }
get { return x; }
}
public double Y
{
set { y = value; }
get { return y; }
}
//constructori
public punct2d()
{
x = 0; y = 0;
}
public punct2d(double a, double b)
{
x = a; y = b;
}
//functii
public void citire()
{
Console.Write("x=");
x = double.Parse(Console.ReadLine());
Console.Write("y=");
y = double.Parse(Console.ReadLine());
}
public void afisare()
{
Console.Write("(" + x + "," + y + ") ");
}
public override string ToString()
{
return "(" + x + "," + y + ") ";
}
public double distanta()//distanta pana la origine
{
return Math.Sqrt(x * x + y * y);
}
public double distanta(punct2d A)//distanta pana la punctul A
{
return Math.Sqrt((x - A.x) * (x - A.x) + (y - A.y) * (y - A.y));
}
public static double operator -(punct2d A, punct2d B)
{//distanta dintre punctele A si B
return Math.Sqrt((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));
}
public static bool operator ==(punct2d A, punct2d B)
{//puncte identice
return A.x == B.x && A.y == B.y;
}
public static bool operator !=(punct2d A, punct2d B)
{//puncte diferite
return !(A == B);
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
//clasa punct in spatiu
class punct3d:punct2d
{
protected double z;
//proprietati
public double Z
{
set { z = value; }
get { return z; }
}
//constructori
public punct3d()
: base()
{
z = 0;
}
public punct3d(double a, double b, double c)
: base(a, b)
{
z = c;
}
//functii
new public void citire()
{
base.citire();
Console.Write("z=");
z = double.Parse(Console.ReadLine());
}
new public void afisare()
{
Console.Write("(" + x + "," + y +"," + z + ") ");
}
public override string ToString()
{
return "(" + x + "," + y + "," + z + ") ";
}
new public double distanta()
{
return Math.Sqrt(x * x + y * y + z * z);
}
new public double distanta(punct3d A)
{
return Math.Sqrt((x - A.x) * (x - A.x) + (y - A.y) * (y - A.y) + (z - A.z) * (z - A.z));
}
public static double operator -(punct3d A, punct3d B)
{//distanta dintre punctele A si B
return A.distanta(B);
}
public static bool operator ==(punct3d A, punct3d B)
{//puncte identice
return A.x == B.x && A.y == B.y && A.z==B.z;
}
public static bool operator !=(punct3d A, punct3d B)
{//puncte diferite
return !(A == B);
}
public override bool Equals(object obj)
{
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
|