版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、商品销售统计 1. 需求和规格说明 1.1问题描述 编写商品销售统计程序,商品的信息有商品名、计量单位(重量 或件)、单价。所有商品的信息事先已存入计算机,屏幕上显示所有 商品的名称,选择商品名,输入商品计量单位(如重量、件数等), 根据单价算出总价。客户一次可能购买多种商品,程序应计算出客户 应付的钱款数。 1.2基本要求 程序分为两个部分:第一部分用于输入商品的信息并允许修改和 删除;第二部分实现销售统计。程序运行时由用户选择进入哪一部分 功能,并能在运行时在两部分之间切换。第二部分运行时,首先显示 所有商品名称及代码(商品数目较多时,应考虑分屏显示),用户输 入商品代码及商品重量或件数,
2、用户一次操作可输入若干商品的购买 信息,然后输入一个特殊的代码(如“-1”表示本次购物结束。此 时,程序计算出应付钱款数并显示。 2. 设计 2.1文字描述 先定义一个商品类GOODS,含有每种商品基本信息即商品名、 计量单位(重量或件)、单价、商品总量皆被定义为私有数据成员; 公有成员部分有该类构造函数以及其他友元函数。 为了完成程序基本要求,采用嵌套系统思想,即先构造一个总的 系统一一商品销售统计工程,通过 switch语句可选择进入其下面两 个子系统商品信息管理系统和商品销售系统,以完成程序要求的 两个部分的功能。其中,每个子系统又可根据 switch语句进行选择 操作,并能实现在两个子
3、系统之间的切换。 2.2图示 类名 类别 类型 名称 说明 private stri ng n ame 商品名 private stri ng un it 计量单位 private double price per un it 单价 private double amount 商品总数 public GOODS) 构造函数 GOODS friend viod sort() 排序,使得信息为空的商品沉底 friend viod in put gds mesg() 底层函数:录入商品信息 friend viod Message modify() 底层函数:修改商品信息 friend viod Me
4、ssage delete() 底层函数:删除商品信息 friend viod Goods Message Ma nage() 中层函数:1.商品信息管理系统 friend viod Goods Sale() 中层函数:2.商品销售系统 friend viod WORK() 高层函数:商品销售统计工程 3. 用户手册 根据提示选择操作即可,具体为: (1)程序运行时,首先要求初始化商品信息,即需添加销售的 商品名称、单价等; (2 )根据需求选择进入商品信息管理系统或者商品销售系统, 其中前者可进行的操作有:录入新商品信息、修改商品信息、删除商 品信息等,后者为用户提供购买商品功能,只需根据提示
5、操作即可; 注意:请输入与程序要求相应的选择以及正确的格式,不要超出 程序给定的范围! 4. 附录源代码 #in clude #in clude #in clude using n amespace std; int choice; class GOODS private: string name;/ 商品名 string unit;/ 计量单位 double price_per_unit; / 单价 double amount;/ 商品总数 public: GOODS(); /构造函数 /排序函数,使得信息为空的商品类数组元素沉底,不为空的排在前面 (被删除商品信息函数调用) frie nd
6、 void sort(GOODS array,i nt size); frie nd void in put_gds_mesg(GOODS goods1,i nt size);/底层函 数:录入商品信息(从属于商品信息管理系统) friend void Message_modify(GOODS goods2,int size);/ 底层函 数:修改商品信息(从属于商品信息管理系统) friend void Message_delete(GOODS goods3,int size);/ 底层函 数:删除商品信息(从属于商品信息管理系统) friend void Goods_Message_Man
7、age(GOODSGoods1,int size); /中层函数:1.商品信息管理系统(从属于商品销售统计工程) friend void Goods_Sale(GOODS Goods2,int size);/ 中层函数: 2商品销售系统(从属于商品销售统计工程) friend void WORK(GOODS Goods,int size);/ 高层函数:商品销 售统计工程 ; GOODS:GOODS() n ame=0; un it=0; price_per_ un it=0.0; amoun t=0; void input_gds_mesg(GOODS goods1,int size)/ 底
8、层函数: 息函数(从属于商品信息管理系统) int i,j,m=0; int s=size; int n=size; stri ng l; for(i=0;is;i+) if(goods1i. name!=0)m+; else if(goods1i. name=0)s=m; for(j=m;j n;j+) cout 录入商品信 e ndl; cout请输入第j+1 goods1j. name; 种商品的名称: e ndl; coute ndl; cout请输入第j+1 goods1j.u nit; coute ndl; cout请输入第j+1 goods1j.price_per_ un it;
9、 种商品的计量单位: 种商品的单价(元) coute ndl; cout请输入第j+1 goods1j.am ount; cout coute ndl; coutvv_ 继续录入商品信息? ( y/n ) _ cin 1; coute ndl; if(l= n|l=N) n=j; else if(|=y|=Y); cout_商品信息录入完成!endlendl; cout e ndl; return; 修改商品信 void Message_modify(GOODS goods2,int size)/ 底层函数: 息函数(从属于商品信息管理系统) if(goods20. name=0) cout
10、c; cout e ndl; coute ndl; if(c=y|c=Y) Goods_Message_Ma nage(goods2,size); WORK(goods2,size); else cout谢谢使用, 祝您愉快!再见! vvvvvvvvvvvvvvvvvvvvvvvvvvvve ndl; exit(O); stri ng p,q; int n; stri ng un it; stri ng n ame; double price; double amount; int choice2; do do coutvv 商品信息列表 e ndle ndl; coutvvt 商品编号t商品
11、名称t商品单价t商品余量 e ndle ndl; int i,m=0; int s=size; for(i=0;is;i+) if(goods2i. name!=0)m+; else if(goods2i. name=0)s=m; for(i=0;im;i+) coutvvtvvi+1v.vvtvvtvvgoods2i. namevtvvgoods2 i.price_per_ un it元 vv/vvgoods2i.u nitvtvvgoods2i.amou ntgoods2i.u nit en dle ndl; cout 请输入您想修改信息的商品编号:_; / int n; cinn; co
12、ut e ndl; coute ndl; coutvv您想修改信息的商品为: p; coute ndl; if(p=y|p=Y) cout e ndl; do cout1.修改商品名称endlendl; cout2.修改商品计量单位endlendl; cout3.修改商品单价(元)endlendl; cout4.修改商品数量endlendl; cout e ndl; cout请输入您的选择(1-4): _; cin choice2; coute ndl; switch(choice2) case 1: cout 请输入 n 号商品 goods2n-1.n
13、amen ame; goods2 n-1. name=n ame; break; case 2: cout 请输入*号商品 goods2 n-1. name的计量单位:_; /!stri ng un it; cinun it; goods2 n-1.u nit=un it; break; case 3: cout 请输入 n号商品 price; goods2 n-1.price_per_ un it=price; break; case 4: cout 请输入 n号商品 am ount; goods2 n-1.am oun t=am
14、ount; break; default: coutvCautio n:对不起,输入有误,请从新输入!; break; while(choice2!=1 while(p= n|p=N); cout e ndl; cout_ 继续修改商品信息(y/n )? _; /stri ng q; cinq; coute ndl; while(q=y|q=Y); cout_商 品 信 息 修 改 完 成! J cout e ndl; return; void sort(GOODS array,int size) /排序函数,使得信息为空的商品类数组 元素沉底,不为空的排在前面(被删除商品信息函数调用) in
15、t i,j; GOODS temp; for(i=0;isize-1;i+) for(j=0;jsize-1-i;j+) if(arrayj. name=0 arrayj=arrayj+1; arrayj+1=temp; return; void Message_delete(GOODS goods3,int size)/ 底层函数: 息函数(从属于商品信息管理系统) if(goods30. name=0) cout c; cout e ndl; coute ndl; if(c=y|c=Y) Goods_Message_Ma nage(goods3,size); WORK(goods3,siz
16、e); else cout 祝您愉快!再见! vvvvvvvvvvvvvvvvvvvvvvvvvvvve ndl; exit(0); 删除商品信 (y/n)_ 谢谢使用, stri ng p,q; int n; stri ng un it; /double price; do do coutvv 商品信息列表 e ndle ndl; coutvvt 商品编号t商品名称t商品单价t商品余量 e ndle ndl; int i,m=0; int s=size; for(i=0;is;i+) if(goods3i. name!=0)m+; else if(goods3i. name=0)s=m; f
17、or(i=0;im;i+) coutvvtvvi+1vtvvtvvgoods3i. namevtvvgoods3i.pri ce_per_ un it元 vv/vvgoods3i.u nitvtvvgoods3i.amou ntgoods3i.u nit en dle ndl; cout e ndl; cout 请输入您想删除信息的商品编号: /int n; cinn; coute ndl; 的商品为: coutvv_您想删除信息 p; coute ndl; if(p=y|p=Y) goods3 n-1. name=0; goods3 n-1.u nit
18、=0; goods3 n-1.price_per_ un it=0.0; goods3 n-1.am oun t=0; cout q; coutvve ndl; while(q=y|q=Y); coutvv商 品 信 息 删 coutvv e ndl; sort(goods3,size); return; 中层函数:M. void Goods_Message_Ma nage(GOODS Goods1,i nt size) / 商品信息管理系统(从属于商品销售统计工程) int choicel; do cout e ndl; cout e ndl; cout e ndl; cout e ndl;
19、 cout 商品信息管理系统 e ndle ndl; cout 行 的 操 作 cout 请选择您要执 e ndle ndl; 1.录入新商品信息 e ndl; cout 2修改商品信息 e ndl; cout e ndl; cout 3.删除商品信息 4.返回 e ndl; cout 0.退出 cout e ndl; cout请输入您的选择:(0-4)_ cin choice1; switch(choicel) cout谢谢使用, 祝您愉快!再见! vvvvvvvvvvvvvvvvvvvvvvvvvvvve ndl; exit(0); break; default: coutvv对不起,您的
20、输入有误,请重新进行选择! e ndle ndl; break; while(choice1!=0 return; void Goods_Sale(GOODS Goods2,int size) / 中层函数:S.商品销售系统 (从属于商品销售统计工程) if(Goods20. name=0) cout c; cout 谢谢使用, 祝您愉快!再见! vvvvvvvvvvvvvvvvvvvvvvvvvvvve ndl; exit(0); stri ng p,q; int num1000,amou nt1OOO;num 存放所要购买商品的 编号, amount存放购买的每种商品数量 int j=0,
21、f=0,r=0; stri ng un it; double mon ey=0.0; do do cout e ndle ndl; coutvvt 商品编号t商品名称t商品单价t商品余量 e ndle ndl; int i,m=0; int s=size; for(i=0;is;i+) if(Goods2i. name!=0)m+; else if(Goods2i. name=0)s=m; for(i=0;im;i+) coutvvtvvi+1vvtvvtvGoods2i. namevtvGoods2i.pri ce_per_ un it元 vv/vGoods2i.u nitvtvGoods2
22、i.amou ntGoods2i.u nit en dle ndl; cout 请输入您想购买的商品的编号(输入“0”结束): nu mj; / do / /cinnu mj; /j+; /while(nu mj-1!=0); cout_您想购买的商品为:endlendl; cout e ndl; cout_商品编号t商品名称endlendl; for(f=0;fvj-1;f+) if(nu mf!=0) cout numfvvtvvtvGoods2 numf-1. namee ndle ndl; cout p; cout e ndl; coute ndl; if(p=y|p=Y) cout请
23、输入您想购买的商品数量:e ndlvve ndl; cout e ndl; coutvv商品编号t商品名称t购买数量endlvvendl; for(f=0,r=0;(fvj-1)f+,叶+) if(nu mf!=0) cout nu mfvvtvvtv am oun tr; Goods2 nu mf-1.am oun t-=am oun tr; coute ndl; cout e ndl; while(p= n|p=N); coutvv_ 您购买的商品信息如下:endlvvendl; cout e ndl; coutt 商品编号t商品名称t商品单价t购买数量 e ndlvve ndl; for(f=0,r=0;(fj-1)f+j+) if(nu mf!=0) coutvvtvv nu mfvvtvvtvvGoods2 nu mf-1. namevvt vvGoods2 nu mf-1.price_per_ un itvv元 vv/vvGoods2 nu mf-1.u ni tvvtvvamou ntrvvGoods2 nu mf- 1.u nitvve ndlvve ndl; cout e ndl; for(f=0,r=0;(fvj-1)f+j+) if(nu mf!
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- AutoCAD机械制图应用教程(2024版)课件 项目2 图形的绘制与编辑
- 长期卧床患者褥疮的预防策略
- 捣谷平台AI创作挑战每月主题参与赢取积分奖励
- 2024-2025学年公务员考试《常识》自我提分评估【模拟题】附答案详解
- 2024-2025学年度燃气职业技能鉴定考前冲刺测试卷(培优A卷)附答案详解
- 2024-2025学年临床执业医师每日一练试卷及完整答案详解(名师系列)
- 2024-2025学年度公务员考试《常识》高频难、易错点题附答案详解(能力提升)
- 2024-2025学年园林绿化作业人员通关考试题库及1套完整答案详解
- 2024-2025学年全国统考教师资格考试《教育教学知识与能力(小学)》预测复习含答案详解(新)
- 2024-2025学年度信阳航空职业学院单招考试文化素质物理复习提分资料及完整答案详解【夺冠系列】
- 执业兽医全科历年真题及答案完整版
- 急诊患者入院护理常规
- 《防雷减灾管理办法》
- 胶版画教学课件
- 仓库物料标签管理制度
- 麻醉睡眠治疗科普
- T/ZBH 013-2019夹层玻璃用乙烯-乙酸乙烯酯共聚物(EVA)中间膜
- T/BCEA 001-2022装配式建筑施工组织设计规范
- 恒丰银行校招笔试题目及答案
- 作战安全与紧急救援
- 四级考前培训
评论
0/150
提交评论