注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 校园网重规划
 帮助

用指针控制数组范围


2007-12-14 22:54:35
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://298452.blog.51cto.com/288452/55198

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

本文出自 “lion_pc” 博客,请务必保留此出处http://298452.blog.51cto.com/288452/55198



上一篇 指针与const  下一篇 函数指针



    文章评论
 
2007-12-16 13:56:28
我也来学习

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: