模拟超市收银系统.docx

上传人:b****5 文档编号:6915298 上传时间:2023-01-12 格式:DOCX 页数:24 大小:99.40KB
下载 相关 举报
模拟超市收银系统.docx_第1页
第1页 / 共24页
模拟超市收银系统.docx_第2页
第2页 / 共24页
模拟超市收银系统.docx_第3页
第3页 / 共24页
模拟超市收银系统.docx_第4页
第4页 / 共24页
模拟超市收银系统.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

模拟超市收银系统.docx

《模拟超市收银系统.docx》由会员分享,可在线阅读,更多相关《模拟超市收银系统.docx(24页珍藏版)》请在冰豆网上搜索。

模拟超市收银系统.docx

模拟超市收银系统

课程设计任务书

2012—2013学年第2学期

一、课程设计题目

模拟超市收银系统〔例子〕

二、课程设计内容

使用文本命令行界面模拟超市收银系统

●由收银员输入顾客的会员卡卡号〔假设有卡〕、所购商品的货号等。

从数据库〔或文件〕中取出有关价格信息,再把这些信息返回给收银台。

同时把该收银台的销售总量和有关种类商品的剩余量以及该持卡顾客的消费情况交数据库〔或文件〕存储以供查询。

●另外,对没有卡的消费情况不记录该顾客的消费情况等个人信息。

如果一个未持卡顾客一次性购物满200元,可为其发放一张会员卡,以后在该商场购物可获得9折优惠。

要求:

建立会员账户类、商品信息类、文件读写类、界面显示类等以及各相关接口类。

三、进度安排

〔1〕1-2学时,选定题目、分析需求、理解需求;

〔2〕3-4学时,程序设计,定义数据类型、数据处理方式;

〔3〕5-10学时,编写程序、调试、测试;

〔4〕11-12学时,编写设计报告;

〔5〕13-16学时,辩论。

四、根本要求

〔1〕只能使用C++语言,源程序要有适当的注释,使程序容易阅读

〔2〕至少采用文本菜单界面〔如果能采用图形菜单界面更好〕

〔3〕学生可自动增加新功能模块〔视情况可另外加分〕

〔4〕建立银行账户类、文件读写类、界面显示类等以及各相关接口类。

〔例子〕

〔5〕写出课程设计报告,应不少于3000字〔不含附录〕,同一组学生只需提交1份,但必须在报告中列明分工。

课程负责人签名:

2013年6月28日

模拟超市收银系统〔例子〕

摘要

使用文本命令行界面模拟超市收银系统

●由收银员输入顾客的会员卡卡号〔假设有卡〕、所购商品的货号等。

从数据库〔或文件〕中取出有关价格信息,再把这些信息返回给收银台。

同时把该收银台的销售总量和有关种类商品的剩余量以及该持卡顾客的消费情况交数据库〔或文件〕存储以供查询。

●另外,对没有卡的消费情况不记录该顾客的消费情况等个人信息。

如果一个未持卡顾客一次性购物满200元,可为其发放一张会员卡,以后在该商场购物可获得9折优惠。

要求:

建立会员账户类、商品信息类、文件读写类、界面显示类等以及各相关接口类。

关键词:

面向对象;超市收银系统;文件操作

 

第一章设计内容

 

设计一个模拟超市收银系统操作的程序,输入你需要的操作〔选择相对的括号里的阿拉伯数字〕程序具体功能有:

(1)顾客结账{付款方式:

1.会员结账2.普通结账}

(2)增加商品

(3)增加会员

(4)查询会员消费记录

〔0〕退出

第二章总体设计

2.1模块化设计

为实现系统功能,本程序主要分为五个模块。

它们分别为:

顾客结账〔内含付款方式:

会员结账,普通结账〕;增加商品;增加会员;查询会员消费记录;退出,这五个函数再通过主函数调用分别得以实现。

主函数,首先提供了程序运行时的友好界面,提供客户选择的菜单。

然后,通过执行多分支选择语句——switch语句,分别实现其它各个函数的调用功能。

