标签:
Problem A: 平面上的点——Point类 (IV)
Problem A: 平面上的点——Point类 (IV)
Time Limit: 1 Sec Memory Limit: 4 MB
Submit: 4107 Solved: 1975
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上的点的操作。
根据“append.cc”,完成Point类的构造方法和show()、showCounter()、showSumOfPoint()方法;实现showPoint()函数。
接口描述:
showPoint()函数:按输出格式输出Point对象,调用Point::show()方法实现。
Point::show()方法:按输出格式输出Point对象。
Point::showCounter()方法:按格式输出当前程序中Point对象的计数。
Point::showSumOfPoint()方法:按格式输出程序运行至当前存在过的Point对象总数。
Input
输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。
Output
对每个Point对象,调用show()方法输出其值,或者用showPoint()函数来输出(通过参数传入的)Point对象的值:X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。每个坐标的输出精度为最长16位。调用用showCounter()方法和showSumOfPoint()输出Point对象的计数统计,输出格式见sample。
C语言的输入输出被禁用。
Sample Input
1,2
3,3
2,1
Sample Output
Point : (1, 2)
Current : 2 points.
Point : (3, 3)
Current : 2 points.
Point : (2, 1)
Current : 2 points.
In total : 4 points.
Current : 3 points.
Point : (0, 0)
Point : (1, 1)
Point : (0, 0)
In total : 6 points.
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
#include<iomanip>
using namespace std;
class Point{
private:
double x,y;
static int sum,num;
public:
Point():x(0),y(0){num++;sum++;}
Point(double a):x(a),y(1){num++;sum++;}
Point(double a,double b):x(a),y(b){num++;sum++;}
Point(const Point&p){x=p.x;y=p.y;num++;sum++;}
~Point(){num--;}
void show(){cout<<setprecision(16)<<"Point : ("<<x<<", "<<y<<")"<<endl;}
static void showCounter(){cout<<setprecision(16)<<"Current : "<<num<<" points."<<endl;}
static void showSumOfPoint(){cout<<setprecision(16)<<"In total : "<<sum<<" points."<<endl;}
};
void showPoint(Point &a,Point &b,Point &c){a.show();b.show();c.show();}
int Point::sum=0;
int Point::num=0;
int main()
{
char c;
double a, b;
Point q;
while(std::cin>>a>>c>>b)
{
Point p(a, b);
p.show();
p.showCounter();
}
q.showSumOfPoint();
Point q1(q), q2(1);
Point::showCounter();
showPoint(q1, q2, q);
Point::showSumOfPoint();
}
Problem B: 平面上的点——Point类 (V)
Problem B: 平面上的点——Point类 (V)
Time Limit: 1 Sec Memory Limit: 4 MB
Submit: 5067 Solved: 1715
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上的点的操作。
根据“append.cc”,完成Point类的构造方法和接口描述中的方法。
接口描述:
showPoint()函数:按输出格式输出Point对象。
Point::show()方法:按输出格式输出Point对象。
Point::showSumOfPoint()方法:按格式输出程序运行至当前存在过的Point对象总数。
Point::x()方法:取x坐标。
Point::y()方法:取y坐标。
Point::x(double)方法:传参数设置x坐标并返回。
Point::y(double)方法:传参数设置y坐标并返回。
Point::getX()方法:取x坐标。
Point::getY()方法:取y坐标。
Point::setX()方法:传参数设置x坐标并返回。
Point::setY()方法:传参数设置y坐标并返回。
Point::setPoint(double,double)方法:设置Point对象的x坐标(第一个参数)和y坐标(第二个参数)并返回本对象
Input
输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。
Output
用ShowPoint()函数来输出(通过参数传入的)Point对象的值或坐标值:X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。每个坐标的输出精度为最长16位。
对每个Point对象,调用show()方法输出其值,输出格式与ShowPoint()函数略有不同:“Point[i] :”,i表示这是程序运行过程中第i个被创建的Point对象。
调用showSumOfPoint()输出Point对象的计数统计,输出格式见sample。
C语言的输入输出被禁用。
Sample Input
1,2
3,3
2,1
Sample Output
Point : (1, 2)
Point : (3, 3)
Point : (2, 1)
Point : (1, 1)
Point : (4, -3)
==========gorgeous separator==========
Point[1] : (1, 0)
Point[2] : (3, 3)
Point[3] : (0, 0)
Point[4] : (4, -3)
Point[64] : (1, 0)
Point[64] : (1, 0)
==========gorgeous separator==========
In total : 66 points.
HINT
传递和返回引用是不构造新对象的。给函数正确的返回值。
Append Code
[Submit][Status][Web Board]
#include<iostream>
#include<iomanip>
using namespace std;
class Point{
private:
double m,n;
int id;
static int sum;
public:
double x(){return m;}
double y(){return n;}
double x(double a){m=a;return m;}
double y(double b){n=b;return n;}
double getX(){return m;}
double getY(){return n;}
double setX(double a){m=a;return m;}
double setY(double b){n=b;return n;}
Point& setPoint(double a,double b){m=a;n=b;return *this;}
Point():m(0),n(0){sum++;id=sum;}
Point(double a):m(a),n(a){sum++;id=sum;}
Point(double a,double b):m(a),n(b){sum++;id=sum;}
Point(const Point&p){m=p.m;n=p.n;sum++;id=sum;}
~Point(){}
void show(){cout<<setprecision(16)<<"Point["<<id<<"] : ("<<m<<", "<<n<<")"<<endl;}
static void showSumOfPoint(){cout<<setprecision(16)<<"In total : "<<sum<<" points."<<endl;}
};
int Point::sum=0;
void ShowPoint(Point p)
{
cout<<std::setprecision(16)<<"Point : ("<<p.x()<<", "<<p.y()<<")"<<endl;
}
void ShowPoint(double x, double y)
{
Point p(x, y);
cout<<std::setprecision(16)<<"Point : ("<<p.x()<<", "<<p.y()<<")"<<endl;
}
void ShowPoint(Point &p, double x, double y)
{
cout<<std::setprecision(16)<<"Point : ("<<p.x(x)<<", "<<p.x(y)<<")"<<endl;
}
int main()
{
int l(0);
char c;
double a, b;
Point pt[60];
while(std::cin>>a>>c>>b)
{
if(a == b)
ShowPoint(pt[l].setPoint(a, b));
if(a > b)
ShowPoint(a, b);
if(a < b)
ShowPoint(pt[l], a, b);
l++;
}
Point p(a), q(b);
ShowPoint(q);
double x(0), y(0);
for(int i = 0; i < l; i++)
x += pt[i].getX(), y -= pt[i].getY();
ShowPoint(pt[l].setX(x), pt[l].setY(y));
cout<<"==========gorgeous separator=========="<<endl;
for(int i = 0; i <= l; i++)
pt[i].show();
q.setPoint(q.x() - p.x() + a, q.y() - p.y() + b).show();
q.show();
cout<<"==========gorgeous separator=========="<<endl;
p.showSumOfPoint();
}
Problem C: 平面上的点——Point类 (VI)
Problem C: 平面上的点——Point类 (VI)
Time Limit: 1 Sec Memory Limit: 4 MB
Submit: 4838 Solved: 1847
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定。现在我们封装一个“Point类”来实现平面上的点的操作。
根据“append.cc”,完成Point类的构造方法和接口描述中的方法和函数。
接口描述:
showPoint()函数:按输出格式输出Point对象。
Point::show()方法:按输出格式输出Point对象。
Point::showSumOfPoint()方法:按格式输出程序运行至当前存在过的Point对象总数。
Point::x()方法:取x坐标。
Point::y()方法:取y坐标。
Point::x(double)方法:传参数设置x坐标并返回。
Point::y(double)方法:传参数设置y坐标并返回。
Point::setPoint(double,double)方法:设置Point对象的x坐标(第一个参数)和y坐标(第二个参数)并返回本对象。
Point::isEqual()方法:判断传入的参数与对象的坐标是否相同,相同返回true。
Point::copy()方法:传参数复制给对象。
Point::inverse()方法,有两个版本:不传参数则将对象自身的x坐标和y坐标互换;若将Point对象做参数传入,则将传入对象的坐标交换复制给对象自身,不修改参数的值。
Input
输入多行,每行为一组坐标“x,y”,表示点的x坐标和y坐标,x和y的值都在double数据范围内。
Output
用ShowPoint()函数来输出(通过参数传入的)Point对象的值或坐标值:X坐标在前,Y坐标在后,Y坐标前面多输出一个空格。每个坐标的输出精度为最长16位。
对每个Point对象,调用show()方法输出其值,输出格式与ShowPoint()函数略有不同:“Point[i] :”,i表示这是程序运行过程中第i个被创建的Point对象。
调用showSumOfPoint()输出Point对象的计数统计,输出格式见sample。
C语言的输入输出被禁用。
Sample Input
1,2
3,3
2,1
Sample Output
Point[3] : (1, 2)
Point[1] : (2, 1)
Point[4] : (3, 3)
Point[1] : (3, 3)
Point[5] : (1, 2)
Point[1] : (1, 2)
Point[2] : (0, 0)
==========gorgeous separator==========
Point[2] : (-7, 5)
Point[3] : (1, 2)
Point[4] : (3, 3)
Point[5] : (1, 2)
Point[6] : (-7, 5)
==========gorgeous separator==========
Point[63] : (3, 3)
Point : (3, 3)
Point : (3, 3)
Point : (3, 3)
In total : 64 points.
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
#include<iomanip>
using namespace std;
class Point
{
private:
double x1;
double y1;
int order;
static int coun ;
public :
Point ():x1(0),y1(0){coun ++; order=coun;}
Point(double a , double b):x1(a) , y1(b){coun ++;order=coun;}
Point(double a ):x1(a),y1(a){coun ++;order=coun;}
///Point(const Point & p){ coun++;aCoun++;x1 = p.x1;y1 = p.y1;order = (aCoun+1);}
///~Point(){coun--;}
void show()const
{
std::cout << "Point["<<order<<"] : ("<<x1<<", " <<y1<<")"<<endl;
}
/*static void showCounter()
{
cout << "Current : "<<coun <<" points."<<endl;
}*/
static void showSumOfPoint(){cout<<setprecision(16)<<"In total : "<<coun<<" points."<<endl;}
double x()const{return x1;}
double y()const{return y1;}
double x(double x){x1 = x;return x1;}
double y(double y){y1 = y;return y1;}
double getX(){return x1;}
double getY(){return y1;}
double setX(double x){return x1=x;}
double setY(double y){return y1=y;}
Point & setPoint(double x ,double y)
{
x1 = x;
y1 = y;
return *this;
}
bool isEqual( Point & p)const
{
if(p.x1 == x1 && p.y1 == y1 )
return true;
else
return false;
}
Point & copy(Point & p)
{
x1 = p.x1;
y1 = p.y1;
return *this;
}
Point & inverse()
{
double temp;
temp = x1;
x1 = y1;
y1 = temp;
return*this;
}
Point& inverse(Point &p){x1=p.y1;y1=p.x1;return *this;}
};
int Point::coun =0;
void ShowPoint(const Point &p)
{
cout << "Point : ("<<std::setprecision(16)<<p.x()<<", " <<p.y() <<")"<<endl;
}
void ShowPoint(double x, double y)
{
cout << "Point : ("<<std::setprecision(16)<<x<<", " <<y <<")"<<endl;
}
void ShowPoint(Point &p, double x, double y)
{
cout<<std::setprecision(16)<<"Point : ("<<p.x(x)<<", "<<p.x(y)<<")"<<endl;
}
int main()
{
int l(0);
char c;
double a, b;
Point p, q, pt[60];
while(std::cin>>a>>c>>b)
{
if(a == b)
p.copy(pt[l].setPoint(a, b));
if(a > b)
p.copy(pt[l].setPoint(a, b).inverse());
if(a < b)
p.inverse(pt[l].setPoint(a, b));
if(a < 0)
q.copy(p).inverse();
if(b < 0)
q.inverse(p).copy(pt[l]);
pt[l++].show();
p.show();
}
q.show();
cout<<"==========gorgeous separator=========="<<endl;
double x(0), y(0);
for(int i = 0; i < l; i++)
x += pt[i].x(), y -= pt[i].y();
pt[l].x(y), pt[l].y(x);
q.copy(pt[l]).show();
for(int i = 0; i <= l; i++)
pt[i].show();
cout<<"==========gorgeous separator=========="<<endl;
const Point const_point(3, 3);
const_point.show();
for(int i = 0; i <= l; i++)
{
if(const_point.isEqual(pt[i]))
{
ShowPoint(const_point);
ShowPoint(const_point.x(), const_point.y());
ShowPoint(Point(const_point.x(), const_point.y()));
}
}
const_point.showSumOfPoint();
}
Problem D: 平面上的点和线——Point类、Line类 (I)
Problem D: 平面上的点和线——Point类、Line类 (I)
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 2814 Solved: 1374
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段。现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作。
根据“append.cc”,完成Point类和Line类的构造方法和show()方法。
接口描述:
Point::show()方法:按格式输出Point对象。
Line::show()方法:按格式输出Line对象。
Input
输入的第一行为N,表示后面有N行测试样例。
每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空格分开,x和y的值都在double数据范围内。
Output
输出为多行,每行为一条线段,起点坐标在前终点坐标在后,每个点的X坐标在前,Y坐标在后,Y坐标前面多输出一个空格,用括号包裹起来。输出格式见sample。
Sample Input
4
0,0 1,1
1,1 2,3
2,3 4,5
0,1 1,0
Sample Output
Point : (0, 0)
Line : (0, 0) to (1, 1)
Line : (1, 1) to (2, 3)
Line : (2, 3) to (4, 5)
Line : (0, 1) to (1, 0)
Line : (1, -2) to (2, -1)
Line : (1, -2) to (0, 0)
Line : (2, -1) to (0, 0)
Line : (0, 0) to (2, -1)
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
#include<iomanip>
using namespace std;
class Point{
friend class Line;
private:
double x,y;
public:
Point():x(0),y(0){};
Point(double a,double b):x(a),y(b){}
void show(){cout<<"Point : ("<<x<<", "<<y<<")"<<endl;}
};
class Line{
friend class Point;
private:
Point p1,p2;
public:
Line(Point p,Point q):p1(p),p2(q){}
Line(double x1,double y1,double x2,double y2):p1(x1,y1),p2(x2,y2){}
void show(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.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;
for(i = 1; i <= num; i++)
{
std::cin>>x1>>c>>y1>>x2>>c>>y2;
Line line(x1, y1, x2, y2);
line.show();
}
Line l1(p, q), l2(p, t), l3(q, t), l4(t, q);
l1.show();
l2.show();
l3.show();
l4.show();
}
Problem E: 平面上的点和线——Point类、Line类 (II)
Problem E: 平面上的点和线——Point类、Line类 (II)
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 2641 Solved: 1357
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段。现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作。
根据“append.cc”,完成Point类和Line类的构造方法和show()方法,输出各Line对象的构造和析构次序。
接口描述:
Point::show()方法:按格式输出Point对象。
Line::show()方法:按格式输出Line对象。
Input
输入的第一行为N,表示后面有N行测试样例。每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空格分开,x和y的值都在double数据范围内。
Output
输出为多行,每行为一条线段,起点坐标在前终点坐标在后,每个点的X坐标在前,Y坐标在后,Y坐标前面多输出一个空格,用括号包裹起来。输出格式见sample。
Sample Input
4
0,0 1,1
1,1 2,3
2,3 4,5
0,1 1,0
Sample Output
Point : (0, 0)
Line : (0, 0) to (1, 1) is created.
Line : (0, 0) to (1, 1)
Line : (0, 0) to (1, 1) is erased.
Line : (1, 1) to (2, 3) is created.
Line : (1, 1) to (2, 3)
Line : (1, 1) to (2, 3) is erased.
Line : (2, 3) to (4, 5) is created.
Line : (2, 3) to (4, 5)
Line : (2, 3) to (4, 5) is erased.
Line : (0, 1) to (1, 0) is created.
Line : (0, 1) to (1, 0)
Line : (0, 1) to (1, 0) is erased.
Line : (1, -2) to (2, -1) is created.
Line : (1, -2) to (0, 0) is created.
Line : (2, -1) to (0, 0) is created.
Line : (0, 0) to (2, -1) is created.
Line : (1, -2) to (2, -1)
Line : (1, -2) to (0, 0)
Line : (2, -1) to (0, 0)
Line : (0, 0) to (2, -1)
Line : (0, 0) to (2, -1) is erased.
Line : (2, -1) to (0, 0) is erased.
Line : (1, -2) to (0, 0) is erased.
Line : (1, -2) to (2, -1) is erased.
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
using namespace std;
class Point{
friend class Line;
private:
double x,y;
public:
Point():x(0),y(0){};
Point(double a,double b):x(a),y(b){}
void show(){cout<<"Point : ("<<x<<", "<<y<<")"<<endl;}
};
class Line{
friend class Point;
private:
Point p1,p2;
public:
Line(Point p,Point q):p1(p),p2(q){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;}
Line(double x1,double y1,double x2,double y2):p1(x1,y1),p2(x2,y2){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;}
~Line(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is erased."<<endl;}
void show(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.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;
for(i = 1; i <= num; i++)
{
std::cin>>x1>>c>>y1>>x2>>c>>y2;
Line line(x1, y1, x2, y2);
line.show();
}
Line l1(p, q), l2(p, t), l3(q, t), l4(t, q);
l1.show();
l2.show();
l3.show();
l4.show();
}
Problem F: 平面上的点和线——Point类、Line类 (III)
Problem F: 平面上的点和线——Point类、Line类 (III)
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 3854 Solved: 1367
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段。现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作。
根据“append.cc”,完成Point类和Line类的构造方法和show()方法,输出各Line对象和Point对象的构造和析构次序。
接口描述:
Point::show()方法:按格式输出Point对象。
Line::show()方法:按格式输出Line对象。
Input
输入的第一行为N,表示后面有N行测试样例。每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空格分开,x和y的值都在double数据范围内。
Output
输出为多行,每行为一条线段,起点坐标在前终点坐标在后,每个点的X坐标在前,Y坐标在后,Y坐标前面多输出一个空格,用括号包裹起来。输出格式见sample。
C语言的输入输出被禁用。
Sample Input
4
0,0 1,1
1,1 2,3
2,3 4,5
0,1 1,0
Sample Output
Point : (1, -2) is created.
Point : (2, -1) is created.
Point : (0, 0) is created.
Point : (0, 0)
=========================
Point : (0, 0) is created.
Point : (1, 1) is created.
Line : (0, 0) to (1, 1) is created.
Line : (0, 0) to (1, 1)
Line : (0, 0) to (1, 1) is erased.
Point : (1, 1) is erased.
Point : (0, 0) is erased.
=========================
Point : (1, 1) is created.
Point : (2, 3) is created.
Line : (1, 1) to (2, 3) is created.
Line : (1, 1) to (2, 3)
Line : (1, 1) to (2, 3) is erased.
Point : (2, 3) is erased.
Point : (1, 1) is erased.
=========================
Point : (2, 3) is created.
Point : (4, 5) is created.
Line : (2, 3) to (4, 5) is created.
Line : (2, 3) to (4, 5)
Line : (2, 3) to (4, 5) is erased.
Point : (4, 5) is erased.
Point : (2, 3) is erased.
=========================
Point : (0, 1) is created.
Point : (1, 0) is created.
Line : (0, 1) to (1, 0) is created.
Line : (0, 1) to (1, 0)
Line : (0, 1) to (1, 0) is erased.
Point : (1, 0) is erased.
Point : (0, 1) is erased.
=========================
Point : (1, -2) is copied.
Point : (2, -1) is copied.
Line : (1, -2) to (2, -1) is created.
Point : (1, -2) is copied.
Point : (0, 0) is copied.
Line : (1, -2) to (0, 0) is created.
Point : (2, -1) is copied.
Point : (0, 0) is copied.
Line : (2, -1) to (0, 0) is created.
Point : (0, 0) is copied.
Point : (2, -1) is copied.
Line : (0, 0) to (2, -1) is created.
Line : (1, -2) to (2, -1)
Line : (1, -2) to (0, 0)
Line : (2, -1) to (0, 0)
Line : (0, 0) to (2, -1)
Line : (0, 0) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (0, 0) is erased.
Line : (2, -1) to (0, 0) is erased.
Point : (0, 0) is erased.
Point : (2, -1) is erased.
Line : (1, -2) to (0, 0) is erased.
Point : (0, 0) is erased.
Point : (1, -2) is erased.
Line : (1, -2) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
Point : (0, 0) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
using namespace std;
class Point{
friend class Line;
private:
double x,y;
public:
Point():x(0),y(0){cout<<"Point : ("<<x<<", "<<y<<") is created."<<endl;};
Point(double a,double b):x(a),y(b){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{
friend class Point;
private:
Point p1,p2;
public:
Line(Point &p,Point &q):p1(p),p2(q){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;}
Line(double x1,double y1,double x2,double y2):p1(x1,y1),p2(x2,y2){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;}
~Line(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is erased."<<endl;}
void show(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.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;
for(i = 1; i <= num; i++)
{
std::cout<<"=========================\n";
std::cin>>x1>>c>>y1>>x2>>c>>y2;
Line line(x1, y1, x2, y2);
line.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();
}
Problem G: 平面上的点和线——Point类、Line类 (IV)
Problem G: 平面上的点和线——Point类、Line类 (IV)
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 2619 Solved: 1277
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段。现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作。
根据“append.cc”,完成Point类和Line类的构造方法和show()方法,输出各Line对象和Point对象的构造和析构次序。
接口描述:
Point::show()方法:按格式输出Point对象。
Line::show()方法:按格式输出Line对象。
Input
输入的第一行为N,表示后面有N行测试样例。
每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空格分开,x和y的值都在double数据范围内。
Output
输出为多行,每行为一条线段,起点坐标在前终点坐标在后,每个点的X坐标在前,Y坐标在后,Y坐标前面多输出一个空格,用括号包裹起来。输出格式见sample。
C语言的输入输出被禁用。
Sample Input
4
0,0 1,1
1,1 2,3
2,3 4,5
0,1 1,0
Sample Output
Point : (1, -2) is created.
Point : (2, -1) is created.
Point : (0, 0) is created.
Point : (0, 0)
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
=========================
Line : (0, 0) to (1, 1)
=========================
Line : (1, 1) to (2, 3)
=========================
Line : (2, 3) to (4, 5)
=========================
Line : (0, 1) to (1, 0)
=========================
Point : (1, -2) is copied.
Point : (2, -1) is copied.
Line : (1, -2) to (2, -1) is created.
Point : (1, -2) is copied.
Point : (0, 0) is copied.
Line : (1, -2) to (0, 0) is created.
Point : (2, -1) is copied.
Point : (0, 0) is copied.
Line : (2, -1) to (0, 0) is created.
Point : (0, 0) is copied.
Point : (2, -1) is copied.
Line : (0, 0) to (2, -1) is created.
Line : (1, -2) to (2, -1)
Line : (1, -2) to (0, 0)
Line : (2, -1) to (0, 0)
Line : (0, 0) to (2, -1)
Line : (0, 0) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (0, 0) is erased.
Line : (2, -1) to (0, 0) is erased.
Point : (0, 0) is erased.
Point : (2, -1) is erased.
Line : (1, -2) to (0, 0) is erased.
Point : (0, 0) is erased.
Point : (1, -2) is erased.
Line : (1, -2) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
Line : (2, 3) to (4, 5) is erased.
Point : (4, 5) is erased.
Point : (2, 3) is erased.
Line : (1, 1) to (2, 3) is erased.
Point : (2, 3) is erased.
Point : (1, 1) is erased.
Line : (0, 0) to (1, 1) is erased.
Point : (1, 1) is erased.
Point : (0, 0) is erased.
Line : (0, 0) to (0, 0) is erased.
Point : (0, 0) is erased.
Point : (0, 0) is erased.
Point : (0, 0) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
using namespace std;
class Point{
friend class Line;
private:
double x,y;
public:
Point(double a=0,double b=0):x(a),y(b){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{
friend class Point;
private:
Point p1,p2;
public:
Line(Point &p,Point &q):p1(p),p2(q){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;}
Line(double x1=0,double y1=0,double x2=0,double y2=0):p1(x1,y1),p2(x2,y2){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;}
~Line(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is erased."<<endl;}
void SetLine(double a,double b,double c,double d){p1.x=a;p1.y=b;p2.x=c;p2.y=d;}
void show(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.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 = 1; 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();
}
Problem H: 平面上的点和线——Point类、Line类 (V)
Problem H: 平面上的点和线——Point类、Line类 (V)
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 3774 Solved: 1425
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段。现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作。
根据“append.cc”,完成Point类和Line类的构造方法和show()方法,输出各Line对象和Point对象的构造和析构次序。
接口描述:
Point::show()方法:按格式输出Point对象。
Line::show()方法:按格式输出Line对象。
Line::SetLine(double, double, double, double)方法:设置Line对象起点的x,y坐标(第一个和第二参数)和终点的x,y坐标(第三个和第四个坐标),并返回本对象
Line::SetLine(const Point &, const Point &)方法:设置Line对象的起点(第一个参数)和终点(第二个坐标),并返回本对象
Line::SetLine(const Line&)方法:设置Line对象,复制参数的坐标,并返回本对象
Line::readLine()方法:从标准输入上读入坐标,格式见Sample
Input
输入的第一行为N,表示后面有N行测试样例。
每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空格分开,x和y的值都在double数据范围内。
Output
输出为多行,每行为一条线段,起点坐标在前终点坐标在后,每个点的X坐标在前,Y坐标在后,Y坐标前面多输出一个空格,用括号包裹起来。输出格式见sample。
C语言的输入输出被禁用。
Sample Input
4
0,0 1,1
1,1 2,3
2,3 4,5
0,1 1,0
Sample Output
Point : (1, -2) is created.
Point : (2, -1) is created.
Point : (0, 0) is created.
Point : (0, 0)
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Line : (0, 0) to (1, 1)
Line : (1, 1) to (2, 3)
Line : (2, 3) to (4, 5)
Line : (0, 1) to (1, 0)
Point : (1, -2) is copied.
Point : (2, -1) is copied.
Line : (1, -2) to (2, -1) is created.
Point : (1, -2) is copied.
Point : (0, 0) is copied.
Line : (1, -2) to (0, 0) is created.
Point : (2, -1) is copied.
Point : (0, 0) is copied.
Line : (2, -1) to (0, 0) is created.
Point : (1, -2) is copied.
Point : (2, -1) is copied.
Line : (1, -2) to (2, -1) is copied.
Line : (1, -2) to (2, -1)
Line : (1, -2) to (2, -1)
Line : (2, -1) to (0, 0)
Line : (0, 0) to (2, -1)
Line : (0, 0) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (0, 0) is erased.
Line : (2, -1) to (0, 0) is erased.
Point : (0, 0) is erased.
Point : (2, -1) is erased.
Line : (1, -2) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
Line : (1, -2) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
Line : (0, 1) to (1, 0) is erased.
Point : (1, 0) is erased.
Point : (0, 1) is erased.
Line : (2, 3) to (4, 5) is erased.
Point : (4, 5) is erased.
Point : (2, 3) is erased.
Line : (1, 1) to (2, 3) is erased.
Point : (2, 3) is erased.
Point : (1, 1) is erased.
Line : (0, 0) to (1, 1) is erased.
Point : (1, 1) is erased.
Point : (0, 0) is erased.
Point : (0, 0) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
using namespace std;
class Point{
friend class Line;
private:
double x,y;
public:
Point(double a=0,double b=0):x(a),y(b){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{
friend class Point;
private:
Point p1,p2;
public:
Line(Point &p,Point &q):p1(p),p2(q){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;}
Line(double x1=0,double y1=0,double x2=0,double y2=0):p1(x1,y1),p2(x2,y2){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is created."<<endl;}
///Line(const Line&l){p1=l.p1;p2=l.p2;cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is copied."<<endl;}
Line(const Line&l):p1(l.p1),p2(l.p2){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is copied."<<endl;}
~Line(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is erased."<<endl;}
Line& setLine(double a,double b,double c,double d){p1.x=a;p1.y=b;p2.x=c;p2.y=d;return *this;}
Line& setLine(const Point &p, const Point &q){p1=p;p2=q;return *this;}
Line& setLine(const Line& l){*this=l;return *this;}
void show(){cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<")"<<endl;}
void readLine(){char c;cin>>p1.x>>c>>p1.y>>p2.x>>c>>p2.y;}
};
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();
}
Problem I: 平面上的点和线——Point类、Line类 (VI)
Problem I: 平面上的点和线——Point类、Line类 (VI)
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 3275 Solved: 1182
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段。现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作。
根据“append.cc”,完成Point类和Line类的构造方法和show()方法,输出各Line对象和Point对象的构造和析构次序。
接口描述:
Point::show()方法:按格式输出Point对象。
Point::x()方法:取x坐标。
Point::y()方法:取y坐标。
Line::show()方法:按格式输出Line对象。
Line::SetLine(double, double, double, double)方法:设置Line对象起点的x,y坐标(第一个和第二参数)和终点的x,y坐标(第三个和第四个坐标),并返回本对象
Line::SetLine(const Point &, const Point &)方法:设置Line对象的起点(第一个参数)和终点(第二个坐标),并返回本对象
Line::SetLine(const Line&)方法:设置Line对象,复制参数的坐标,并返回本对象
Line::readLine()方法:从标准输入上读入坐标,格式见Sample
Line::start()方法:取Line的起点
Line::end()方法:取Line的终点
Line::setStart()方法:设置Line的起点
Line::setEnd()方法:设置Line的终点
以下三个函数用于输出Line对象,格式同sample
showLineCoordinate(const Line&)
showLinePoint(const Line&)
showLine(const Line&)
Input
输入的第一行为N,表示后面有N行测试样例。
每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空格分开,x和y的值都在double数据范围内。
Output
输出为多行,每行为一条线段,起点坐标在前终点坐标在后,每个点的X坐标在前,Y坐标在后,Y坐标前面多输出一个空格,用括号包裹起来。输出格式见sample。
C语言的输入输出被禁用。
Sample Input
4
0,0 1,1
1,1 2,3
2,3 4,5
0,1 1,0
Sample Output
Point : (1, -2) is created.
Point : (2, -1) is created.
Point : (0, 0) is created.
Point : (0, 0)
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Point : (0, 0) is created.
Point : (0, 0) is created.
Line : (0, 0) to (0, 0) is created.
Line : (0, 0) to (1, 1)
Line : (1, 1) to (2, 3)
Line : (2, 3) to (4, 5)
Line : (0, 1) to (1, 0)
Point : (1, -2) is copied.
Point : (2, -1) is copied.
Line : (1, -2) to (2, -1) is created.
Point : (1, -2) is copied.
Point : (0, 0) is copied.
Line : (1, -2) to (0, 0) is created.
Point : (2, -1) is copied.
Point : (0, 0) is copied.
Line : (2, -1) to (0, 0) is created.
Point : (1, -2) is copied.
Point : (2, -1) is copied.
Line : (1, -2) to (2, -1) is copied.
Line : (1, -2) to (2, -1)
Line : Point : (1, -2) to Point : (0, 0)
Line : Point : (1, -2) to Point : (2, -1)
Line : (0, 0) to (2, -1)
Line : (0, 0) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (0, 0) is erased.
Line : (1, -2) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
Line : (1, -2) to (0, 0) is erased.
Point : (0, 0) is erased.
Point : (1, -2) is erased.
Line : (1, -2) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
Line : (0, 1) to (1, 0) is erased.
Point : (1, 0) is erased.
Point : (0, 1) is erased.
Line : (2, 3) to (4, 5) is erased.
Point : (4, 5) is erased.
Point : (2, 3) is erased.
Line : (1, 1) to (2, 3) is erased.
Point : (2, 3) is erased.
Point : (1, 1) is erased.
Line : (0, 0) to (1, 1) is erased.
Point : (1, 1) is erased.
Point : (0, 0) is erased.
Line : (0, 0) to (2, -1) is erased.
Point : (2, -1) is erased.
Point : (0, 0) is erased.
Point : (0, 0) is erased.
Point : (2, -1) is erased.
Point : (1, -2) is erased.
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
using namespace std;
class Point{
friend class Line;
private:
double m,n;
public:
///Point():m(0),n(0){cout<<"Point : ("<<m<<", "<<n<<") is created."<<endl;}
Point(double a):m(a),n(a){cout<<"Point : ("<<m<<", "<<n<<") is created."<<endl;}
Point(double a=0,double b=0):m(a),n(b){cout<<"Point : ("<<m<<", "<<n<<") is created."<<endl;}
Point(const Point&p){m=p.m;n=p.n;cout<<"Point : ("<<m<<", "<<n<<") is copied."<<endl;}
~Point(){cout<<"Point : ("<<m<<", "<<n<<") is erased."<<endl;}
void show(){cout<<"Point : ("<<m<<", "<<n<<")"<<endl;}
double x()const {return m;}
double y()const {return n;}
///Point &setPoint(double x,double y){m=x;n=y;return *this;}
void showNoEndOfLine()const{cout<<"Point : ("<<m<<", "<<n<<")";}
};
class Line{
friend class Point;
private:
Point p1,p2;
public:
Line(Point &p,Point &q):p1(p),p2(q){cout<<"Line : ("<<p1.m<<", "<<p1.n<<") to ("<<p2.m<<", "<<p2.n<<") is created."<<endl;}
Line(double x1=0,double y1=0,double x2=0,double y2=0):p1(x1,y1),p2(x2,y2){cout<<"Line : ("<<p1.m<<", "<<p1.n<<") to ("<<p2.m<<", "<<p2.n<<") is created."<<endl;}
Line(const Line&l):p1(l.p1),p2(l.p2){cout<<"Line : ("<<p1.m<<", "<<p1.n<<") to ("<<p2.m<<", "<<p2.n<<") is copied."<<endl;}
~Line(){cout<<"Line : ("<<p1.m<<", "<<p1.n<<") to ("<<p2.m<<", "<<p2.n<<") is erased."<<endl;}
Line& setLine(double a,double b,double c,double d){p1.m=a;p1.n=b;p2.m=c;p2.n=d;return *this;}
Line& setLine(const Point &p, const Point &q){p1=p;p2=q;return *this;}
Line& setLine(const Line& l){*this=l;return *this;}
void show()const{cout<<"Line : ("<<p1.m<<", "<<p1.n<<") to ("<<p2.m<<", "<<p2.n<<")"<<endl;}
void readLine(){char c;cin>>p1.m>>c>>p1.n>>p2.m>>c>>p2.n;}
const Point &start()const{return p1;}
const Point &end()const{return p2;}
void setStart(Point &p){p1=p;}
void setEnd(Point &p){p2=p;}
};
void showLineCoordinate(const Line& line)
{
std::cout<<"Line : ";
std::cout<<"("<<line.start().x()<<", "<<line.start().y()<<")";
std::cout<<" to ";
std::cout<<"("<<line.end().x()<<", "<<line.end().y()<<")";
std::cout<<std::endl;
}
void showLinePoint(const Line& line)
{
std::cout<<"Line : ";
line.start().showNoEndOfLine();
std::cout<<" to ";
line.end().showNoEndOfLine();
std::cout<<std::endl;
}
void showLine(const Line& line)
{
line.show();
}
int main()
{
int num, i;
Point p(1, -2), q(2, -1), t;
t.show();
std::cin>>num;
Line line[num + 1];
for(i = 1; i <= num; i++)
{
line[i].readLine();
showLine(line[i]);
}
Line l1(p, q), l2(p,t), l3(q,t), l4(l1);
showLineCoordinate(l1);
showLinePoint(l2);
showLinePoint(l3.setLine(l1));
showLineCoordinate(l4.setLine(t,q));
line[0].setStart(t);
line[0].setEnd(q);
}
Problem J: 平面上的点和线——Point类、Line类 (VII)
Problem J: 平面上的点和线——Point类、Line类 (VII)
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 2151 Solved: 1171
[Submit][Status][Web Board]
Description
在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段。现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作。
根据“append.cc”,完成Point类和Line类的构造方法和show()方法,输出各Line对象和Point对象的构造和析构次序。
接口描述:
Point::showCounter()方法:按格式输出当前程序中Point对象的计数。
Point::showSum()方法:按格式输出程序运行至当前存在过的Point对象总数。
Line::showCounter()方法:按格式输出当前程序中Line对象的计数。
Line::showSum()方法:按格式输出程序运行至当前存在过的Line对象总数。
Input
输入的第一行为N,表示后面有N行测试样例。
每行为两组坐标“x,y”,分别表示线段起点和终点的x坐标和y坐标,两组坐标间用一个空格分开,x和y的值都在double数据范围内。
Output
输出格式见sample。
C语言的输入输出被禁用。
Sample Input
4
0,0 1,1
1,1 2,3
2,3 4,5
0,1 1,0
Sample Output
Current : 3 points.
In total : 3 points.
Current : 6 lines.
In total : 6 lines.
Current : 17 points.
In total : 17 points.
Current : 6 lines.
In total : 7 lines.
Current : 15 points.
In total : 17 points.
Current : 6 lines.
In total : 8 lines.
Current : 17 points.
In total : 21 points.
Current : 6 lines.
In total : 9 lines.
Current : 15 points.
In total : 21 points.
Current : 6 lines.
In total : 10 lines.
Current : 17 points.
In total : 25 points.
Current : 6 lines.
In total : 11 lines.
Current : 15 points.
In total : 25 points.
Current : 6 lines.
In total : 12 lines.
Current : 17 points.
In total : 29 points.
Current : 6 lines.
In total : 13 lines.
Current : 15 points.
In total : 29 points.
Current : 9 lines.
In total : 17 lines.
Current : 21 points.
In total : 37 points.
Current : 13 lines.
In total : 21 lines.
Current : 21 points.
In total : 45 points.
HINT
Append Code
[Submit][Status][Web Board]
#include<iostream>
using namespace std;
class Point{
friend class Line;
private:
double m,n;
static int psum,pnum;
public:
Point(double a=0,double b=0):m(a),n(b){psum++;pnum++;}
Point(const Point&p){m=p.m;n=p.n;psum++;pnum++;}
~Point(){pnum--;}
static void showCounter(){cout<<"Current : "<<pnum<<" points."<<endl;}
static void showSum(){cout<<"In total : "<<psum<<" points."<<endl;}
};
class Line{
friend class Point;
private:
Point p1,p2;
static int lsum,lnum;
public:
Line(Point &p,Point &q):p1(p),p2(q){lsum++;lnum++;}
Line(double x1=0,double y1=0,double x2=0,double y2=0):p1(x1,y1),p2(x2,y2){lsum++;lnum++;}
///Line(const Line&l){p1=l.p1;p2=l.p2;cout<<"Line : ("<<p1.x<<", "<<p1.y<<") to ("<<p2.x<<", "<<p2.y<<") is copied."<<endl;}
Line(const Line&l):p1(l.p1),p2(l.p2){lsum++;lnum++;}
~Line(){lnum--;}
void readLine(){char c;cin>>p1.m>>c>>p1.n>>p2.m>>c>>p2.n;}
static void showCounter(){cout<<"Current : "<<lnum<<" lines."<<endl;}
static void showSum(){cout<<"In total : "<<lsum<<" lines."<<endl;}
};
int Point::psum=0;
int Point::pnum=0;
int Line::lsum=0;
int Line::lnum=0;
int main()
{
int num, i;
Point p(1, -2), q(2, -1), t;
t.showCounter();
t.showSum();
std::cin>>num;
Line line[num + 1];
for(i = 1; i <= num; i++)
{
Line *l1, l2;
l1->showCounter();
l1->showSum();
l1 = new Line(p, q);
line[i].readLine();
p.showCounter();
p.showSum();
delete l1;
l2.showCounter();
l2.showSum();
q.showCounter();
q.showSum();
}
Line l1(p, q), l2(p,t), l3(q,t), l4(l1);
Line::showCounter();
Line::showSum();
Point::showCounter();
Point::showSum();
Line *l = new Line[num];
l4.showCounter();
l4.showSum();
delete[] l;
t.showCounter();
t.showSum();
}
实验3
标签:
原文地址:http://www.cnblogs.com/auto1945837845/p/5513563.html