deklaracja obiektów

0

class Point
{
double x;
double y;
public:
Point(double xpos,double ypos)
{
x=xpos;
y=ypos;
}
void setX(double xpos){x=xpos;}
void setY(double ypos){y=ypos;}
double getX(){return x;}
double getY(){return y;}
};
class Line
{
public:
Point P1;
Point P2;
Line(double x1,double y1,double x2,double y2)
{
//tutaj chciałbym zdefiniować
//P1 i P2
}
};


2
struct Point // Nie ma co tworzyć niepotrzebnych bytów, każda kombinacja x,y jest poprawnym punktem, więc bawienie się w settery i gettery to masturbacja.
  {
   double x,y;
   public:
   Point():x(0),y(0) {}
   Point(double x,double y):x(x),y(y) {}
  };

struct Line // jak wyżej nie ma co tu hermetyzować.
  {
   Point begin,end;
   Line() {} // automagicznie użyje Point()
   Line(const Point &begin,const Point &end):begin(begin),end(end) {}
   Line(double xbegin,double ybegin,double xend,double yend):begin(xbegin,ybegin),end(xend,yend) {}
  };

1 użytkowników online, w tym zalogowanych: 0, gości: 1