//point.h头文件
#include"iostream"
#include"cmath"
using namespace std;
class point
{
private:
double x,y;
public:
point(double =0,double =0);
double Getx();
double Gety();
void Setxy(double,double);
~point();
};
const int num=10;
void Set(point *);
void Display(point *);
double Lenth(point *);
//*************************************
// main 主函数实现
//*************************************
#include"point.h"
point::point(double a,double b)
{x=a;y=b;}
double point::Getx() {return x;}
double point::Gety() {return y;}
void point::Setxy(double a,double b)
{
x=a;y=b;
}
point::~point()
{
cout<<"delete it:"<<x<<","<<y<<endl;
}
int main()
{
point *p=new point[];
if(p==NULL)
{
cout<<"地址申请失败"<<endl;
return 0;
}
Set(p);
// cout<<"内存块的数据如下:"<<endl;
// Display(p);
cout<<"组成的折线长度为:"<<endl;
cout<<Lenth(p);
delete []p;
return 0;
}
//****************************************
//Set(p)函数的实现
//****************************************
point *set(point *p)
{
int i;
double a,b;
for(i=0;i<10;i++,p++)
{
cin>>a>>b;
p->Setxy(a,b);
}
p=p-i+1;
return p;
}
//****************************************
//Display函数的实现
//****************************************
/*void Display(point *p)
{
for(int i=0;i<num;i++)
{
cout<<(p+i)->Getx()<<","<<(p+i)->Gety<<endl;
}
}*/
//*****************************************
//Lenth函数的实现
//*****************************************
double Lenth(point *p)
{
double sum(0.0),a1,a2,b1,b2;
a1=p->Getx();
a2=p->Gety();
for(int i=1;i<10;i++)
{
a2=(p+i)->Getx();
b2=(p+i)->Gety();
sum=sum+sqrt((a1-a2)*(a1-a2)+(b1-b2)*(b1-b2));
a1=a2;
b1=b2;
}
return sum;
}