//7.7.cpp--array function and const #include <iostream> const int MAX=5; double* fill_array(double* begin,double* end); void show_array(const double ar[],const double* n); void reValue_array(double r,double ar[],const double* n); int main() { using namespace std; double properties[MAX]; const double* size=fill_array(properties,properties+MAX); show_array(properties,size); cout<<\"Please enter the double value you want to change.\\n\"; double value; cin>>value; reValue_array(value,properties,size); show_array(properties,size); return 0; } double* fill_array(double* begin,double* end) { using namespace std; double* pt; //double* temp; double a; //temp=&a; for(pt=begin;pt!=end;pt++) { cout<<\"Please enter the value #: \\n\"; cin>>a; if(!cin) { cin.clear(); while(cin.get()!=’\\n’) continue; cout<<\"Bad input,input process terminated.\\n\"; break; } else if(a<0) break; *pt=a; } return pt; } void show_array(const double ar[],const double* n) { using namespace std; const double* pt; for(pt=ar;pt!=n;pt++) { cout<<\"The value of properties #: \\n\"; cout<<*pt<<endl; } cout<<endl; } void reValue_array(double r,double ar[],const double* n) { using namespace std; double* pt; for(pt=ar;pt!=n;pt++) { *pt=r; } } |