主题:有谁能帮我把他编译过了啊??
本人刚刚开始学C++,在按着辅导书上的代码输入Visual C++ 中编译的时候总是过不了,搞了一天还是不行,有哪位高手能给解决一下,谢谢了!!!
代码如下:
#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 GetAmont(void); //读取商品数量
float GetPrice(void); //读取商品单价
float GetTotal_value(void); //读取商品总价值
}; //最后的分号不可少
void main()
{
CGoods car;
char string[21];
int number;
float pr;
cout<<"请输入汽车的型号: ";
cin.getline(string, 20); // 输入的串长必须小于20 (char型的一种取法)
cout<<"请依次输入汽车数量和单价: ";
cin>>number>>pr;
car.RegisterGoods(string, number, pr);
car.CountTotal();
string[0] = '\0';
car.GetName(string);
cout<<setw(20)<<string<<setw(5)<<car.GetAmont();
cout<<setw(10)<<car.GetPrice()<<setw(20)<<car.GetTotal_value()<<endl;
}
void CGoods::RegisterGoods(char[] name, int amount, float price) //出错的位置
{
strcpy(Name, name); //字符串copy
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);
}
代码如下:
#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 GetAmont(void); //读取商品数量
float GetPrice(void); //读取商品单价
float GetTotal_value(void); //读取商品总价值
}; //最后的分号不可少
void main()
{
CGoods car;
char string[21];
int number;
float pr;
cout<<"请输入汽车的型号: ";
cin.getline(string, 20); // 输入的串长必须小于20 (char型的一种取法)
cout<<"请依次输入汽车数量和单价: ";
cin>>number>>pr;
car.RegisterGoods(string, number, pr);
car.CountTotal();
string[0] = '\0';
car.GetName(string);
cout<<setw(20)<<string<<setw(5)<<car.GetAmont();
cout<<setw(10)<<car.GetPrice()<<setw(20)<<car.GetTotal_value()<<endl;
}
void CGoods::RegisterGoods(char[] name, int amount, float price) //出错的位置
{
strcpy(Name, name); //字符串copy
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);
}