其它各个函数的功能分别如下:

顾客结账:

{1.会员结账vip_count()2.普通结账count()}

商品入库:

input()

增加会员:

CClientele()

查询会员消费记录:

Rec.read_record();

显示所有商品:

all();

找零:

change();

 

2.2程序运行示意图

 

 

是否

 

第三章详细设计

3.文件设计

本程序中,运用了多种函数。

首先商品入库、参加会员、显示主界面、再按数字输入进展选择性操作。

在主函数中分别调用各项的函数。

//商品入库

voidProduct:

:

input(){

cout<<"编号:

";

cin>>id;

ifstreaminfile("Goods.dat",ios:

:

in|ios:

:

binary);//判断商品是否已存在

if(!

infile){

d_show();

exit;

}

while(infile){

intn;

infile.read((char*)&G1,sizeof(G1));

n=infile.gcount();

if(n==sizeof(G1))

if(G1.id==id){

cout<<"货物已存在,请核实后再输入!

"<

return;

}

}

infile.close();

cout<<"商品名:

";

cin>>Goodsname;

cout<<"单价:

";

cin>>price;

cout<<"数量:

";

cin>>number;

G1.Setdata(id,Goodsname,price,number);

ofstreamoutfile("Goods.dat",ios:

:

app|ios:

:

binary);

if(!

outfile){

d_show();

exit;

}

outfile.write((char*)&G1,sizeof(G1));

outfile.close();

b_show();

}

 

//增加会员

voidClientele:

:

CClientele(){

cout<<"输入卡号:

";

cin>>num;

ofstreamoutfile("Clientele.dat",ios:

:

app|ios:

:

binary);//将文件输出提前定义,为了能创立文件

if(outfile){

ifstreaminfile("Clientele.dat",ios:

:

in|ios:

:

binary);//判断会员是否已存在

if(!

infile){

d_show();

exit;

}

while(infile){

intn;

infile.read((char*)&C1,sizeof(C1));

n=infile.gcount();

if(n==sizeof(C1))

if(C1.num==num){

cout<<"该会员以存在,请核实后再输入!

"<

return;

}

}

infile.close();

}

cout<<"输入姓名:

";

cin>>name;

C1.Setdata(num,name);

outfile.write((char*)&C1,sizeof(C1));

outfile.close();

b_show();

}

3.2程序模块设计

本程序执行的入口是main函数,在main函数中首先调用了界面类中的各项操作的函数,在界面类中选择所需要进展的操作,在switch语句进展界面显示,实现超市收银系统算法的操作

while

(1){

show.a_show();

show.b_show();

Goods.all();

show.b_show();

cout<<"1.顾客结账2.增加商品3.增加会员\n\n4.查询会员消费记录\t0.退出\n";

show.b_show();

cout<<"请选择:

";

cin>>i;

show.b_show();

switch(i){

case1:

cout<<"付款方式:

1.会员结账2.普通结账"<

";

cin>>n;

show.b_show();

switch(n){

case1:

VIP.SClientele();

Goods.vip_count();

show.c_show();

break;

case2:

Goods.count();

show.c_show();

break;

}

break;

case2:

Goods.input();

break;

case3:

VIP.CClientele();

break;

case4:

Rec.read_record();

break;

case0:

return1;

}

}

return0;

}

 

第四章调试与测试

4.1调试过程中的主要问题

由于本程序是分界面设计的,所以运行时选择完操作并且执行完操作后,又会继续回到主菜单,供用户继续选择操作并执行操作。

对于本程序的调试运行,总体上情况良好。

但是,其中也出现了一些小问题。

我发现的主要问题有:

从文件读取数据到vector时,有时会产生错误;以及保存到文件中时,也存在格式上的问题。

后来这些问题均以通过探究与测试中解决。

4.2测试结果

〔1〕主菜单〔如图〕

〔2〕商品入库

(3)增加新会员

〔4〕普通结账

(5)会员结账

〔6〕查询会员消费记录〔如图〕

第五章

