下面这个源程序编译运行后,最后的totalweight 是0;不知道哪里错了,怎么改,请各位帮忙看看
#include <iostream>
using namespace std;
class Car;
class Boat
{
public:
Boat(Boat &b) {weight1=b.weight1;}
Boat(float m=0) {weight1=m;}
void Set();
void Print();
friend float totalweight(Boat &b,Car &c);
private:
float weight1;
};
void Boat::Set()
{
cin>>weight1;
}
void Boat::Print()
{
cout<<"the weight of boat is "<<weight1<<endl;
}
class Car
{
public:
Car(Car &c) {weight2=c.weight2;}
Car(float n=0) {weight2=n;}
void Set();
void Print();
friend float totalweight(Boat &b,Car &c);
private:
float weight2;
};
void Car::Set()
{
cin>>weight2;
}
void Car::Print()
{
cout<<"the weight of car is "<<weight2<<endl;
}
float totalweight(Boat &b,Car &c)
{
float w;
w=b.weight1+c.weight2;
return (w);
}
void main()
{ float weight1,weight2;
Boat boat(weight1);
Car car(weight2);
cout<<"input boat's weight:"<<endl;
boat.Set();
cout<<"input car's weight:"<<endl;
car.Set();
boat.Print();
car.Print();
Boat b;
Car c;
cout<<"total weight is "<<totalweight(b,c)<<endl;
}