标签:
改写要求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=0;i<length;i++) pa[i]=a1[i]; new_max=x; new_min=y; max=min=pa[0]; for(i=0;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=0;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=0; cout<<"输入元素个数"<<endl; cin>>i; double *data=new double[i+1]; int x,y; cin>>data[0]; 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; }
C++程序设计实践指导1.12数组中数据线性变换改写要求实现
标签:
原文地址:http://www.cnblogs.com/c5395348/p/4282109.html