C++快餐店销售管理软件设计.docx

上传人:b****9 文档编号:26205885 上传时间:2023-06-17 格式:DOCX 页数:27 大小:97.64KB
下载 相关 举报
C++快餐店销售管理软件设计.docx_第1页
第1页 / 共27页
C++快餐店销售管理软件设计.docx_第2页
第2页 / 共27页
C++快餐店销售管理软件设计.docx_第3页
第3页 / 共27页
C++快餐店销售管理软件设计.docx_第4页
第4页 / 共27页
C++快餐店销售管理软件设计.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

C++快餐店销售管理软件设计.docx

《C++快餐店销售管理软件设计.docx》由会员分享,可在线阅读,更多相关《C++快餐店销售管理软件设计.docx(27页珍藏版)》请在冰豆网上搜索。

C++快餐店销售管理软件设计.docx

C++快餐店销售管理软件设计

 

沈阳航空航天大学

 

实验报告

 

课程名称:

面向对象程序设计及C++

实验题目:

快餐店销售管理系统

 

院(系):

计算机学院

专业:

计算机科学与技术

班级:

34010103

学号:

2013040101133

姓名:

吴小勇

一、实验目的

达到对所学面向对象程序设计知识的一次综合运用,熟练掌握面象对象分析问题、解决问题的方法。

2、实验内容描述

快餐店销售管理主要包含显示菜单和购买商品,在购买商品之后,把销售之后的数据保存在文件当中,当下一次进行购买或者显示菜单时直接从文件中把快餐店的商品销售信息,剩余商品数量等等读取出来。

商品包含两类,分别是食物类和饮料类,都是继承自基类商品类。

3、

-first:

Node*

Node

类设计及描述

+acnt:

Goods*

+next:

Node*

Goods

+Goods(string,int,int,int,float)

+ssetcount(intco):

int

+ssetsalecount(intsco):

int

+getid():

int

+getname():

int

+getcount():

int

+getsalecount():

int

+getoprice():

float

+virtualshowData():

void

+virtualsaleG():

void

GoodList

+saleGoods():

void

+sale(Goods*p):

void

+find(intiid)const:

Goods*

+save():

void

+deleteN():

void

+Add(Goods&pa):

void

+show():

void

+showD():

void

#name:

string

#id:

int

#count:

int

#salecount:

int

#oprice:

float

-size:

int

Food

Drink

+Food(string,int,int,int,float)

+virtualshowData():

void

+virtualsaleG():

void

+Drink(string,int,int,int,float)

+virtualshowData():

void

+virtualsaleG():

void

 

1、物品类(Goods)是整个类体系的基类,包含了所有物品的销售信息

classGoods{

protected:

stringname;//销售的食物或饮料种类名称

intid;//商品的编号

intcount;//商品的总数

intsalecount;//已售出的商品数

floatoprice;//售价

public:

Goods(stringname,intid,intcount,intsalecount,floatoprice);

intssetcount(intco){count=co;returncount;}//设置库存量

intssetsalecount(intsco){salecount=sco;returnsalecount;}//设置已售量

intgetid(){returnid;}//获取id

stringgetname(){returnname;}//获取产品名

intgetcount(){returncount;}//获取库存量

intgetsalecount(){returnsalecount;}//获取已售量

floatgetoprice(){returnoprice;}//获取售价

virtualvoidshowData();

virtualvoidsaleG(){}

virtual~Goods(){}

};

2、食物类(Food)和饮料类(Drink)是子类:

classFood:

publicGoods{

public:

Food(stringname,intid,intcount,intsalecount,floatoprice)

:

Goods(name,id,count,salecount,oprice){}

virtualvoidshowData();

virtualvoidsaleG();

virtual~Food(){}

};

classDrink:

publicGoods{

public:

Drink(stringname,intid,intcount,intsalecount,floatoprice)

:

Goods(name,id,count,salecount,oprice){}

virtualvoidshowData();

virtualvoidsaleG();

virtual~Drink(){}

};

3、结点类(Node)和链表类(GoodList)对整个类体系进行操作

classNode{

public:

Goods*acnt;

Node*next;

Node(Goods*pa){acnt=pa;next=NULL;}

};

classGoodList{

intsize;Node*first;

public:

GoodList():

size(0),first(NULL){}//构造

voidsaleGoods();//购买

voidsale(Goods*p);

Goods*find(intiid)const;//查找

voidsave();//保存

voiddeleteN();

voidAdd(Goods&pa);//添加

voidshow();//显示

voidshowD();

~GoodList();//析构

};

4、关键函数描述

1、类体系中的所有功能函数

voidGoodList:

:

Add(Goods&pa){//把文件中读取出来的数据添加到链表

Node*temp=first;

Node*pn=newNode(&pa);

if(first==NULL){first=pn;

}else{while(temp->next)temp=temp->next;

temp->next=pn;}

size++;

}