超市收银系统程序代码

#include

#include

#include

usingnamespacestd;

//显示类

classShow{

public:

voida_show(){

cout<<"\t***************************************************************\n";

cout<<"\t**欢迎来到超级超市**\n";

cout<<"\t***************************************************************\n";

}

staticvoidb_show(){

cout<<"------------------------------------------------------\n";

}

voidc_show(){

cout<<"\n\t************************欢迎再次光临!

*************************\n\n";

cout<<"\t**************************************************************\n\n\n\n";

}

staticvoidd_show(){

cout<<"openerror!

";

}

};

 

//会员类

classClientele:

publicShow{

intnum;//卡号

charname[20];//会员名

public:

Clientele(){//初始化

num=0;

name[0]=0;

}

Clientele(intnuml,char*namel){

Setdata(numl,namel);

}

~Clientele(){}

intGetnum(){returnnum;}

char*Getname(){returnname;}

voidSetdata(int,char*);//对Clientele进展赋值

voidShowClientele();//显示会员信息

voidSClientele();//搜索会员

voidCClientele();//添加会员

};

//产品类

classProduct:

publicShow{

public:

voidinput();//商品入库

voidcount();//普通结账

voidvip_count();//会员结账

voidall();//显示所有商品

voidchange();//找零

voidSetdata(int,char*,int,int);//对Product进展赋值

voidShow(int);

voidShowl(){

cout<

}

Product(){//初始化

id=0;

name[0]=0;

price=0;

number=0;

}

Product(intidl,char*namel,intpricel,intnumberl){

Setdata(idl,namel,pricel,numberl);

}

~Product(){}

intGetid(){returnid;}

char*Getname(){returnname;}

intGetprice(){returnprice;}

intGetnumber(){returnnumber;}

private:

intid;//商品编号

charname[20];//商品名

intprice;//单价

intnumber;//数量

};

//记录会员消费记录类

classrecord:

publicClientele,publicProduct{

private:

intnum,goodsid,goodsprice,goodsnum;

charname[20],goodsname[20];

public:

record(){

num=0;

name[0]=0;

goodsid=0;

goodsname[0]=0;

goodsprice=0;

goodsnum=0;

}

record(intnuml,char*namel,intgoodsidl,char*goodsnamel,intgoodspricel,intgoodsnuml):

Clientele(numl,namel),Product(goodsidl,goodsnamel,goodspricel,goodsnuml){

Setdata(numl,namel,goodsidl,goodsnamel,goodspricel,goodsnuml);

}

~record(){}

//赋值

voidSetdata(intnuml,char*namel,intgoodsidl,char*goodsnamel,intgoodspricel,intgoodsnuml){

num=numl;

strcpy_s(name,namel);

goodsid=goodsidl;

strcpy_s(goodsname,goodsnamel);

goodsprice=goodspricel;

goodsnum=goodsnuml;

}

voidviprecord();//记录会员消费

voidread_record();//查询记录

voidShow();

};

//全局变量

ClienteleC1;

ProductG1;

recordR1;

intnum,i,j,n,id,price,number;

charname[20],Goodsname[20];

//对Clientele进展赋值

voidClientele:

:

Setdata(intnuml,char*namel){

num=numl;

strcpy_s(name,namel);

}

//Product赋值

voidProduct:

:

Setdata(intidl,char*namel,intpricel,intnumberl){

id=idl;

strcpy_s(name,namel);

price=pricel;

number=numberl;

}

//查询会员信息

voidClientele:

:

SClientele(){

cout<<"输入卡号:

";

cin>>num;

b_show();

ifstreaminfile("Clientele.dat",ios:

:

in|ios:

:

binary);

if(!

infile){

d_show();

exit;

}

while(infile){

intn;

infile.read((char*)&C1,sizeof(C1));

n=infile.gcount();

if(n==sizeof(C1))

if(C1.num==num){

C1.ShowClientele();

break;

}

}

infile.close();

b_show();

}

//记录新会员

voidClientele:

:

