C++primer plus第六版课后编程题答案7.6
7.6
#include <iostream>
using namespace std;
void Fill_array(double arr[],int arrSize) ;//因为是对数组进行操作,所以可以不用返回值;
void const Show_array(const double arr[],int arrSize);
void Reverse_array(double arr[],int arrSize);
void main76()
{
double arr[10];
Fill_array(arr,10);
Show_array(arr,10);
Reverse_array(arr,10);
system("pause");
}
void Fill_array(double arr[],int arrSize) //因为是对数组进行操作,所以可以不用返回值;
{
int i=0;//用于记录输入了多少个数字
for(i=0;i<arrSize;i++)
{
cout<<"\nPlease enter the "<<i+1<<" double values:";
if(!(cin>>arr[i]))//如果输入非法值,跳出循环
break;
}
cout<<"\n you had input "<<i<<" values!"<<endl;
}
void const Show_array(const double arr[],int arrSize)
{
cout<<"the array is:"<<endl;
for(int i=0;i<arrSize&&arr[i]!='\0';i++)
cout<<arr[i]<<" ";
cout<<"\nshow end!"<<endl;
}
void Reverse_array(double arr[],int arrSize)
{
int temp;
cout<<"\nnow Reverse the array!"<<endl;
for(int i=1;i<arrSize/2;i++)
{
temp=arr[i];
arr[i]=arr[arrSize-1-i];
arr[arrSize-1-i]=temp;
}
cout<<"this is the new array:"<<endl;
Show_array(arr,arrSize);
}

浙公网安备 33010602011771号