|
说明:
头文件都有<>,但是我加上以后贴子显示不出来,因此我没打,源程序中有<>
程序的代码为:
# include iostream.h
# include iomanip.h
# include string.h
class CGoods{
private:
char Name[21];
int Amount;
float Price;
float Total_value;
public:
void RegisterGoods(char[],int,float);
void CountTotal(void);
void GetName(char[]);
int GetAmount(void);
float GetPrice(void);
float GetTotal_value(void);
};
void CGoods::RegisterGoods(char[] name,int amount,float price){
strcpy(Name,name);
Amount=amount;Price=price;
}
void CGoods::CountTotal(void){
Total_value=Price*Amount;
}
void CGoods::GetName(char[] name){
strcpy(name,Name);
}
int CGoods::GetAmount(void){
return(Amount);
}
float CGoods::GetPrice(void){
return(Price);
}
float CGoods::GetTotal_value(void){
return(Total_value);
}
void main(){
CGoods car;
char string[21];
int number;
float pr;
cout<<"请输入汽车型号:";
cin.getline(string,20);
cout<<"请依次输入汽车数量与单价:";
cin>>number>>pr;
car.RegisterGoods(string,number,pr);
car.CountTotal();
string[0]='\0';
car.GetName(string);
cout<<setw(20)<<string<<setw(5)<<car.GetAmount();
cout<<setw(10)<<car.GetPrice()<<setw(20)<<car.GetTotal_value<<endl;
}
运行以后提示的错误为:
g:\vc++\cpp1.cpp(19) : error C2146: syntax error : missing ')' before identifier 'name'
g:\vc++\cpp1.cpp(19) : error C2146: syntax error : missing ';' before identifier 'name'
g:\vc++\cpp1.cpp(19) : error C2244: 'CGoods::RegisterGoods' : unable to resolve function overload
g:\vc++\cpp1.cpp(19) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Cpp1.obj - 4 error(s), 0 warning(s)
第19行就是我用红色标出的那一行,我觉得没有什么错啊,该如何修该,请大家指教一下,十分感谢! |
|