C ++ Programming Practice Guidance 1.12 data line conversion and rewriting requirements in the array, Programming Practice 1.12
Rewrite requirement 1: replace array with pointer pa and pb respectively
Rewrite requirement 2: input any number of data element elements from the keyboard, input 0 ends
# 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] ;}} v Oid 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 <"Number of input elements" <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 <"input x, y" <endl; cin> x> y; DATA test (data, x, y, I); test. fun (); test. print (); system ("PAUSE"); return EXIT_SUCCESS ;}