[c++]代码库
#include<iostream>
using namespace std;
class Point
{
public:
double x,y;
Point(double a,double b)
{
x=a;
y=b;
cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;
}
Point()
{
x=y=0;
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;
}
};
class Line
{
private:
Point m,n;
public:
void SetLine (double a1,double b1,double a2,double b2)
{
m.x=a1;
m.y=b1;
n.x=a2;
n.y=b2;
}
Line (Point &a,Point &b):m(a),n(b)
{
cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is created."<<endl;
}
Line(double a1=0,double b1=0,double a2=0,double b2=0):m(a1,b1),n(a2,b2)
{
//m.x=m.y=n.x=n.y=0;
cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is created."<<endl;
}
~Line()
{
cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<") is erased."<<endl;
}
double show()
{
cout<<"Line : ("<<m.x<<", "<<m.y<<") to ("<<n.x<<", "<<n.y<<")"<<endl;
}
};
int main()
{
char c;
int num, i;
double x1, x2, y1, y2;
Point p(1, -2), q(2, -1), t;
t.show();
std::cin>>num;
Line line[num];
for(i = 0; i <num; i++)
{
std::cout<<"=========================\n";
std::cin>>x1>>c>>y1>>x2>>c>>y2;
line[i].SetLine(x1, y1, x2, y2);
line[i].show();
}
std::cout<<"=========================\n";
Line l1(p, q), l2(p, t), l3(q, t), l4(t, q);
l1.show();
l2.show();
l3.show();
l4.show();
}
by: 发表于:2017-09-01 09:54:14 顶(0) | 踩(0) 回复
??
回复评论