1、101006434商品销售管理系统数据结构课 程 设 计 报 告 书题 目: 商品销售管理 系 别: 计算机科学与应用系 学 号: 101006434 学生姓名: 指导教师: 傅尔胜 完成日期: 2012年6月7日 一、需求分析 商品销售管理 商品信息的组成部分为:商品编号、商品名称、商品单价、生产商、库存量等。销售单信息的组成部分为:商品编号、商品名称、商品单价、购买数量、该商品应付金额等。2、概要设计1、数据类(class Data)的数据类型定义:class Data /数据类private: int id; /产品编号 char name100; /产品名称 int count; /库
2、存数量 int salecount; /已售数量 float iprice; /进价 float oprice ; /售价 char gys20; /供应商Public: /公有函数 int getid() /获取id char *getname() /获取产品名 Int getcount() /获取库存量 Int getsalecount() /获取已售量 Float getbuy() /获取进价 Float getsale() /获取售价 Char *getgys() /获取供应商 Void setid(int n) /输入id Void setname(char na) /产品名 Voi
3、d setcount(int c) /库存量 Void setsalecount(int s) /已售量 Void setbuy(float i) /进价 Void setsale(float o) /售价 Void setgys(char g) /供应商;2、class commodity 商品类设计:class Commodity /商品类private: Data t50; /数组 int n; /商品数量public: void newFile() /添加商品信息 void showData(int i) /显示商品信息 void showData() /显示文字信息 void sav
4、e() /写入数据至文件 int search() /商品查询 void sale() /商品销售结算 void showSale() /销售清单 inline void menu() /主菜单 3、本程序结构 (1)主函数 Void main() menu(); Commodity com; int c; switch(c)return Break;(2)数据类实现对数据的输入输出。(3)商品类系统各项功能的实现。三、详细设计 (1)数据类 class Data /数据类private: int id;/产品编号 char name100;/产品名称 int count;/库存数量 int
5、salecount;/已售数量 float iprice;/进价 float oprice;/售价 char gys20;/供应商public: int getId() return id; char *getName() return name; int getCount() return count; int getSaleCount() return salecount; float getBuy() return iprice; float getSale() return oprice; char *getGys() return gys; /- void setId(int n)
6、id=n; void setName(char na) strcpy(name,na); void setCount(int c) count=c; void setSaleCount(int s) salecount=s; void setBuy(float i) iprice=i; void setSale(float o) oprice=o; /. void setGys(char g) strcpy(gys,g); ;(2)商品类 class Commodity /商品类 private: Data t50; /数组 int n; /商品数量 public: void newFile(
7、) int id; char name50; /字符数组 int count; float iprice; float oprice; char gys20; if(n0) n=0; int i; Data temp; for(;n+) coutid; if(id=-1) break; tn.setId(id); coutname; tn.setName(name); coutcount; tn.setCount(count); coutiprice; tn.setBuy(iprice); coutoprice; tn.setSale(oprice); coutgys; tn.setGys(g
8、ys); tn.setSaleCount(0);/售出此产品0个 cout若商品添加完毕,请按-1退出添加!endl; for(i=0;itn.getId() temp=ti; ti=tn; tn=temp; void showData(int i) coutti.getId() setw(10)ti.getName() setw(10)ti.getCount() setw(10)ti.getSaleCount() 6 setw(8)ti.getBuy() setw(8)ti.getSale() setw(8)ti.getGys()endl; void showData() cout商品编号
9、setw(8)商品名 setw(8)库存量 setw(10)已售量 setw(10)进价 setw(8)售价 setw(8)供应商endl; for(int i=0;i0 ) showData(i); cout产品种类:nendl; void save() /写入数据至文件 ofstream fout; fout.open(商品销售管理系统.txt); if(!fout) coutcannot open the file!endl; return ; fout商品编号 商品名 库存量 进价 售价 供应商 已售量endl; for(int i=0;in;i+) foutti.getId()set
10、w(14)ti.getName()setw(10)ti.getCount()setw(10)ti.getBuy()setw(10)ti.getSale()setw(10)ti.getGys()setw(10)ti.getSaleCount(); cout*Save Success!*endl; fout.close(); int search() int id; coutid; int low=0,mid,high=n-1; while(lowid) high=mid-1; Else low=mid+1; return -1; void sale() cout产品编号; int temp; t
11、emp=search(); if(temp=-1) coutcannot find the commodity!endl; return; if(ttemp.getCount()=0) cout此产品已缺!endl; int count; coutcount; float money; coutmoney; if(countttemp.getCount()/输入的是负数或超出该产品库存量 cout数量输入不正确endl; else if(moneyttemp.getSale()*count) 8 cout购物金额不足,还需增加金额ttemp.getSale()*count-money元endl
12、; else ttemp.setCount(ttemp.getCount()-count);/当前库存减少count ttemp.setSaleCount(ttemp.getSaleCount()+count);/出售量增加count cout*名称:ttemp.getName()endl *数量:countendl *单价:ttemp.getSale()元endl *应收:count*ttemp.getSale()元endl *找零:money-count*ttemp.getSale()元endl *endl; void showSale() for(int i=0;i0 ) showDat
13、a(i); ;(3)主函数inline void menu() cout *欢迎使用商品销售管理系统* endl; cout *主菜单* endl; cout (1)添加 endl; cout (2)保存 endl; cout (3)显示 endl; cout (4)菜单 endl; cout (5)销售单 endl; cout (0)退出系统 endl; cout *2011-2012* endl; void main() menu(); Commodity com; int c; for(;) coutc; switch(c) case 1:com.newFile();break; cas
14、e 2:com.save();break; case 3:com.showData();break; case 4:menu();break; case 5:com.sale();break; case 0: cout *谢谢使用* endl; cout *!再见!* endl; return; break; 四、调试分析(1)、error C2143: syntax error : missing ; before 行246少了一个分号(2)、error C2562: main : void function returning a value空类型不能有返回值(3)、error C2679
15、: binary : no operator defined which takes a right-hand operand of type (or there is no acceptable conversion) ti.getName后面少了()5、用户使用说明1、本程序的运行环境为windows操作系统,执行文件为Ks.exe;2、进入演示程序后,即显示对话形式的提示操作过程:如:第一项:(1)商品添加功能在选择一栏输入:1即显示商品编号、商品名、库存量、进价、售价、供应商各项商 品信息,依次输入所需添加的数据 。添加商品完毕,按-1退出添加。选择:2 即将商品信息保存。选择:3 显
16、示已保存的商品信息。选择:4 重新回到主菜单。选择:5 进行商品销售结算。同时选择:3 显示商品库存和已销售的完整信息。六、测试结果 进入演示程序后,即显示对话形式的提示操作过程:选择:1 输入相应提示的商品信息选择:2 界面显示数据保存成功选择:3 显示商品信息 选择:4 重新回到主菜单选择:5 进行商品结算选择:3 显示商品信息7、附录程序源代码:#include#include#include#include /为了声明标识符setw()函数#define Mfname 100class Data /数据类private: int id;/产品编号 char name100;/产品名称
17、int count;/库存数量 int salecount;/已售数量 float iprice;/进价 float oprice;/售价 char gys20;/供应商public: int getId() return id; char *getName() return name; int getCount() return count; int getSaleCount() return salecount; float getBuy() return iprice; float getSale() return oprice; char *getGys() return gys; /
18、- void setId(int n) id=n; void setName(char na) strcpy(name,na); void setCount(int c) count=c; void setSaleCount(int s) salecount=s; void setBuy(float i) iprice=i; void setSale(float o) oprice=o; /. void setGys(char g) strcpy(gys,g); ;class Commodity /商品类private: Data t50; /数组 int n; /商品数量public: vo
19、id newFile() int id; char name50; /字符数组 int count; float iprice; float oprice; char gys20; if(n0) n=0; int i; Data temp; for(;n+) coutid; if(id=-1) break; tn.setId(id); coutname; tn.setName(name); coutcount; tn.setCount(count); coutiprice; tn.setBuy(iprice); coutoprice; tn.setSale(oprice); coutgys;
20、tn.setGys(gys); tn.setSaleCount(0);/售出此产品0个 cout若商品添加完毕,请按-1退出添加!endl; for(i=0;itn.getId() temp=ti; ti=tn; tn=temp; void showData(int i) coutti.getId() setw(10)ti.getName() setw(10)ti.getCount() setw(10)ti.getSaleCount() setw(8)ti.getBuy() setw(8)ti.getSale() setw(8)ti.getGys()endl; void showData()
21、cout商品编号 setw(8)商品名 setw(8)库存量 setw(10)已售量 setw(10)进价 setw(8)售价 setw(8)供应商endl; for(int i=0;i0 ) showData(i); cout产品种类:nendl; void save() /写入数据至文件 ofstream fout; fout.open(商品销售管理系统.txt); if(!fout) coutcannot open the file!endl; return ; fout商品编号 商品名 库存量 进价 售价 供应商 已售量endl; for(int i=0;in;i+) foutti.getId()setw(14)ti.getName()setw(10)ti.getCount()setw(10)ti.getBuy()setw(10)ti.getSale()setw(10)ti.getGys()setw(10)ti.getSaleCount(); cout*Save Success!*endl; fout.close(); int search() int id; coutid; int low=0,mid,high=n-1; while(lowid) high=mid-1; els