OJ:line point 6
来源:互联网 发布:mac打开防火墙 编辑:程序博客网 时间:2024/05/15 21:19
#include <iostream>using namespace std;class Point{public: double a; double b;public: Point(double aa,double bb):a(aa),b(bb) {cout<<"Point : ("<<a<<", "<<b<<") is created."<<endl;} Point(double aa):a(aa),b(aa) {cout<<"Point : ("<<a<<", "<<b<<") is created."<<endl;} Point():a(0),b(0) {cout<<"Point : ("<<a<<", "<<b<<") is created."<<endl;} double x()const {return a;} double y()const {return b;} void showNoEndOfLine()const {cout<<"Point : ("<<a<<", "<<b<<")";} ~Point(){cout<<"Point : ("<<a<<", "<<b<<") is erased."<<endl;} Point(const Point &q) { a=q.a; b=q.b; cout<<"Point : (" <<a<<", " <<b<<") is copied."<<endl; } void show(){cout<<"Point : ("<<a<<", "<<b<<")"<<endl;}};class Line{ Point d1; Point d2;public: Line():d1(0),d2(0){cout<<"Line : ("<<d1.x()<<", "<<d1.y()<<")"<<" to "<<"("<<d2.x()<<", "<<d2.y()<<") is created."<<endl;} Line (double a,double b,double c,double d):d1(a,b),d2(c,d){cout<<"Line : ("<<d1.x()<<", "<<d1.y()<<")"<<" to "<<"("<<d2.x()<<", "<<d2.y()<<") is created."<<endl;} Line (const Line &p):d1(p.d1),d2(p.d2){cout<<"Line : ("<<d1.x()<<", "<<d1.y()<<")"<<" to "<<"("<<d2.x()<<", "<<d2.y()<<") is copied."<<endl;} Line (Point &a,Point &b):d1(a),d2(b){cout<<"Line : ("<<d1.x()<<", "<<d1.y()<<")"<<" to "<<"("<<d2.x()<<", "<<d2.y()<<") is created."<<endl;} const Point &start() const {return d1;} const Point &end () const {return d2;} void setStart(Point &a1){d1=a1;} void setEnd(Point &a2) {d2=a2;} Line &setLine(const Line &p) {// d1.setx(p.d1.getx());// d1.sety(p.d1.gety());// d2.setx(p.d2.getx());// d2.sety(p.d2.gety()); d1.a=p.d1.a; d1.b=p.d1.b; d2.a=p.d2.a; d2.b=p.d2.b; return *this; } Line &setLine(const Point &aa,const Point &bb) {// d1.setx(a.getx());// d1.sety(a.gety());// d2.setx(b.getx());// d2.sety(b.gety()); d1.a=aa.a; d1.b=aa.b; d2.a=bb.a; d2.b=bb.b; return *this; } Line setLine(double a1,double b1,double a2,double b2) { d1.a=a1; d1.b=b1; d2.a=a2; d2.b=b2; cout<<"Line : ("<<d1.x()<<", "<<d1.y()<<")"<<" to "<<"("<<d2.x()<<", "<<d2.y()<<") is created."<<endl; return *this; } ~Line() { cout<<"Line : ("<<d1.x()<<", "<<d1.y()<<")"<<" to "<<"("<<d2.x()<<", "<<d2.y()<<") is erased."<<endl; } void show()const { cout<<"Line : ("<<d1.x()<<", "<<d1.y()<<")"<<" to "<<"("<<d2.x()<<", "<<d2.y()<<")"<<endl; } void readLine() { char c; double x1,y1,x2,y2; cin>>x1>>c>>y1>>x2>>c>>y2; d1.a=x1; d1.b=y1; d2.a=x2; d2.b=y2; }};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);}
0 0
- OJ:line point 6
- OJ:line point 7
- OJ:line point 5
- line segment and point
- C++ Line,Point类
- point类和Line类
- max-point-on-a-line
- distinct between point and line (for svm)
- (15C++ for homework)Point&Line
- 计算几何(point&line)红书模板
- HDU OJ 3400 Line belt
- 【模拟】Codeforces 710B Optimal Point on a Line
- codeforces 710B - Optimal Point on a Line
- Codeforces 710B-Optimal Point on a Line
- Educational Codeforces Round 16 B. Optimal Point on a Line
- CodeForces-710B. Optimal Point on a Line
- CodeForces 710B Optimal Point on a Line 找中位数
- leedcode——Max Point on a Line
- 【设计模式】使用unity实现建造者模式(Builder mode)
- 平均查找长度
- 单片机I/O口管脚内部结构(锁存器,输出驱动器,三态缓冲器,多路开关)
- Cornerstone SVN可视化工具使用详解
- iOS适配HTTPS,创建一个自签名的SSL证书(x509)具体步骤
- OJ:line point 6
- 利用Lambda表达式让指定对象的所有引用置空
- Celery学习笔记(二)
- js中typeof与instanceof用法的区别
- 算法导论 练习题 6.3-3
- C++学习 11 设计模式 1
- HotSpot虚拟机对象的创建、内存布局、访问定位
- Qt5_使用QtCreator来运行NS3的脚本
- Android主题样式之副作用