您的位置:首页 > 其它

用指针控制数组范围

2007-12-14 22:54 357 查看
#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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