简单的带默认参数值得函数

#include<iostream>
#include<iomanip> 
using namespace std;

int getVolume( int length, int width = 2, int height = 3);

int main()
{
const int x = 10 ,y = 12, z = 15;
cout<<"盒子的数据:";
cout<<getVolume(x,y,z)<<endl;
cout<<"盒子的数据:";
cout<<getVolume(x,y)<<endl;
cout<<"盒子的数据:";
cout<<getVolume(x)<<endl;
return 0;
}
int getVolume(int length, int width, int height)
{
cout << setw(5) <<length <<setw(5) << width<< setw(5) <<height<<'\t';//setw是操作符 原型是setw(int)
return length * width * height;
}

猜你喜欢

转载自blog.csdn.net/qq_41814721/article/details/82491108
今日推荐