救命a!C++高手进,程序补全能运行就好了,重谢呀!!在线等!!!!!!!!!!!!

2025-01-04 14:26:39
推荐回答(2个)
回答1:

using namespace std;

class Goods{
private:
int m_No; //商品编码
string m_Name; //名称
string m_Class; //种类
float m_price; //单价

public:
Goods(int No,string Name, string Class, float price)
{
m_No = No;
m_Name = Name;
m_Class = Class;
m_price = price;
}
bool operater == (const Goods s)
{
return s.m_No == m_No;
}
};

class Item
{
public:
Goods m_Goods; //商品
int m_Goods_Num; //商品数量
};

class Cart
{
private:
map mm;
public:
Add(Goods g, int n=1)
{
mm.insert(make_pair(g,n));
}
Remove(Goods g, int n=1)
{
map::iterator i = mm.find(g);
if(i != mm.end())
{
(*i).second -= n;
if((*i).second <=0 )
mm.erase(i);
}
}
float Price(void)
{
float r = 0;
for(map::iterator i=mm.begin();
i!= mm.end(); ++i)
r += (*i).m_price;
return r;
}

void Details(void)
{
for(map::iterator i=mm.begin();
i!= mm.end(); ++i)
{
cout << "编码" << i->m_No < cout << "名称" << i->m_Name < cout << "种类" << i->m_Class < cout << "单价" << i->m_price < }
}
};

但不知道你的item做什么用?

回答2:

正在做。
#include
#include
using namespace std;
class Goods
{
private:
int code;
string name;
string type;
float price;
public:
Goods();
Goods(int code,string name,string type,float price);
void Show(int attr=0);
void Set(int attr=0);
};

Goods::Goods(int code,string name,string type,float price){
this->code = code;
this->name = name;
this->type = type;
this->price = price;
};

void Goods::Show(int attr=0){
switch(attr){
case 0:cout< case 1:cout< case 2:cout< case 3:cout< case 4:cout< default:cout<<"无效输入"< }
};

void Goods::Set(int attr=0){
switch(attr){
case 1:;break;
case 2:;break;
case 3:;break;
case 4:;break;
default:cout<<"无效输入"< }
};

class Item
{
private:
Goods good;
int num;
public:
Item();
Item(Goods good,int num);
};

class Cart
{
private:

public:
void Add(Goods good,int num=0);
void Remove(Goods good,int num=0);
float Price();
void Details();
};

void Cart::Add(Goods good,int num=0){

};

void Cart::Remove(Goods good,int num=0){

};

float Cart::Price(){

};
void Cart::Details(){

};