#include <iostream>
#include <iomanip>
using namespace std;
class Point
{
public:
double x() {return x_;}
double y() {return y_;}
double x(double x) {x_=x; return x_;}
double y(double y) {y_=y; return y_;}
public:
Point (){x_=0,y_=0;cout<<"Point : ("<<x_<<", "<<y_<<") is created."<<endl;}
Point (double x):x_(x),y_(x){cout<<"Point : ("<<x_<<", "<<y_<<") is created."<<endl;}
Point (double x,double y){x_=x;y_=y;cout<<"Point : ("<<x_<<", "<<y_<<") is created."<<endl;}
Point (const Point& p){ x_=p.x_;y_=p.y_;cout<<"Point : ("<<x_<<", "<<y_<<") is copied."<<endl;}
~Point(){cout<<"Point : ("<<x_<<", "<<y_<<") is erased."<<endl;};
void show() {cout<<"Point : ("<<x_<<", "<<y_<<")"<<endl;}
private:
double x_,y_;
};
class Line
{
public:
Line (){x1=0,x2=0,y1=0,y2=0;
cout<<"Point : ("<<x1<<", "<<y1<<") is created."<<endl;
cout<<"Point : ("<<x2<<", "<<y2<<") is created."<<endl;
cout<<"Line : ("<<x1<<", "<<y1<<") to ("<<x2<<", "<<y2<<") is created."<<endl;}
Line (const Line &p){x1=p.x1;x2=p.x2;y1=p.y1;y2=p.y2;
cout<<"Point : ("<<x1<<", "<<y1<<") is copied."<<endl;
cout<<"Point : ("<<x2<<", "<<y2<<") is copied."<<endl;
cout<<"Line : ("<<x1<<", "<<y1<<") to ("<<x2<<", "<<y2<<") is copied."<<endl;}
Line ( Point &a, Point &b){
x1=a.x();
y1=a.y();
x2=b.x();
y2=b.y();
cout<<"Point : ("<<x1<<", "<<y1<<") is copied."<<endl;
cout<<"Point : ("<<x2<<", "<<y2<<") is copied."<<endl;
cout<<"Line : ("<<x1<<", "<<y1<<") to ("<<x2<<", "<<y2<<") is created."<<endl;}
Line (double a,double b,double c,double d)
{
x1=a;
y1=b;
x2=c;
y2=d;}
Line &setLine ( const Line &p){x1=p.x1;x2=p.x2;y1=p.y1;y2=p.y2;
// cout<<"Point : ("<<x1<<", "<<y1<<") is created."<<endl;
// cout<<"Point : ("<<x2<<", "<<y2<<") is created."<<endl;
// cout<<"Line : ("<<x1<<", "<<y1<<") to ("<<x2<<", "<<y2<<")dddddddddddddddd"<<endl;
return *this;
}
Line &setLine (double a,double b,double c,double d)
{
x1=a;
y1=b;
x2=c;
y2=d;
// cout<<"Line : ("<<x1<<", "<<y1<<") to ("<<x2<<", "<<y2<<")ssssssssssssssssssss"<<endl;
}
Line &setLine( Point &a, Point &b)
{
x1=a.x();
y1=a.y();
x2=b.x();
y2=b.y();
// cout<<"Point : ("<<x1<<", "<<y1<<") is created."<<endl;
// cout<<"Point : ("<<x2<<", "<<y2<<") is created."<<endl;
// cout<<"Line : ("<<x1<<", "<<y1<<") to ("<<x2<<", "<<y2<<") is created."<<endl;
}
~Line(){
cout<<"Line : ("<<x1<<", "<<y1<<") to ("<<x2<<", "<<y2<<") is erased."<<endl;
cout<<"Point : ("<<x2<<", "<<y2<<") is erased."<<endl;
cout<<"Point : ("<<x1<<", "<<y1<<") is erased."<<endl;
}
void show()
{
cout<<"Line : ("<<x1<<", "<<y1<<") to ("<<x2<<", "<<y2<<")"<<endl;
}
void readLine()
{
char c;
cin>>x1>>c>>y1>>x2>>c>>y2;
}
private:
double x1,y1,x2,y2;
};
int main()
{
int num, i;
Point p(1, -2), q(2, -1), t;
t.show();
std::cin>>num;
Line line[num];
for(i = 0; i < num; i++)
{
line[i].readLine();
line[i].show();
}
Line l1(p, q), l2(p,t), l3(q,t), l4(l1);
l1.show();
l2.setLine(l1).show();
l3.show();
l4.setLine(t,q).show();
}
OJ:line point 5
最新推荐文章于 2025-05-29 23:36:29 发布