0% found this document useful (0 votes)
37 views2 pages

מחלקות

The document defines a Point class with properties for x and y coordinates and methods for getting/setting coordinates, calculating distance between points, and finding the midpoint between two points. It then creates two Point objects, swaps their x values, and calls methods to output the points and calculate their midpoint, demonstrating use of the Point class.

Uploaded by

hadaramran
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

מחלקות

The document defines a Point class with properties for x and y coordinates and methods for getting/setting coordinates, calculating distance between points, and finding the midpoint between two points. It then creates two Point objects, swaps their x values, and calls methods to output the points and calculate their midpoint, demonstrating use of the Point class.

Uploaded by

hadaramran
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

:‫מחלקות‬

class Points
{
static void Main(string[] args)
{
double t;
Point a = new Point(43, 7);
Point b = new Point(5, 5);
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine("insert new x of 2 points");
t = b.GetX();
b.SetX(a.GetX());
a.SetX(t);
Console.WriteLine(a);
Console.WriteLine(b);
Point m = new Point();
m = a.Middle(b);
Console.WriteLine(m);
}
}
}

class Point
{
private double x;
private double y;

public Point()
{
x = 0;
y = 0;
}
public Point(double x, double y)
{
this.x = x;
this.y = y;
}
public double GetX()
{
return x;
}
public double GetY()
{
return y;
}
public void SetX(double x)
{
this.x = x;
}
public void SetY(double y)
{
this.y = y;
}
public override string ToString()
{
return ("(" + this.x + "," + this.y + ")");
}
public double Distance(Point a)
{
double d = Math.Sqrt(Math.Pow((this.x - a.x),2) +
Math.Pow((this.y - a.y),2));
return d;
}
public Point Middle(Point a)
{
Point m = new Point((this.x + a.x) / 2, (this.y + a.y) /
2);
return m;
}
}
}

You might also like