C ++ Programming Practice Guidance 1.12 data line conversion and rewriting requirements in the array, Programming Practice 1.12

Source: Internet
Author: User

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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.