全文预览

西安交大c++程序设计第九章作业

上传者:塑料瓶子 |  格式:doc  |  页数:24 |  大小:0KB

文档介绍
include<iostream>#include<cmath>usingnamespacestd;#include"point.h"classLine:publicPoint{doublelength;public:Pointpoint1,point2;Line(){point1.SetPoint(0,0);point2.SetPoint(0,0);}Line(inta,intb,intc,intd){SetLine(a,b,c,d);}voidSetLine(inta,intb,intc,intd){point1.SetPoint(a,b);point2.SetPoint(c,d);}voidEndPoint(){intx1=point1.GetX(),y1=point1.GetY(),x2=point2.GetX(),y2=point2.GetY();length=sqrt((x1-x2)*(x1-x2)*1.0+(y1-y2)*(y1-y2)*1.0);}voidPrint(){cout<<length;}};#endif//main文件执行测试#include<iostream>#include"point.h"#include"line.h"usingnamespacestd;intmain(){Pointp(30,50);Linel(12,34,56,78);cout<<"Pointp:";p.Print();cout<<"\nThelocationofLinel:";cout<<"\tPoint1:";l.point1.Print();cout<<"\tPoint2:";l.point2.Print();cout<<"\nThelengthoflinel:";l.EndPoint();l.Print();cout<<endl;return0;}2.实验结果:

收藏

分享

举报
下载此文档