資源簡介
某商場有如下的幾種貨品:襯衣、鞋子、帽子、褲子、冰箱、電視、立柜、壁櫥、沙發。每一種貨物都有詳細的說明信息。

代碼片段和文件信息
#include
#include
using?namespace?std;
class?Goods????????????????????//聲明基類
{
public:????????????????????????//基類公用成員
Goods(){}
Goods(double?pstring?padouble?sint?cn);//構造函數
void?set();????????????????//為類更改現有類函數,與構造函數累世,不過不創建新類
void?setPrice(double?&);???//設計價格
void?setStorage(double?&);?//設定庫存
void?getGoods(double?&);???//取出貨物,庫存更新
void?setContainer(int?&);??//設定所屬貨柜
double?sumPrice();?????????//獲得總價格(單價*庫存量)
void?showPrice();??????????//顯示單價
void?showStorge();?????????//顯示庫存量???
void?showAddr();???????????//顯示產地
void?showContainer();??????//顯示所屬貨柜
void?display();????????????//顯示所有屬性信息
protected:
static?string?name;????????//貨物名稱,聲明為靜態變量,直接在類體外初始化
double?price;??????????????//單價
string?productAddr;????????//產地
double?storge;?????????????//庫存量
int?containerNum;??????????//所屬貨柜
};
string?Goods::name=“Goods“;
Goods::Goods(double?pstring?padouble?sint?cn):price(p)productAddr(pa)storge(s)containerNum(cn){}
void?set(){}
void?Goods::setPrice(double?&p){}
void?Goods::setStorage(double?&s){}
void?Goods::getGoods(double?&){};
void?Goods::setContainer(int?&cn){};
double?sumPrice(){?return?1;}
void?Goods::showAddr(){}
void?Goods::showStorge(){}
void?Goods::showPrice(){}
void?Goods::display(){}
class?Shirt:public?Goods
{
public:
Shirt(){cloth=“*“size=“*“price=0productAddr=“*“storge=0containerNum=-1;}??
???????????????????????????????????????????????????????????????//默認初始化
void?set(string?clstring?sidouble?pstring?padouble?stint?cn);
???????????????????????????????????????????????????????????//對所有成員的修改
void?setPrice(double?&);???????????????????????????????????//設定價格
void?setStorage(double?&);?????????????????????????????????//設定庫存量
void?getGoods(double?&);???????????????????????????????????//取貨物,修改庫存
void?setContainer(int?&);??????????????????????????????????//設定所屬貨柜
double?sumPrice();?????????????????????????????????????????//求總價值
void?showAddr();???????????????????????????????????????????//設定產地
void?showStorge();?????????????????????????????????????????//顯示庫存量
void?showPrice();??????????????????????????????????????????//顯示價格
void?showContainer();??????????????????????????????????????//顯示所屬貨柜
void?display();????????????????????????????????????????????//貨物所有信息顯示
protected:
string?cloth;??????????????????????????????????????????????//子類Shirt增加的成員
string?size;
static?string?name;????????????????????????????????????????//靜態成員,標示類名
};
string?Shirt::name=“Shirt“;
void?Shirt::set(string?clstring?sidouble?pstring?padouble?stint?cn)
{
cloth=cl;
size=si;
price=p;
productAddr=pa;
storge=st;
containerNum=cn;
}
void?Shirt::setPrice(double?&s)
{
??price=s;
}
void?Shirt::setStorage(double?&s)
{
??storge+=s;
}
void?Shirt::getGoods(double?&g)
{
??double?s;
??if(g<=storge)?storge-=g;
??else?{cout<<“請重新輸入:“;cin>>s;getGoods(s);}
}
void?Shirt::setContainer(int?&cn)
{
??containerNum=cn;
}
double?Shirt::sum
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????42345??2013-06-05?16:49??shop.cpp
?????文件??????285974??2013-06-26?09:36??報告.doc
- 上一篇:打印出有向圖中的所有環C++
- 下一篇:c語言課程設計圖書信息管理系統
評論
共有 條評論