输入:
一行,输2个整数m和n(1 ≤ m, n ≤ 10000),分别表示船和小汽车的重量。
输出:
输出船和汽车共重多少吨,详见样例。
输入:
50 20
输出:
船和汽车共重70吨
代码:
#include<iostream>
using namespace std;
class Boat
{
protected:
int weight;
public:
Boat(int n) : weight(n) {}
int boat1()
{
return weight;
}
};
class Car
{
protected:
int weight;
public:
Car(int m) : weight(m) {}
friend int getTotalWeight(Boat &boat,Car &car);
};
int getTotalWeight(Boat &boat,Car &car)
{
return boat.boat1()+car.weight;
}
int main()
{
int n,m;
cin>>n>>m;
Boat boat(n);
Car car(m);
cout<<"船和汽车共重"<<getTotalWeight(boat,car)<<"吨"<<endl;
}