CClientele(){

cout<<"输入卡号:

";

cin>>num;

ofstreamoutfile("Clientele.dat",ios:

:

app|ios:

:

binary);//将文件输出提前定义,为了能创立文件

if(outfile){

ifstreaminfile("Clientele.dat",ios:

:

in|ios:

:

binary);//判断会员是否已存在

if(!

infile){

d_show();

exit;

}

while(infile){

intn;

infile.read((char*)&C1,sizeof(C1));//从文件中读取C1数据,长度为C1

n=infile.gcount();//gcount()用来获得实际读取的字节数,不出错n是等于C1的长度

if(n==sizeof(C1))//如果n等于C1的长度,就可以执行

if(C1.num==num){

cout<<"该会员以存在,请核实后再输入!

"<

return;

}

}

infile.close();

}

cout<<"输入姓名:

";

cin>>name;

C1.Setdata(num,name);

outfile.write((char*)&C1,sizeof(C1));

outfile.close();

b_show();

}

//商品入库

voidProduct:

:

input(){

cout<<"编号:

";

cin>>id;

ifstreaminfile("Goods.dat",ios:

:

in|ios:

:

binary);//判断商品是否已存在

if(!

infile){

d_show();

exit;

}

while(infile){

intn;

infile.read((char*)&G1,sizeof(G1));

n=infile.gcount();

if(n==sizeof(G1))

if(G1.id==id){

cout<<"货物已存在,请核实后再输入!

"<

return;

}

}

infile.close();

cout<<"商品名:

";

cin>>Goodsname;

cout<<"单价:

";

cin>>price;

cout<<"数量:

";

cin>>number;

G1.Setdata(id,Goodsname,price,number);

ofstreamoutfile("Goods.dat",ios:

:

app|ios:

:

binary);

if(!

outfile){

d_show();

exit;

}

outfile.write((char*)&G1,sizeof(G1));

outfile.close();

b_show();

}

//显示所有商品

voidProduct:

:

all(){

ifstreaminfile("Goods.dat",ios:

:

in|ios:

:

binary);

if(!

infile){//如果翻开文件失败,那么创立文件

ofstreamoutfile("Goods.dat",ios:

:

binary);

outfile.close();

}

cout<<"编号\t"<<"名字\t"<<"单价\t"<<"数量\t"<

while(infile){

intn;

infile.read((char*)&G1,sizeof(G1));

n=infile.gcount();

if(n==sizeof(G1))

G1.Showl();

}

infile.close();

}

//普通结账

voidProduct:

:

count(){

ints=0,S=0,k;

cout<<"完毕输入按“0〞"<

do{

cout<<"商品编号:

";

cin>>i;

cout<<"购置数量:

";

cin>>j;

b_show();

ifstreaminfile("Goods.dat",ios:

:

in|ios:

:

binary);

if(!

infile){

d_show();

exit;

}

while(infile){

intn;

infile.read((char*)&G1,sizeof(G1));

n=infile.gcount();

if(n==sizeof(G1))

if(G1.id==i){

G1.Show(j);

b_show();

s=G1.price*j;//导入单价和购置数量,进展结算

S=S+s;

break;

}

}

infile.close();

}while(i!

=0);

cout<<"金额:

"<

cout<<"收款:

";

cin>>k;

cout<<"找零:

"<

if(S>200){//消费超过200,办理会员

cout<<"消费已超过200,可办理会员,“y/n〞"<

charl;

cin>>l;

if(l='y')

C1.CClientele();

}

b_show();

}

//会员结账

voidProduct:

:

vip_count(){

ints=0,S=0,k;

cout<<"完毕输入按“0〞"<

do{

cout<<"商品编号:

";

cin>>i;

cout<<"购置数量:

";

cin>>j;

ifstreaminfile("Goods.dat",ios:

:

in|ios:

:

binary);

if(!

infile){

d_show();

exit;

}

while(infile){

intn;

infile.read((char*)&G1,sizeof(G1));

n=infile.gcount();

if(n==sizeof(G1))

if(G1.id==i)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1