Goods*GoodList:

:

find(intiid)const{//根据输入的商品标号进行查找

Node*pN;

for(pN=first;pN!

=NULL;pN=pN->next){

if((pN->acnt)->getid()==iid){return(pN->acnt);}

}

returnNULL;

}

voidGoodList:

:

save(){//每次销售完商品,把最新数据信息保存进文件中

ofstreamfout;

fout.open("快餐店销售管理系统.txt",ios:

:

out);

if(!

fout){cout<<"cannotopenthefile!

"<

return;

}

Node*q;

for(q=first;q!

=NULL;q=q->next){

fout<<(q->acnt)->getid()<acnt)->getname()<acnt)->getcount()<acnt)->getsalecount()<acnt)->getoprice()<

}

fout<<"-1"<<"\n";

fout.close();

}

voidGoodList:

:

showD(){//从文件中读取销售商品的信息

stringna;inti;intco;intsco;floatop;

ifstreamfin;

fin.open("快餐店销售管理系统.txt");

if(!

fin){cout<<"cannotopenthefile!

"<

return;

}

Goods*pa=NULL;

while(!

fin.eof()){fin>>i>>na>>co>>sco>>op;

if(i==-1)break;

if(i>8){pa=newDrink(na,i,co,sco,op);}

if(i<=8){pa=newFood(na,i,co,sco,op);}

Add(*pa);

}

show();

}

voidGoodList:

:

show(){//把文件中的数据输出到屏幕上

Node*pb;pb=first;

for(intk=0;k

=NULL);k++,pb=pb->next)(pb->acnt)->showData();

}

voidGoodList:

:

deleteN(){//每次购买之后,对链表进行清空,便于循环运行程序

Node*pN=NULL;

while(first!

=NULL){pN=first;

first=first->next;deletepN;pN=NULL;

}

}

voidGoodList:

:

