定义一boat与car两个类,二者都有weight属性,定义二者的一个友元函数totalweight(),计算二者的重量和。
测试程序样例:
输入样例:
1000 2000
输出样例:
3000
--------------------------------------------------分割线-----------------------------------------------------
class boat
{
private:
int weight;
public:
boat(int w)
{
weight = w;
}
int getW()
{
return weight;
}
};
class car
{
private:
int weight;
public:
car(int w)
{
weight = w;
}
int getW()
{
return weight;
}
};
int totalweight(boat b1,car c1)
{
return b1.getW() + c1.getW();
}