include<iostream.h>
#include<fstream.h>
#include<iomanip.h>
#include<math.h> /*
下边程序是一个点类和直线类,请再设计一个类Relation,以便于判断两条直线的关系, 可以通过计算两线的斜率,k1*k2=-1为垂直;k1=k2为平行。 */
class Point{ public: Point(){x=0;y=0;count++;} Point(int xx,int yy):x(xx),yy){count++;}
int GetX(){ return x; }
int GetY(){ return y; } virtual float slope(){return 0;}
Point(Point&pt){x=pt.x;y=pt.y;count++;}
friend ostream&operator<<(ostream&show,Point&); ~Point(){count--;}
private: int x,y; static int count; }; int Point::count=0; ostream&operator<<(ostream&show,Point&p1){ show<<p1.x<<","<<p1.y;
return shofriend ostream&operator<<(ostream&,Line&); private: Point P1,P2; };
float Line::slope(){ float xx=P1.GetX()-P2.GetX(); float yy=P1.GetY()-P2.GetY(); return yy/xx; } ostream&operator<<(ostream&disp,Line&L1){ disp<<L1.P1<<"<---->"<<L1.P2<<endl; return disp; }
class Relation:public Line{ public: private: Line L1,L2; };
int main(){ Line s1(2,3,6,5); cout<<s1; cout<<s1.slope(); return 0; }
#include<fstream.h>
#include<iomanip.h>
#include<math.h> /*
下边程序是一个点类和直线类,请再设计一个类Relation,以便于判断两条直线的关系, 可以通过计算两线的斜率,k1*k2=-1为垂直;k1=k2为平行。 */
class Point{ public: Point(){x=0;y=0;count++;} Point(int xx,int yy):x(xx),yy){count++;}
int GetX(){ return x; }
int GetY(){ return y; } virtual float slope(){return 0;}
Point(Point&pt){x=pt.x;y=pt.y;count++;}
friend ostream&operator<<(ostream&show,Point&); ~Point(){count--;}
private: int x,y; static int count; }; int Point::count=0; ostream&operator<<(ostream&show,Point&p1){ show<<p1.x<<","<<p1.y;
return shofriend ostream&operator<<(ostream&,Line&); private: Point P1,P2; };
float Line::slope(){ float xx=P1.GetX()-P2.GetX(); float yy=P1.GetY()-P2.GetY(); return yy/xx; } ostream&operator<<(ostream&disp,Line&L1){ disp<<L1.P1<<"<---->"<<L1.P2<<endl; return disp; }
class Relation:public Line{ public: private: Line L1,L2; };
int main(){ Line s1(2,3,6,5); cout<<s1; cout<<s1.slope(); return 0; }