saleGoods(){//购买商品函数

charch='y';intj=0;

for(;ch=='y';j++){inty1;

cout<<"请选择购买的商品编号:

";cin>>y1;

Goods*p=find(y1);

if(p!

=NULL){sale(p);}

else{cout<<"商品"<getid()<<""<getname()<<"不存在"<

deleteN();

cout<<"是否继续购买(是-y,否-n):

";cin>>ch;

if(ch=='y')cout<<"--------------------"<

}

}

2、类体系中的导航菜单函数

inlinevoidmenu(){

cout<<"----------------------------------------"<

cout<<"|******欢迎使用快餐店销售管理系统******|"<

cout<<"|**********主菜单**********|"<

cout<<"|

(1)显示菜单|"<

cout<<"|

(2)购买|"<

cout<<"|(0)退出系统|"<

cout<<"|**************************|"<

cout<<"----------------------------------------"<

}

voidmain(){//主函数

menu();GoodListList;intc;

for(inti=0;;i++){

cout<<"-------------------------------------------------------------"<

cout<<"请选择(1-2-0):

";

cin>>c;

cout<<"-------------------------------------------------------------"<

switch(c){

case1:

List.showD();break;

case2:

List.saleGoods();break;

case0:

{

cout<<"***********谢谢使用**********"<

cout<<"*********!

再见!

**********"<

return;

}

default:

system("cls");menu();cout<<"请输入正确编号"<

break;

}

}

}

5、程序测试/运行的结果

六、实验总结

通过编写快餐店销售管理系统这个程序,感觉到自己有很多方面的不足,在编写过程中多次的求助于老师或同学,不断的查找资料和翻书本,自己真是受益匪浅。

首先,在编程学习中,实践是非常重要的,无论自己在读程序看程序时是多么的明白,但到了电脑面前,才知道在实际操作中有很多问题等着我们去解决。

而且我也意识到学习在很大程度上靠自觉,要自己积极主动的去发现问题和解决问题,遇到不懂得一定要打破沙锅问到底,拿出积极的学习态度!

这样才能巩固我们的基础知识,有利于我们今后的发展,所以以后要多多加强动手操作和编写能力。

其次要多和同学老师交流,因为写程序是有很多技巧和方法的,这是一笔宝贵的经验等着我们去学习,在经常的交流和实践中,才能准确快速的编写出所需要的程序,通过程序进而解决问题。

“书到用时方恨少!

”每一门专业基础课都是我们手中不可替代的武器,只有把他们有机联系起来才有可能实现一个完整的功能,本次C++编程实验使我体会到只有付出才会有收获,只有平日认真学习关键时刻才会不捉襟见肘,只有互助才会顺利。

在实验过程中,只有自己亲手动手,不管它是否有结果。

你要学的是知识,是解决问题的方法和思想,要端正学习态度,一时的成败不足以论英雄,每一次突破都是一种收获,就是在这样的过程中我们才能不断提高。

附录(实验代码)

//fileGoods.h

#ifndefGOODS_H

#defineGOODS_H

#include

#include

#include

usingnamespacestd;

classGoods

{

protected:

stringname;//销售的食物或饮料种类名称

intid;//商品的编号

intcount;//商品的总数

intsalecount;//已售出的商品数

floatoprice;//售价

public:

Goods(stringname,intid,intcount,intsalecount,floatoprice);

//intssetid(intii){id=ii;returnid;}//获取id

intssetcount(intco){count=co;returncount;}//设置库存量

intssetsalecount(intsco){salecount=sco;returnsalecount;}//设置已售量

//floatssetoprice(floatoo){oprice=oo;returnoprice;}//设置售价

intgetid(){returnid;}//获取id

stringgetname(){returnname;}//获取产品名

intgetcount(){returncount;}//获取库存量

intgetsalecount(){returnsalecount;}//获取已售量

floatgetoprice(){returnoprice;}//获取售价

virtualvoidshowData();

virtualvoidsaleG(){}

virtual~Goods(){}

};

#endif

//fileFood.h

#ifndefFOOD_H

#defineFOOD_H

#include"Goods.h"

#include

classFood:

publicGoods

{

public:

Food(stringname,intid,intcount,intsalecount,floatoprice)

:

Goods(name,id,count,salecount,oprice){}

virtualvoidshowData();

virtualvoidsaleG();

virtual~Food(){}

};

#endif

//fileDrink.h

#ifndefDRINK_H

#defineDRINK_H

#include"Goods.h"

#include

classDrink:

publicGoods

{

public:

Drink(stringname,intid,intcount,intsalecount,floatoprice):

Goods(name,id,count,salecount,oprice){}

virtualvoidshowData();

virtualvoidsaleG();

virtual~Drink(){}

};

#endif

//fileGoodList.h

#ifndefGOODLIST_H

#defineGOODLIST_H

#include"Goods.h"

classNode

{

public:

Goods*acnt;

Node*next;

Node(Goods*pa)

{

acnt=pa;

next=NULL;

}

};

classGoodList

{

intsize;Node*first;

public:

GoodList():

size(0),first(NULL){}//构造

voidsaleGoods();//购买

voidsale(Goods*p);

Goods*find(intiid)const;//查找

voidsave();//保存

voiddeleteN();

voidAdd(Goods&pa);//添加

voidshow();//显示

voidshowD();

~GoodList();//析构

};

#endif

//fileGoods.cpp

#include"Goods.h"

#include

Goods:

:

Goods(stringvname,intvid,intvcount,intvsalecount,floatvoprice)

{

name=vname;id=vid;count=vcount;salecount=vsalecount;oprice=voprice;

}

voidGoods:

:

showData()

{

cout<

<

}

//fileFood.cpp

#include"Food.h"

voidFood:

:

showData()

{

cout<<"食物编号"<<""<<"食物名"<<""<<"剩余数量"<<""<<"已售"<<""<<"价格"<<""<

Goods:

:

showData();

}

voidFood:

:

saleG()//购买

{

intdcount;

cout<<"请输入购买数量:

";

cin>>dcount;

intoprice1=0,oprice2=0;

oprice1=oprice;

oprice2=oprice1*dcount;

cout<<"总共(元):

"<

intffcount=0,dsalecount=0;

ffcount=count;

ffcount=ffcount-dcount;

ssetcount(ffcount);

dsalecount=salecount;

dsalecount+=dcount;

ssetsalecount(dsalecount);

}

//fileDrink.cpp

#include"Drink.h"

voidDrink:

:

showData()

{

cout<<"饮料编号"<<""<<"饮料名"<<""<<"剩余数量"<<""<<"已售"<<""<<"价格"<<""<

Goods:

:

showData();

}

voidDrink:

:

saleG()//购买

{

intdcount;

cout<<"请输入购买数量:

";

cin>>dcount;

intoprice1=0,oprice2=0;

oprice1=oprice;

oprice2=oprice1*dcount;

cout<<"总共(元):

"<

intffcount=0,dsalecount=0;

ffcount=count;

ffcount=ffcount-dcount;

ssetcount(ffcount);

dsalecount=salecount;

dsalecount+=dcount;

ssetsalecount(dsalecount);

}

//fileGoodList.cpp

#include"GoodList.h"

#include"Food.h"

#include"Drink.h"

#include"Goods.h"

#include

voidGoodList:

:

Add(Goods&pa)//添加到链表

{

Node*temp=first;

Node*pn=newNode(&pa);

if(first==NULL)

{

first=pn;

}

else

{

while(temp->next)

temp=temp->next;

temp->next=pn;

}

size++;

}

Goods*GoodList:

:

find(intiid)const//查找

{

Node*pN;

for(pN=first;pN!

=NULL;pN=pN->next)

{

if((pN->acnt)->getid()==iid)

{

ret

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

当前位置:首页 > 幼儿教育 > 幼儿读物

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

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