C++课程设计商品管理系统.docx
《C++课程设计商品管理系统.docx》由会员分享,可在线阅读,更多相关《C++课程设计商品管理系统.docx(34页珍藏版)》请在冰豆网上搜索。
![C++课程设计商品管理系统.docx](https://file1.bdocx.com/fileroot1/2023-1/12/613f82b1-3feb-432e-8f25-09635e7baee4/613f82b1-3feb-432e-8f25-09635e7baee41.gif)
C++课程设计商品管理系统
院计算机工程学院
课程设计报告
设计名称:
C++程序设计课程设计
姓名:
学号:
专业班级:
系(院):
设计时间:
设计地点:
指导教师评语:
签名:
成绩:
1、课程设计目的
C++程序设计课程设计是计算机科学与技术专业重要的实践性教学环节之一,本次设计结合
实际应用的要求,使课程设计既覆盖C++的知识点,又接近工程实际需要。
目的是通过课程设计的综合训练,培养学生实际分析问题、解决问题的能力,以及编程和动手能力,最终目标是通过课程设计这种形式,帮助学生系统掌握C++程序设计这门课程的主要内容,养成良好的编程习惯,更好的完成教学任务。
2、课程设计任务与要求:
本次课程设计利用《C++程序设计》课程中所学到的编程知识和编程技巧,完成具有一定难度和工作量的程序设计题目,帮助学生掌握编程、调试的基本技能,独立完成所布置的任务。
要求:
1、对系统进行功能需求分析
2、设计合理的数据结构和系统框架
3、编程简练,程序功能齐全,能正确运行
4、说明书、流程图要清楚
5、课题完成后必须按要求提交课程设计报告
任务:
设计一个商品销售管理系统。
运用C++语言描述商品类、供应商类。
要求设计中综合运用C++基础知识,利用指针对商品、供应商链表进行处理,方便快捷的进行增删改,充分利用友元来处理两个类之间的关系,理解面
向对象程序设计的核心的概念。
(5)
商品信息、供应商信息的输出
实现功能:
备注:
将商品、供应商保存为文件,能够写入与读出。
概要设计
(1)需求分析:
要实现对商品,供应商信息的添加、修改、删除、查找,并输出信息,能够方便快捷,并有用户能详细清楚的操作指南。
(2)模块说明:
本次程序设计中,需要设计10个模块,分别是添加、修改、删除、查找、输出
商品信息和供应商信息,一共4个类:
分别是商品类、商品数据类、供应商类、供应商数据类。
通过几个switch语句实现用户选择功能。
主要函数流程图:
(3)详细设计
商品数据类的设计
classspDataprivate:
charname[100];
intcount;
floatiprice;
floatoprice;
chargys[20];
public:
intid;
intgetld()
char*getName()
intgetCount()
floatgetBuy()
floatgetSale()
char*getGys()
voidsetId(intn)
voidsetName(charna[])
voidsetCount(intc)
voidsetBuy(floati)
voidsetSale(floato)
voidsetGys(charg[])
};
商品类的设计
classCommodityprivate:
spDatat[50];
intn;
public:
voidnewFileO
intid;
intn;
charname[50];
intcount;
floatiprice;
floatoprice;
chargys[20];
if(nvO)
n=O;
inti;
spDatatemp;
for(;;n++)
coutvv"商品编号:
";
cin>>id;
if(id==-1)
break;
t[n].setld(id);
coutvv"商品名:
";
cin>>name;
t[n].setName(name);
coutvv"库存量:
";
cin>>count;
t[n].setCount(count);
coutvv"进价:
";
cin>>iprice;
t[n].setBuy(iprice);
coutvv"售价:
";
cin>>oprice;
t[n].setSale(oprice);
coutvv"供应商:
";
cin>>gys;
t[n].setGys(gys);
coutvv"
若商品添加完毕,请按-1退出添加!
"vvendl;
for(i=0;ivn;i++)
if(t[i].getld()>t[n].getld())
temp=t[i];
t[i]=t[n];
t[n]=temp;
voidshowData(inti)
spDatat,*p;
P=&t;
coutvvp->getld()
vvsetw(IO)vvp->getName()
<getCount()
<getBuy()
<getSale()vvsetw(8)vvp->getGys()vvendl;
voidshowDataO
{intn;
coutvv"商品编号"
vvsetw(8)vv"商品名"vvsetw(8)vv"库存量"<for(inti=0;ivn;i++)
if(t[i].getCount()>0)
showData(i);
coutvv"商品种类:
"<voidsave()
ofstreamfout;
fout.open(”商品清单.txt",ios:
:
app);
if(!
fout)
coutvv"cannotopenthefile!
"<return;
foutvv"商品编号"<<""<<"商品名"<<""<<"库存量"<<""<<"进价"<<"
"<<"售价"<<""<<"供应商"<<""<for(inti=0;ivn;i++)
foutvvt[i].getld()vvsetw(14)vvt[i].getName()vvsetw(10)vvt[i].getCount()vvsetw(10)<CoUt<<"*************SaveSUCCess!
*****************"<fout.closeO;
voidxiugaiO
intcount;
charname[100];
floatiprice;
floatoprice;
chargys[20];
inttemp;
temp=search();
if(temp==-1)
cout<<"cannotfindtheshopping!
"vvendl;
return;
else{coutvv"请输入新数据:
"vvendl;
coutvv"商品名:
";
cin>>name;
t[temp].setName(name);
coutvv"库存量:
";
cin>>count;
t[temp].setCount(count);
coutvv"进价:
";
cin>>iprice;
t[temp].setBuy(iprice);
coutvv"售价:
";
cin>>oprice;
t[temp].setSale(oprice);
coutvv"供应商:
";
cin>>gys;
t[temp].setGys(gys);
intsearchO
{intid;
cout<<"id:
";
cin>>id;
intlow=0,mid,high=n-1;
while(lowv=high)
mid=(low+high)/2;
if(t[mid].getld()==id)
returnmid;
elseif(t[mid].getld()>id)
high=mid-1;
elselow=mid+1;
return-1;
voidremoveO
{spDatat[1O];
coutvv"请输入要删除的商品编号"<intid;
cin>>id;
fstreamfile("
商品清单.txt",ios:
:
in|ios:
:
out|ios:
:
binary);
for(intu=0;u<5;u++)file.read((char*)&t[u],sizeof(t[u]));
for(intv=0;v<5;v++)
if(t[v].id==id)
continue;
else
file.write((char*)&t[v],sizeof(t[v]));
coutvv"该商品被删除"<file.closeO;
};
供应商数据类的设计
classspData
private:
charname[100];
intcount;
floatiprice;
floatoprice;
chargys[20];
public:
intid;
intgetld()char*getName(charna[])intgetCount()floatgetBuy()
floatgetSale()
char*getGys()voidsetld(intn)voidsetName(charna[])voidsetCount(intc)voidsetBuy(floati)voidsetSale(floato)
voidsetGys(charg[])
};
供应商类的设计
classgongyingshang
private:
gysDatat[50];
intn;
public:
voidnewFileO
{intid;
charname[50];
intphone;
if(nv0)
n=0;
for(;;n++)
coutvv"供应商编号:
";
cin>>id;
if(id==-1)
break;
t[n].setid();
coutvv"供应商名称:
";
t[n].setname(name);
coutvv"供应商电话:
";
t[n].setphone();
coutvv"
若供应商添加完毕,请按-1退出添加ryvendl;
voidshowData(inti)
gysDatat,*p;
P=&t;coutvvsetw(8)vvp->getid()
vvsetw(10)vvp->getname()vvsetw(10)vvp->getphone()vvendl;
voidshowDafao
coufAASefw(8)AA
AASefw(8)八八
AASefw(8)八八
AAendr
foranfiHO天n=++)
showDafa(三
OOC7A-「和寻淋「-AAnAAendr
voidsaofsfreamfour
fouf.openvSMMIxpiosjappr
if(一fouf)
coutvv"cannotopenthefile!
"vvendl;
return;
foutvv"供应商编号"<<"
"<<"供应商姓名"<<"
"<<"供应商手机号"<<"
"<
for(inti=0;ivn;i++)foutvvt[i].getid()vvsetw(10)vvt[i].getname()vvsetw(14)vvt[i].getphone()vvendl;
coutvv"*************SaveSuccess!
*****************"<fout.close();
int
search()
intid;
cout<<"id:
";
cin>>id;
intlow=0,mid,high=n-1;
while(lowv=high)
mid=(low+high)/2;
if(t[mid].getid()==id)
returnmid;
elseif(t[mid].getid()>id)
high=mid-1;
elselow=mid+1;
return-1;
voidxiugai()
charname[100];
intphone;
inttemp;
temp=search();
if(temp==-1)
cout<<"cannotfindthegys!
"vvendl;
return;
else{coutvv"请输入新数据:
"vvendl;
coutvv"供应商名:
";
cin>>name;
t[temp].setname(name);
coutvv"供应商手机号:
";
cin>>phone;
t[temp].setphone();
voidremoveO
{gysDatag[10];
coutvv"请输入要删除的供应商编号"<intid;
cin>>id;
fstreamfile("gys.txt",ios:
:
in|ios:
:
out|ios:
:
binary);
for(intu=0;u<5;u++)file.read((char*)&g[u],sizeof(g[u]));
for(intv=0;v<5;v++)
if(g[v].id==id)
continue;
else
file.write((char*)&g[v],sizeof(g[v]));
coutvv"该供应商被删除"<file.closeO;
};
菜单函数的设计
inlinevoidmenu2()
system("cls");
coutvv"
******
欢迎使用商品销售管理系统******"vvendl;
coutvv"
***********
商品选项**********"vvendl;
coutvv"
(1)
添加
"vvendl;
coutvv"
保存
"vvendl;
coutvv"
删除
"vvendl;
coutvv"
查找
"vvendl;
coutvv"
信息输出
"vvendl;
coutvv"
修改
"vvendl;
cout<<"
菜单
"<cout<<"
(0)
退出系统
"<cout<<"
***********20126***********
"<inlinevoidmenu1()
system("cls");
coutvv"
欢迎使用商品销售管理系统******"vvendl;
coutvv"
***********
主菜单**********"vvendl;
coutvv"
(1)
商品选项
"vvendl;
coutvv"
供应商选项
"vvendl;
coutvv"
(0)
退出系统
"vvendl;
coutvv"
***********20126*************
"vvendl;
inlinevoidmenu3()
system("cls");
coutvv"
******
欢迎使用商品销售管理系统******"vvendl;
coutvv"
***********
供应商选项**********"vvendl;
coutvv"
(1)
添加
"vvendl;
coutvv"
保存
"vvendl;
coutvv"
删除
"vvendl;
coutvv"
查找
"vvendl;
coutvv"
信息输出
"vvendl;
coutvv"
修改
"vvendl;
coutvv"
菜单
"vvendl;
coutvv"
(0)
退出系统
"vvendl;
coutvv"
***********20126***********
"vvendl;
主函数的设计:
intmain()
menu1();
请选择:
";
intx;
cout<<"cin>>x;
switch(x)case1:
menu2();
Commoditycom;
intc;
for(;;)
请选择:
";
cout<<"cin>>c;
switch(c)
case1:
com.newFile();break;
case2:
com.save();break;
case3:
com.remove();break;
case4:
com.search;break;
case5:
com.showData();break;
case6:
menu1();break;
coutvv"
*********
:
舟:
^见!
**********
case0:
{
"<"vvendl;
break;
case2:
menu3();
gongyingshanggys;
intc;
请选择:
";
for(;;)
cout<<"cin>>c;
switch(c)case1:
gys.newFile();break;
case2:
gys.save();break;
case3:
gys.remove();break;
case4:
gys.showData();break;
case5:
gys.search();break;
"<"vvendl;
case6:
menu1();break;
case0:
{
coutvv"
coutvv"
break;
***********
谢谢使用**********
*********
**********
case0:
{
coutvv"
mu*
谢谢使用**********
"vvendl;
coutvv"
*********
再^见!
**********
"vvendl;
break;
return0;
(4)调试分析:
程序\3.cpp(226):
warningC4700:
localvariable'n'usedwithouthavingbeeninitialized
程序\3.cpp(246):
warningC4700:
localvariable'c1'usedwithouthavingbeeninitialized
程序\3.cpp(348):
warningC4700:
localvariable'g1'usedwithouthavingbeeninitialized
桌面\q.cpp(237):
errorC2562:
'search':
'void'functionreturningavalue
桌面\q.cpp(228):
seedeclarationof
'search'
桌面\q.cpp(243):
errorC2562:
'search':
'void'functionreturningavalue
桌面\q.cpp(228):
seedeclarationof
'search'
(5)用户使用说明手册:
1.进入演示程序后,即显示对话形式的提示操作过程:
如第一个选择1商品选项,即显示
(1)添加
(2)保存(3)删除(4)查找(5)信息输出
(6)修改(7)菜单(0)退出系统选择1,即显示商品编号、商品名、库存量、进价、售价、供应商各项商品信息,一次输入所添
加的数据。
添加完毕,按-1退出添加;
如第一个选择2,供应商选项,同样显示
(1)添加
(2)保存(3)删除(4)查找(5)
(6)修改
(7)菜单(0)退出系统
信息输出
选择数据的功能跟上面一样。
第一个选择0退出系统。
(6)测试数据
进入演示程序后,即显示对话形式的提示操作过程:
选择:
商品选项
选择:
添加商品
选择:
保存信息
选择:
删除信息
选择:
查找信息
选择:
信息输出
选择:
修改
选择:
退出系统
选择:
供应商选项
供应商信息的各选项跟商品信息的选项一样。
4.课程设计成果
程序源代码
#includeviostream.h>
#include
#include#includeviomanip.h>#defineMfname100
#include
#includevstdio.h>
#includevprocess.h>#includeclassspDataprivate:
charname[100];
intcount;
floatiprice;
floatoprice;
chargys[20];
public:
intid;
intgetld()
returnid;
char*getName()
returnname;
intgetCount()
returncount;
floatgetBuy()
returniprice;
floatgetSaleO
returnoprice;
char*getGys()
returngys;
voidsetld(intn)
id=n;
voidsetName(charna[])
strcpy(name,na);
voidsetCount(intc)
count=c;
voidsetBuy(floati)
iprice=i;
voidsetSale(floato)
oprice=o;
voidsetGys(charg[])
strcpy(gys,g);
};
classgysData
private:
charname[100];
intphone;
public:
intid;
intgetid()
returnid;
char*getname()