64,682
社区成员
发帖
与我相关
我的任务
分享
//获得一个畸变量数组
#include <iostream>
#include <iomanip>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
const double xp = 0, yp = 0;
class pointcoord
{
private:
double x, y;
public:
pointcoord()
{
x = y = 0;
}
void readcoord(const double& a,const double& b)
{
x = a;
y = b;
}
void showcoord()
{
cout<<setprecision(20)x<<"\t"<<y<<endl;
}
/*pointcoord& operator=(const pointcoord&& apoint)
{
this->x = apoint.x;
this->y = apoint.y;
return *this;
}*/
pointcoord& operator=(const pointcoord& apoint)
{
this->x = apoint.x;
this->y = apoint.y;
return *this;
}
};
pointcoord CalcDistortion(const double &a,const double &b);
int main()
{
double x0 = 0.0, y0 = 0, xn = 0, yn = 0, x_step = 0, y_step = 0;
int n = 0;
double x_offset = 0, y_offset = 0;
pointcoord *Distor_Array;
cout << "Enter x0,y0,xn,yn,n,in sequence" << endl;
cin >> x0 >> y0 >> xn >> yn >> n;
if(n<=0)
{
cout<<"n value error.";
return 0;
}
Distor_Array = new pointcoord[n];
x_offset = x0 - xp;
y_offset = y0 - yp;
x_step = (xn-x0)/n;
y_step = (yn-y0)/n;
double tempx,tempy;
for(int i=0;i<=n;i++)
{
tempx = x_offset+static_cast<double>(i)*x_step;
tempy = y_offset+static_cast<double>(i)*y_step;
Distor_Array[i] = CalcDistortion(tempx,tempy);
}
for(int j=0;j<=n;j++)
{
cout<<j<<"\t";
Distor_Array[j].showcoord();
}
delete [] Distor_Array;//内存泄露,问题出在哪?
//system("pause");
return 0;
}
pointcoord CalcDistortion(const double &a,const double &b)
{
double DeltaX = 0, DeltaY = 0;
pointcoord temppoint;
temppoint.readcoord(DeltaX,DeltaY);
return temppoint;
}