1,P18
#include <iostream.h>
void swap(int& num1,int& num2)
{
int tmp=num1;
num1=num2;
num2=tmp;
}
void main()
{
int x=10,y=15;
swap(x,y);
cout<<"x:"<<x;
cout<<"y:"<<y;
}
2,P21
#include <iostream.h>
inline double volume(double s) //内联函数
{
return(s*s*s);
}
void main()
{
float side=3.5;
cout<<"/n边长为"<<side<<"的立方体的体积是:";
cout<<volume(side);
}
3,P23
#include <iostream.h>
int are(int);
double area(double,int);
double area(int ,int);
int area(int s) //计算正方形的面积
{
return(s*s);
}
double area(double l,int b) //计算长方形的面积
{
return(1*b);
}
double area(int b,int h) //计算三角形的面积
{
return(0.5*b*h);
}
void main()
{
int side=12;
double length=10.5;
int breadth=20;
int base=10,height=15;
cout<<"边长为"<<side<<"的正方形的面积是:";
cout<<area(12);
cout<<"/n长为"<<length<<"且宽为"<<breadth<<"的长方形的面积是:";
cout<<area(10.5,20);
cout<<"/n底边长为"<<base<<"且高为"<<height<<"的三角形的面积是:";
cout<<area(10,15);
}