改写要求1:分别用指针pa、pb代替数组

改写要求2:从键盘输入data元素 元素个数任意,输入0结束

#include <cstdlib>
#include <iostream> using namespace std;
class DATA
{
double *pa,*pb;
double max,min;
double new_max,new_min;
int length;
public:
DATA(double a1[],double x,double y,int len)
{
int i;
length=len;
pa=new double[len];
pb=new double[len];
for(i=;i<length;i++)
pa[i]=a1[i];
new_max=x;
new_min=y;
max=min=pa[];
for(i=;i<length;i++)
{
if(pa[i]>max)
max=pa[i];
if(pa[i]<min)
min=pa[i];
}
}
void fun();
void print()
{
while(*pa!='\0')
cout<<*pa++<<'\t';
cout<<endl;
cout<<"["<<new_min<<","<<new_max<<"]"<<endl;
while(*pb!='\0')
cout<<*pb++<<endl;
}
};
void DATA::fun()
{
for(int i=;i<length;i++)
pb[i]=(pa[i]-min)*(new_max-new_min)/(max-min)+new_min;
}
int main(int argc, char *argv[])
{
int i,j=;
cout<<"输入元素个数"<<endl;
cin>>i;
double *data=new double[i+];
int x,y;
cin>>data[];
while(data[j])
{
j++;
cin>>data[j];
}
while(*data!='\0')
cout<<*data++<<'\t';
cout<<endl;
cout<<"输入x,y"<<endl;
cin>>x>>y;
DATA test(data,x,y,i);
test.fun();
test.print();
system("PAUSE");
return EXIT_SUCCESS;
}
04-15 02:25