Rewrite requirement 1: Replace array with pointer PA, PB, respectively
Rewrite requirement 2: Enter data element from keyboard any number of elements, enter 0 end
#include <cstdlib>#include<iostream>using namespacestd;classdata{Double*pa,*PB; Doublemax,min; Doublenew_max,new_min; intlength; Public: DATA (DoubleA1[],DoubleXDoubleYintLen) { inti; 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]; } } voidFun (); voidprint () { while(*pa!=' /') cout<<*pa++<<'\ t'; cout<<Endl; cout<<"["<<new_min<<","<<new_max<<"]"<<Endl; while(*pb!=' /') cout<<*pb++<<Endl; }};voidData::fun () { for(intI=0; i<length;i++) Pb[i]= (pa[i]-min) * (new_max-new_min)/(max-min) +new_min;}intMainintargcChar*argv[]) { inti,j=0; cout<<"number of input elements"<<Endl; CIN>>i; Double*data=New Double[i+1]; intx, y; CIN>>data[0]; while(Data[j]) {J++; CIN>>Data[j]; } while(*data!=' /') cout<<*data++<<'\ t'; cout<<Endl; cout<<"enter X, y"<<Endl; CIN>>x>>y; DATA test (data,x,y,i); Test.fun (); Test.print (); System ("PAUSE"); returnexit_success;}
C + + Programming Practice Guide 1.12 Data linear transformations in arrays rewriting requirements implementation