用指针控制数组范围
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;
}
}
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;
}
}
相关文章推荐
- 一个包含指针数组的排序和使用函数指针来控制排序方式
- 定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同打印G
- *指针_函数指针、指针控制数组、链表(结构体指针)
- PHP学习笔记——使用数组的内部指针控制函数遍历数组
- 数组内部指针控制
- 3 定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同
- int数组 smart pointer 的实现,带范围检查的指针
- 3.定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同打
- 数组的指针控制以及超全局数组的定义和意义
- 定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同打印G
- 指针的控制范围
- 定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同打印G
- 定义两个整型指针,分别用malloc、calloc对其分配空间保存3个元素,malloc分配的空间用memset清零,随机对数组进行赋值随机范围1-3,赋值后用memcmp比较两个数组。如果相同打印G
- 利用指针控制数组大小过程
- 数组指针——指向数组的指针(通过指针控制数组)
- 指针和数组
- 用指针 数组连接
- [c基础] 二维指针数组
- 数组指针 与 指针数组
- 程序员之---C语言细节12(指针和数组细节,"//"的可移植性说明)