[cpp]
/*
* Copyright (c) 2013, 煙台大學計算機學院
* All rights reserved.
* 文件名稱:test.cpp
* 作者:樊露露
* 完成日期:2013 年 5 月1 0日
* 版本號:v1.0
*
* 輸入描述:無
* 問題描述:
* 程序輸出:
* 問題分析:
* 算法設計:略
*/ #include <iostream>
#include <Cmath>
using namespace std;
class Point
{
public:
Point():x(0),y(0) {};
Point(double x0,double y0):x(x0),y(y0) {};
void PrintPoint();//輸出點的信息
double x,y;
};
void Point::PrintPoint()
{
cout<<"Point:("<<x<<","<<y<<")";
}
class Line:public Point //利用坐標點類定義直線類,由基類的數據成員表示直線的中點
{
public:
Line(Point pts,Point pte):pt1(pts),pt2(pte) {};//構造函數,用初始化直線的兩個端點及由基類數據成員描述的中點
double Length();//計算並返回直線的長度
void PrintLine1();//輸出直線的1個中點
void PrintLine2();//輸出直線的2個端點
private:
class Point pt1,pt2;//直線的兩個端點
};
double Line::Length()
{
double m;
m=sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
return m;
}
void Line::PrintLine1()
{
Point ptm;
ptm.x=(pt1.x+pt2.x)/2;
ptm.y=(pt1.y+pt2.y)/2;
cout<<"("<<ptm.x<<","<<ptm.y<<")";
}
void Line::PrintLine2()
{
cout<<"("<<pt1.x<<","<<pt1.y<<")"<<" "<<"("<<pt2.x<<","<<pt2.y<<")";
}
int main()
{
Point ps(-2,5),pe(7,9);
Line l(ps,pe);
double d;
d=l.Length();
cout<<"\n The length of Line:";
cout<<d<<endl;
cout<<"\n The endpoint of Line:";
l.PrintLine2();
cout<<"\n The middle point of Line:";
l.PrintLine1();
cout<<endl;
return 0;
}
/*
* Copyright (c) 2013, 煙台大學計算機學院
* All rights reserved.
* 文件名稱:test.cpp
* 作者:樊露露
* 完成日期:2013 年 5 月1 0日
* 版本號:v1.0
*
* 輸入描述:無
* 問題描述:
* 程序輸出:
* 問題分析:
* 算法設計:略
*/ #include <iostream>
#include <Cmath>
using namespace std;
class Point
{
public:
Point():x(0),y(0) {};
Point(double x0,double y0):x(x0),y(y0) {};
void PrintPoint();//輸出點的信息
double x,y;
};
void Point::PrintPoint()
{
cout<<"Point:("<<x<<","<<y<<")";
}
class Line:public Point //利用坐標點類定義直線類,由基類的數據成員表示直線的中點
{
public:
Line(Point pts,Point pte):pt1(pts),pt2(pte) {};//構造函數,用初始化直線的兩個端點及由基類數據成員描述的中點
double Length();//計算並返回直線的長度
void PrintLine1();//輸出直線的1個中點
void PrintLine2();//輸出直線的2個端點
private:
class Point pt1,pt2;//直線的兩個端點
};
double Line::Length()
{
double m;
m=sqrt((pt1.x-pt2.x)*(pt1.x-pt2.x)+(pt1.y-pt2.y)*(pt1.y-pt2.y));
return m;
}
void Line::PrintLine1()
{
Point ptm;
ptm.x=(pt1.x+pt2.x)/2;
ptm.y=(pt1.y+pt2.y)/2;
cout<<"("<<ptm.x<<","<<ptm.y<<")";
}
void Line::PrintLine2()
{
cout<<"("<<pt1.x<<","<<pt1.y<<")"<<" "<<"("<<pt2.x<<","<<pt2.y<<")";
}
int main()
{
Point ps(-2,5),pe(7,9);
Line l(ps,pe);
double d;
d=l.Length();
cout<<"\n The length of Line:";
cout<<d<<endl;
cout<<"\n The endpoint of Line:";
l.PrintLine2();
cout<<"\n The middle point of Line:";
l.PrintLine1();
cout<<endl;
return 0;
}