Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace PointExercise
- {
- class Point
- {
- private double x;
- private double y;
- public Point(double x, double y)
- {
- this.x = x;
- this.y = y;
- }
- public double GetX()
- {
- return this.x;
- }
- public void SetX(double x)
- {
- this.x = x;
- }
- public double GetY()
- {
- return this.y;
- }
- public void SetY(double y)
- {
- this.y = y;
- }
- override public string ToString()
- {
- return "(" + this.x + ", " + this.y + ")";
- }
- public double Distance(Point p)
- {
- double dx = GetX() - p.GetX();
- double dy = y - p.y;
- double dis2 = Math.Pow(dx, 2) + Math.Pow(dy, 2);
- return Math.Sqrt(dis2);
- }
- public Point Middle(Point p)
- {
- double midX = (x + p.x) / 2;
- double midY = (y + p.y) / 2;
- Point mid = new Point(midX, midY);
- return mid;
- }
- }
- }
Add Comment
Please, Sign In to add comment