请教一个简单的c++问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 05:13:44
#include <iostream>
#include "conio.h"
using namespace std;
class Car;

class BOAT
{
public:
float set_weight(float)
{
return weight;
}

friend float fdisk(BOAT &a,Car &b);
private:
float weight;
};

class Car
{
public:
float set_weight1(float)
{
return weight1;
}

friend float fdisk(BOAT &a,Car &b);
private:
float weight1;
};

float fdisk(BOAT &a,Car &b)
{
double x;
x=double(a.weight+b.weight1);
return x;
}

int main()
{float k;
BOAT A;Car B;

A.set_weight(3);
B.set_weight1(4);

k=fdisk(A,B);
cout<<"the add of weights is:"<<k<<endl;
getch();
}
哪个地方有错?谢谢

你的设置没有起到作用。。要增加负重语句。。不然是随机数呀。。我改了OK了!
#include <iostream>
#include "conio.h"
using namespace std;
class Car;

class BOAT
{
public:
float set_weight(float a)
{
return weight=a;
}

friend float fdisk(BOAT &a,Car &b);
private:
float weight;
};

class Car
{
public:
float set_weight1(float a)
{
return weight1=a;
}

friend float fdisk(BOAT &a,Car &b);
private:
float weight1;
};

float fdisk(BOAT &a,Car &b)
{
double x;
x=double(a.weight+b.weight1);
return x;
}

int main()
{float k;
BOAT A;Car B;

A.set_weight(3);
B.set_weight1(4);

k=fdisk(A,B);
cout<<"the add of weights is:"<<k<<endl;
getch();
}