C++ 急问:

来源:百度知道 编辑:UC知道 时间:2024/05/15 23:22:34
#include <iostream.h>

class CPetrol
{
private:
int type;
float price;
float count;
public:
void setpetrol(int Ptype,float Pprice,float Pcount)
{
//cin>>"please input the petrol type,price and count:">>Ptype>>pprice>>Pcount>>endl;
if(Ptype==90||Ptype==93||Ptype==98)
{
type=Ptype;
price=Pprice;
count=Pcount;
}
else cout<<"The petrol type is error,please input again:"<<endl;

}
float process()
{
cout<<"the "<<type <<"type count is:"<<price*count<<endl;
return price*count;
}
};

void sum(CPetrol a,CPetrol b, CPetrol c)
{
float sum;
sum=a.process+b.process+c.process;
cout<<"the sum is:"<<sum<<endl;
};

void main()
{
CPetrol

在类的sum()函数里面你调用process函数后面因该有“()”吧;
正确应该如下:
void sum(CPetrol a,CPetrol b, CPetrol c)
{
float sum;
sum=a.process()+b.process()+c.process();
cout<<"the sum is:"<<sum<<endl;
};

sum=a.process+b.process+c.process;
改为sum=a.process()+b.process()+c.process();
就可以了