资源描述
C++课设 商品销售管理系统
目录
一、 需求分析......................................2
二、 概要设计......................................2
三、 详细设计......................................3
四、 调试分析......................................9
五、 用户手册.....................................10
六、 测试数据.....................................11
七、 附录.........................................12
—1—
一、需求分析
商品销售管理程序
商品信息:商品编号、商品名称、商品类别(普通电视机、DVD、带DVD的电视机,带DVD的电视机的售价为普通电视机和DVD单价之和的80%)、商品进货价格、商品销售价格、商品数量、供应商名称等。
记录每一次销售商品的数量和价格,并提供对已售出商品的价格、数量进行统计、排序功能,但允许用户退商品。
(要求:1.源文件采用多文件的工程结构2.数据存储采用文件形式3.标准的C输入输出4.功能完善,适当的注释,5.关于文件的内容需要自学)
二、 概要设计
1、数据类(class Data)的数据类型定义:
class Data //数据类
{
private:
int id; //产品编号
char name[100]; //产品名称
int count; //库存数量
int salecount; //已售数量
float iprice; //进价
float oprice ; //售价
char gys[20]; //供应商
Public: //公有函数
int getid() //获取id
char *getname() //获取产品名
Int getcount() //获取库存量
Int getsalecount() //获取已售量
Float getbuy() //获取进价
Float getsale() //获取售价
Char *getgys() //获取供应商
—2—
Void setid(int n) //输入id
Void setname(char na[]) //产品名
Void 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 t[50]; //数组
—2—
int n; //商品数量
public:
void newFile() //添加商品信息
void showData(int i) //显示商品信息
void showData() //显示文字信息
void save() //写入数据至文件
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 name[100];//产品名称
int count;//库存数量
int salecount;//已售数量
float iprice;//进价
float oprice;//售价
char gys[20];//供应商
public:
int getId()
{
return id;
}
char *getName()
{
return name;
}
int getCount()
{
—3—
return count;
}
int getSaleCount()
{
return salecount;
}
float getBuy()
{
return iprice;
}
float getSale()
{
return oprice;
}
char *getGys()
{
return gys;
}
//----------------------
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;
}
—4—
//...................
void setGys(char g[])
{
strcpy(gys,g);
}
};
(2) 商品类
class Commodity //商品类
{
private:
Data t[50]; //数组
int n; //商品数量
public:
void newFile()
{
int id;
char name[50]; //字符数组
int count;
float iprice;
float oprice;
char gys[20];
if(n<0)
n=0;
int i;
Data temp;
for(;;n++)
{
cout<<"商品编号:";
cin>>id;
if(id==-1)
break;
t[n].setId(id);
cout<<"商品名:";
cin>>name;
t[n].setName(name);
cout<<"库存量:";
cin>>count;
t[n].setCount(count);
cout<<"进价:";
—5—
cin>>iprice;
t[n].setBuy(iprice);
cout<<"售价:";
cin>>oprice;
t[n].setSale(oprice);
cout<<"供应商:";
cin>>gys;
t[n].setGys(gys);
t[n].setSaleCount(0);//售出此产品0个
cout<<"若商品添加完毕,请按-1退出添加!"<<endl;
for(i=0;i<n;i++)
{
if(t[i].getId()>t[n].getId())
{
temp=t[i];
t[i]=t[n];
t[n]=temp;
}
}
}
}
void showData(int i)
{
cout<<t[i].getId()
<<setw(10)<<t[i].getName()
<<setw(10)<<t[i].getCount()
<<setw(10)<<t[i].getSaleCount()
—6—
<<setw(8)<<t[i].getBuy()
<<setw(8)<<t[i].getSale()
<<setw(8)<<t[i].getGys()<<endl;
}
void showData()
{
cout<<"商品编号"
<<setw(8)<<"商品名"
<<setw(8)<<"库存量"
<<setw(10)<<"已售量"
<<setw(10)<<"进价"
<<setw(8)<<"售价"
—6—
<<setw(8)<<"供应商"<<endl;
for(int i=0;i<n;i++)
if(t[i].getCount()>0 )
showData(i);
cout<<"产品种类:"<<n<<endl;
}
void save() //写入数据至文件
{
ofstream fout;
fout.open("商品销售管理系统.txt");
if(!fout)
{
cout<<"cannot open the file!"<<endl;
return ;
}
fout<<"商品编号"<<" "<<"商品名"<<" "<<"库存量"<<" "<<"进价"<<" "<<"售价"<<" "<<"供应商"<<" "<<"已售量"<<endl;
for(int i=0;i<n;i++)
{
fout<<t[i].getId()<<setw(14)<<t[i].getName()<<setw(10)<<t[i].getCount()<<setw(10)<<t[i].getBuy()<<setw(10)<<t[i].getSale()<<setw(10)<<t[i].getGys()<<setw(10)<<t[i].getSaleCount();
}
cout<<"*************Save Success!*****************"<<endl;
fout.close();
}
int search()
{
int id;
cout<<"id:";
cin>>id;
int low=0,mid,high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(t[mid].getId()==id)
return mid;
else if(t[mid].getId()>id)
high=mid-1;
Else
low=mid+1;
—7—
}
return -1;
}
void sale()
{
cout<<"产品编号";
int temp;
temp=search();
if(temp==-1)
{
cout<<"cannot find the commodity!"<<endl;
return;
}
if(t[temp].getCount()<=0)
{
cout<<"此产品已缺!"<<endl;
}
int count;
cout<<"输入数量:";
cin>>count;
float money;
cout<<"输入收到金额(元):";
cin>>money;
if(count<=0 && count>t[temp].getCount())//输入的是负数或超出该产品库存量
cout<<"数量输入不正确"<<endl;
else if(money<t[temp].getSale()*count)
—8—
cout<<"购物金额不足,还需增加金额"<<t[temp].getSale()*count-money<<"元"<<endl;
else
{
t[temp].setCount(t[temp].getCount()-count);//当前库存减少count
t[temp].setSaleCount(t[temp].getSaleCount()+count);//出售量增加count
cout<<"***名称:"<<t[temp].getName()<<endl
<<"***数量:"<<count<<endl
<<"***单价:"<<t[temp].getSale()<<"元"<<endl
—8—
<<"***应收:"<<count*t[temp].getSale()<<"元"<<endl
<<"***找零:"<<money-count*t[temp].getSale()<<"元"<<endl
<<"*************"<<endl;
}
}
void showSale()
{
for(int i=0;i<n;i++)
if(t[i].getSaleCount()>0 )
showData(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(;;)
{
cout<<" 请选择:";
cin>>c;
—9—
switch(c)
{
case 1:com.newFile();break;
case 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: binary '<<' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
t[i].getName后面少了()
五、 用户手册
1、 本程序的运行环境为windows操作系统,执行文件为Ks..exe;
2、 进入演示程序后,即显示对话形式的提示操作过程:
如:第一项:(1)商品添加功能
在选择一栏输入:1
即显示商品编号、商品名、库存量、进价、售价、供应商各项商
品信息,依次输入所需添加的数据 。添加商品完毕,按-1退出添加。
选择:2 即将商品信息保存。
选择:3 显示已保存的商品信息。
选择:4 重新回到主菜单。
选择:5 进行商品销售结算。同时选择:3 显示商品库存和已销售的完整信息。
六、测试数据
进入演示程序后,即显示对话形式的提示操作过程:
选择:1
—10—
输入相应提示的商品信息
选择:2 界面显示数据保存成功
选择:3 显示商品信息
—11—
选择:4 重新回到主菜单
选择:5 进行商品结算
选择:3 显示商品信息
七、 附录
程序源代码:
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<iomanip.h> //为了声明标识符setw()函数
#define Mfname 100
class Data //数据类
{
private:
int id;//产品编号
char name[100];//产品名称
int count;//库存数量
int salecount;//已售数量
float iprice;//进价
float oprice;//售价
char gys[20];//供应商
public:
int getId()
{
return id;
}
char *getName()
{
return name;
}
int getCount()
{
return count;
}
int getSaleCount()
{
return salecount;
}
float getBuy()
{
return iprice;
—12—
}
float getSale()
{
return oprice;
}
char *getGys()
{
return gys;
}
//----------------------
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:
—13—
Data t[50]; //数组
int n; //商品数量
public:
void newFile()
{
int id;
char name[50]; //字符数组
int count;
float iprice;
float oprice;
char gys[20];
if(n<0)
n=0;
int i;
Data temp;
for(;;n++)
{
cout<<"商品编号:";
cin>>id;
if(id==-1)
break;
t[n].setId(id);
cout<<"商品名:";
cin>>name;
t[n].setName(name);
cout<<"库存量:";
cin>>count;
t[n].setCount(count);
cout<<"进价:";
cin>>iprice;
t[n].setBuy(iprice);
cout<<"售价:";
cin>>oprice;
t[n].setSale(oprice);
cout<<"供应商:";
cin>>gys;
t[n].setGys(gys);
t[n].setSaleCount(0);//售出此产品0个
—14—
cout<<"若商品添加完毕,请按-1退出添加!"<<endl;
for(i=0;i<n;i++)
{
if(t[i].getId()>t[n].getId())
{
temp=t[i];
t[i]=t[n];
t[n]=temp;
}
}
}
}
void showData(int i)
—15—
{
cout<<t[i].getId()
<<setw(10)<<t[i].getName()
<<setw(10)<<t[i].getCount()
<<setw(10)<<t[i].getSaleCount()
<<setw(8)<<t[i].getBuy()
<<setw(8)<<t[i].getSale()
<<setw(8)<<t[i].getGys()<<endl;
}
void showData()
{
cout<<"商品编号"
<<setw(8)<<"商品名"
<<setw(8)<<"库存量"
<<setw(10)<<"已售量"
<<setw(10)<<"进价"
<<setw(8)<<"售价"
<<setw(8)<<"供应商"<<endl;
for(int i=0;i<n;i++)
if(t[i].getCount()>0 )
showData(i);
cout<<"产品种类:"<<n<<endl;
}
void save() //写入数据至文件
{
ofstream fout;
fout.open("商品销售管理系统.txt");
if(!fout)
{
—15—
cout<<"cannot open the file!"<<endl;
return ;
}
fout<<"商品编号"<<" "<<"商品名"<<" "<<"库存量"<<" "<<"进价"<<" "<<"售价"<<" "<<"供应商"<<" "<<"已售量"<<endl;
for(int i=0;i<n;i++)
{
fout<<t[i].getId()<<setw(14)<<t[i].getName()<<setw(10)<<t[i].getCount()<<setw(10)<<t[i].getBuy()<<setw(10)<<t[i].getSale()<<setw(10)<<t[i].getGys()<<setw(10)<<t[i].getSaleCount();
}
cout<<"*************Save Success!*****************"<<endl;
fout.close();
}
int search()
{
int id;
cout<<"id:";
cin>>id;
int low=0,mid,high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(t[mid].getId()==id)
return mid;
else if(t[mid].getId()>id)
high=mid-1;
else
low=mid+1;
}
return -1;
}
void sale()
{
cout<<"产品编号";
int temp;
temp=search();
if(temp==-1)
{
cout<<"cannot find the commodity!"<<endl;
return;
—16—
}
if(t[temp].getCount()<=0)
{
cout<<"此产品已缺!"<<endl;
}
int count;
cout<<"输入数量:";
cin>>count;
float money;
cout<<"输入收到金额(元):";
cin>>money;
if(count<=0 && count>t[temp].getCount())//输入的是负数或超出该产品库存量
—17—
cout<<"数量输入不正确"<<endl;
else if(money<t[temp].getSale()*count)
cout<<"购物金额不足,还需增加金额"<<t[temp].getSale()*count-money<<"元"<<endl;
else
{
t[temp].setCount(t[temp].getCount()-count);//当前库存减少count
t[temp].setSaleCount(t[temp].getSaleCount()+count);//出售量增加count
cout<<"***名称:"<<t[temp].getName()<<endl
<<"***数量:"<<count<<endl
<<"***单价:"<<t[temp].getSale()<<"元"<<endl
<<"***应收:"<<count*t[temp].getSale()<<"元"<<endl
<<"***找零:"<<money-count*t[temp].getSale()<<"元"<<endl
<<"*************"<<endl;
}
}
void showSale()
{
for(int i=0;i<n;i++)
if(t[i].getSaleCount()>0 )
showData(i);
}
};
inline void menu()
{
cout<<" ******欢迎使用商品销售管理系统****** "<<endl;
cout<<" **************主菜单********** "<<endl;
cout<<" (1)添加 "<<endl;
—17—
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(;;)
{
cout<<" 请选择:";
cin>>c;
switch(c)
{
case 1:com.newFile();break;
case 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;
}
}
}
—18—
领导小组主要职责:负责组织
展开阅读全文