Есть два класса: Точка и Треугольник.
Point сам по себе, и Triangle должен иметь массив из 3 встроенных объектов класса Point.
Точка работает отлично, но когда дело дошло до создания треугольника, появилась куча ошибок.
Где я ошибся?
Point:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Classes
{
class Point
{
private int x;
private int y;
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public void setX()
{
//get user input, validate
Console.WriteLine("Enter X co-ord: ");
int inputX;
if (Int32.TryParse(Console.ReadLine(), out inputX))
{
setX(inputX);
}
else
{
Console.WriteLine("Invalid input value");
Console.WriteLine("Assigning default value of 0 to X co-ord");
setX(0);
}
}
public void setX(int xx)
{
x = xx;
}
public void setX(Point px)
{
if (px == null)
x = 0;
else
x = px.x;
}
public void setY()
{
//get user input, validate
Console.WriteLine("Enter Y co-ord: ");
int inputY;
if (Int32.TryParse(Console.ReadLine(), out inputY))
{
setY(inputY);
}
else
{
Console.WriteLine("Invalid input value");
Console.WriteLine("Assigning default value of 0 to Y co-ord");
setY(0);
}
}
public void setY(int yy)
{
y = yy;
}
public void setY(Point py)
{
if (py == null)
y = 0;
else
y = py.y;
}
public void setPoint()
{
setX();
setY();
}
public void setPoint(int xx, int yy)
{
setX(xx);
setY(yy);
}
public void setPoint(Point p)
{
setX(p);
setY(p);
}
public Point()
{
setPoint();
}
public Point(int xx, int yy)
{
setPoint(xx, yy);
}
public Point(Point p)
{
setPoint(p);
}
public static Point operator +(Point p1, Point p2)
{
Point temp = new Point(0,0);
temp.x = p1.getX() + p2.getX();
temp.y = p1.getY() + p2.getY();
return temp;
}
public static Point operator -(Point p1, Point p2)
{
Point temp = new Point(0, 0);
temp.x = p1.getX() - p2.getX();
temp.y = p1.getY() - p2.getY();
return temp;
}
public static Point Add(Point p1, Point p2)
{
Point temp = new Point(0, 0);
temp.x = p1.getX() + p2.getX();
temp.y = p1.getY() + p2.getY();
return temp;
}
public static Point Add(int xx, int yy ,Point p)
{
Point temp = new Point(0, 0);
temp.x = xx + p.getX();
temp.y = yy + p.getY();
return temp;
}
public static Point Add(int x1, int x2, int y1, int y2)
{
Point temp = new Point(0, 0);
temp.x = x1 + x2;
temp.y = y1 + y2;
return temp;
}
public Point Add(Point p)
{
Point temp = new Point(0, 0);
temp.x = getX() + p.x;
temp.y = getY() + p.y;
return temp;
}
public Point Add(int xx, int yy)
{
Point temp = new Point(0, 0);
temp.x = getX() + xx;
temp.y = getY() + yy;
return temp;
}
public static Point Subtract(Point p1, Point p2)
{
Point temp = new Point(0, 0);
temp.x = p1.getX() - p2.getX();
temp.y = p1.getY() - p2.getY();
return temp;
}
public static Point Subtract(int xx, int yy, Point p)
{
Point temp = new Point(0, 0);
temp.x = xx - p.getX();
temp.y = yy - p.getY();
return temp;
}
public static Point Subtract(int x1, int x2, int y1, int y2)
{
Point temp = new Point(0, 0);
temp.x = x1 - x2;
temp.y = y1 - y2;
return temp;
}
public Point Subtract(Point p)
{
Point temp = new Point(0, 0);
temp.x = getX() - p.x;
temp.y = getY() - p.y;
return temp;
}
public Point Subtract(int xx, int yy)
{
Point temp = new Point(0, 0);
temp.x = getX() - xx;
temp.y = getY() - yy;
return temp;
}
public void displayPoint()
{
System.Console.WriteLine("Point: X={0} ; Y={1}", getX(), getY());
}
public bool isEqual(Point p)
{
if (x == p.x && y == p.y)
return true;
else
return false;
}
public static bool isEqual(Point p1, Point p2)
{
if (p1.x == p2.x && p1.y == p2.y)
return true;
else
return false;
}
public bool isNotEqual(Point p)
{
if (this.isEqual(p) == true)
return false;
else
return true;
}
public static bool isNotEqual(Point p1, Point p2)
{
if (Point.isEqual(p1, p2) == true)
return true;
else
return false;
}
public static bool operator ==(Point p1, Point p2)
{
if (p1.isEqual(p2) == true)
return true;
else
return false;
}
public static bool operator !=(Point p1, Point p2)
{
if (p1.x == p2.x && p1.y == p2.y)
return true;
else
return false;
}
}
}
Triangle:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Classes
{
class Triangle
{
private Point pnt[]; /*Bad array declarator*/
public Triangle()
{
pnt = new Point[3]; /*Can't convert Point[] to Point*/
for (int i=0; i<pnt.Length; i++) /*Length doesn't exists in Point*/
pnt[i] = new Point(); /*Can't apply indexing to Point[]*/
}
}
}