7.7

原创 2018年04月16日 21:04:59
#include<iostream>

using std::cin;
using std::cout;
using std::endl;

double* fill_array(double* ar,int n)
{
	double temp;
	int i;
	for( i=0;i<n;i++)
	{
		cout<<"enter value#"<<(i)<<": ";
		cin>>temp;
		if(!cin)
		{
			cin.clear();
			while(cin.get()!='\n')
				continue;
			cout<<"bad input,input process terminated.\n";
			break;
		}
		else if(temp<0)
			break;
		*ar=temp;
		ar++;
	}
	return --ar;
}
void show_array (const double *ar,const double *br)
{
	const double *p=ar;
	for(int i=0 ;p<=br;p++,i++)
	{
		cout<<"property"<<(i+1)<<" ";
		cout<<*p<<endl;
	}
}
void revalue(double r,double *ar,double *br)
{
	 double *p=ar;
	for(int i=0 ;p<=br;p++,i++)
	{
		*p=*p*r;
	}
}

int main()
{
	double properties[5];
	double*end=fill_array(properties,5);
	show_array(properties,end);
	if(end>=properties)
	{
		cout<<"enter revalution factor";
		double factor;
		while(!(cin>>factor))
		{
			cin.clear();
			while(cin.get()!='\n')
				continue;
			cout<<"bad input,please enter a number";
		}
		revalue(factor,properties,end);
		show_array(properties,end);
	}
	cout<<"done"<<endl;
	cin.get();
	system("pause");
	return 0;
}

收藏助手
不良信息举报
您举报文章:7.7
举报原因:
原因补充:

(最多只允许输入30个字)