C++课程设计-超市管理系统.docx_第1页
C++课程设计-超市管理系统.docx_第2页
C++课程设计-超市管理系统.docx_第3页
C++课程设计-超市管理系统.docx_第4页
C++课程设计-超市管理系统.docx_第5页
已阅读5页,还剩73页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

软件学院课程设计报告设计名称: C+课程设计 选题名称: 超市管理系统 姓名: 学号: 专业班级: 云计算3班 系(院): 软件学院 设计时间: 2016.6.12016.6.10 设计地点: 室验室15#502 一、 系统设计该程序设计主要利用了C+的基本知识,程序的几乎全部工作都是由各个函数分别完成的。该超市管理系统主要实现了对管理员,顾客的功能。以下就是程序实现的主要功能:管理员的功能:1. 录入商品信息2. 添加商品信息3. 查询商品信息4. 删除商品信息5. 修改商品信息6. 显示商品信息7. 统计商品信息8. 返回上级菜单9. 清空商品信息0. 退出系统顾客的功能:1查询商品信息2购买商品3回上级菜单0退出系统程序模块图如下:管理系统统计商品信息返回上级菜单清空商品信息了解商品购买商品修改商品信息删除商品信息查询商品信息添加商品信息录入商品信息显示商品信息退出系统流程图:开始管理员:输入i的值i=修改信息15录入信息26添加信息显示信息37查询信息统计信息48删除信息返回菜单9清空信息0结束顾客:开始输入j的值J=1查询信息2购买商品3返回菜单0结束开始录入流程图:输入t的值iti+是结束增加流程图:开始2输入i的值1i=类别编号输入类别输入编号否是是是否找到是否找到插入插入成功插入成功插入无此商品结束开始查询流程图:结束i=显示无此商品显示无此商品显示查询查询查询是否找到是否找到是否找到输入厂家输入类别输入名称类别厂家名称输入i的值13否2是否否是是删除流程图: 修改流程图:修改信息无此商品结束是否找到输入编号开始开始删除信息无此商品是否找到结束输入类别和名称否否是是二详细设计主文件:1写出头文件#include 40.h#include 40.cpp#include2定义一些变量和对象Administrator t;Administrator p1(123456),p2;Customer n;int i,c,j;3写出主菜单,管理员,顾客的菜单,通过调用函数来实现。主菜单使用全局函数和延迟函数输入,主菜单和管理员,顾客菜单之间用到清屏函数和调用颜色来实现的。int main() Administrator t; Administrator p1(123456),p2; Customer n; int i,c,j; system(color A); Slow(tt_欢迎进入超市商品管理系统_); coutendl; Slow(tt超市管理人员, 请输入1); coutendl; Slow(tt顾客 , 请输入2); coutendl; Slow( tt退出 , 请输入0); coutendl; Slow(tt); cout c; system(cls); system(color B); switch(c) case 1: p2.Login(p1); while(1) couttt_欢迎进入超市商品管理系统_endl; couttt输入商品信息, 请输入1endl; couttt增加商品信息, 请输入2endl; couttt查询商品信息, 请输入3endl; couttt删除商品信息, 请输入4endl; couttt修改商品信息, 请输入5endl; couttt显示商品信息, 请输入6endl; couttt统计商品信息, 请输入7endl; couttt返回上级菜单, 请输入8endl; couttt清空商品信息, 请输入9endl; couttt退出, 请输入0endl; coutttendl; couti; system(cls); system(color A); switch(i) case 1: t.InputandSavefile(); break; case 2: t.Readfile(); t.Add(); t.Savefile(); break; case 3: t.Inquiry(); break; case 4: t.Readfile(); t.Amputate(); t.Savefile(); break; case 5: t.Readfile(); t.Revise(); t.Savefile(); break; case 6: t.Readfile(); t.Print(); break; case 7: t.Readfile(); t.Count(); break; case 8: t.Destroy(); main(); break; case 9: t.Empty(); break; case 0: t.Destroy(); exit(0); default: cout对不起,你的选择是错误的!; cout请你重新选择endl; break; case 2: while(1) couttt_欢迎进入超市商品管理系统_endl; couttt查询商品信息, 请输入1endl; couttt购买商品, 请输入2endl; couttt返回上级菜单, 请输入3endl; couttt退出 , 请输入0endl; coutttendl; coutj; system(cls); system(color C); switch(j) case 1: n.Readfile(); n.Find(); break; case 2: n.Readfile(); n.Buy(); n.Savefile(); break; case 3: n.Destroy(); main(); break; case 0: n.Destroy(); exit(0); default: cout对不起,你的选择是错误的!; cout请你重新选择endl; break; case 0: exit(0);default: cout对不起,你的选择是错误的!; cout请你重新选择endl; main(); return 0;类文件:1写出四个类,信息类,人类,管理员类,顾客类。信息类作为基类,人类继承信息类,派生出的人类也作为基类,管理员类和顾客类继承人类。#ifndef _MAIN_H#define _MAIN_H信息类class Information protected: char type20;/类别 char name20;/商品名称 double price; /价格 int stock;/库存量 char shop20; /生产厂家 int num; /编号 public: Information() Information() virtual int get_num()=0; virtual char *get_type()=0; virtual char *get_shop()=0; virtual char *get_name()=0; virtual int get_stock()=0; virtual double get_price()=0; Information *next; void display(); void show();人类class Person:public Information protected: Information *head; public: Person() Person() Person(int,char *,char *,int,double,char *); char *get_type(); char *get_name(); double get_price(); int get_stock(); char *get_shop(); int get_num(); void Savefile(); void Readfile(); void Destroy();管理员类class Administrator:public Person protected: int password; public: Administrator() Administrator() Administrator (int aa) password=aa; void Login(Administrator &); void InputandSavefile(); void Print(); void Add(); void Add_num(); void Add_type(); void Inquiry(); void Inquiry_type(); void Inquiry_name(); void Inquiry_shop(); void Revise(); void Empty(); void Amputate(); void Count(); void Count_price(); void Count_stock();顾客类class Customer:public Person public: Customer() Customer() void Find(); void Buy(); ;#endif函数实现文件:头文件#include 40.h#include#include#include#includeusing namespace std;全局变量static int s=1;int n=3;返回函数char *Person:get_type() return type;char *Person:get_name() return name;double Person:get_price() return price;int Person:get_stock() return stock;char *Person:get_shop() return shop;int Person:get_num() return num;输入函数Person:Person(int n,char *na,char *ty,int s,double p,char *sh) num=n; strcpy(name,na); strcpy(type,ty); stock=s; price=p; strcpy(shop,sh);显示函数void Information:display() cout编号:numt名称:namet类别:typetendl;void Information:show() cout编号:numt名称:namet类别:typet数量:stockt价格:pricet厂家:shoptendl;延迟函数void Slow(char *p) while(1) if(*p!=0) coutnext; while(p!=NULL) q=p; p=p-next; delete q; delete p;保存函数void Person:Savefile() /保存 Information *p; p=head-next; ofstream infile(ok.txt); if(!infile) coutok.txt cannot be openednext; infile.close();读取函数void Person:Readfile() /读取ifstream outfile(ok.txt);Information *q1,*q2,*head1;head1=new Person;head1-next=NULL;q1=head1;if(!outfile ) coutok.txt cannot be openednext=q2; q1=q2;q1-next=NULL;head=head1;outfile.close();密码函数void Administrator:Login(Administrator &s)int pd=0;cout请登录系统,输入管理员密码:(共有3次机会)pd;doif(pd=s.password) break;elsecout输入错误!(还有 n-1 次机会)endl;n-;if(n=0) exit(0);cout请重新输入:pd;while(n0);录入函数void Administrator:InputandSavefile() Information *p,*q; int num; char shop20; int stock; double price; char name20; char type20; int i=0,t,j; ofstream infile(ok.txt,ios:app); if(!infile) coutok.txt cannot be openedendl; exit(-1); head=new Person(num,name,type,stock,price,shop); p=head; cout你想录入多少信息?t; while(it) couttt选择不同的商品进行创建endl; couttt食品类请按1endl; couttt化妆品类请按2endl; couttt日用品类请按3endl; couttt饮料类请按4endl; coutttendl; cout j; switch(j) case 1: strcpy(type,食品类); break; case 2: strcpy(type,化妆品类); break; case 3: strcpy(type,日用品类); break; case 4: strcpy(type,饮料类); break; num=s; cout输入商品名称:name; cout输入库存数量:stock; cout输入产品单价:price; cout输入生产厂家:shop; q=new Person(num,name,type,stock,price,shop); p-next=q; p=q; infile.write(char *)p,sizeof(Person); i+; s+; p-next=NULL; infile.close();添加函数void Administrator:Add() int t; char ch; do cout-endl; cout- 添加系统-endl; cout-按编号添加,请按1-endl; cout-按类别添加,请按2-endl; cout-退出,请按0-endl; cout-endl; cout请输入1至2,选择适当的添加endl; cout t; switch(t) case 1: Add_num(); break; case 2: Add_type(); break; case 0: exit(0); default: cout对不起,你的选择是错误的!; break; coutt如果继续添加请按 ych; while(ch=y);按编号添加void Administrator:Add_num() Information *p,*q; int num; char name20; char type20; int stock; double price; char shop20; int num1; int j; char ch; do p=head; cout你想插入哪个编号后面?num1; while(p-get_num()!=num1&p-next!=NULL) p=p-next; if(p-get_num()=num1) couttt选择不同的商品进行添加endl; couttt食品类请按1endl; couttt化妆品类请按2endl; couttt日用品类请按3endl; couttt饮料类请按4endl; coutttendl; cout j; switch(j) case 1: strcpy(type,食品类); break; case 2: strcpy(type,化妆品类); break; case 3: strcpy(type,日用品类); break; case 4: strcpy(type,饮料类); break; num=s; cout输入商品名称:name; cout输入库存数量:stock; cout输入产品单价:price; cout输入生产厂家:shop; q=new Person(num,name,type,stock,price,shop); q-next=p-next; p-next=q; s+; cout添加成功!endl; else cout无此商品!endl; coutt如果继续按编号添加请按 ych; while(ch=y);按类别添加void Administrator:Add_type() Information *p,*q; int num; char name20; char type20; int stock; double price; char shop20; int num1; char type120; int j; char ch; do p=head; cout你想插入哪个后面,请输入类别type1; while(strcmp(p-get_type(),type1)!=0&p-next!=NULL) p=p-next; if(strcmp(p-get_type(),type1)=0) cout请输入编号num1; while(p-get_num()!=num1&p-next!=NULL) p=p-next; if(p-get_num()=num1) couttt选择不同的商品进行创建endl; couttt食品类请按1endl; couttt化妆品类请按2endl; couttt日用品类请按3endl; couttt饮料类请按4endl; coutttendl; cout j; switch(j) case 1: strcpy(type,食品类); break; case 2: strcpy(type,化妆品类);break; case 3: strcpy(type,日用品类);break; case 4: strcpy(type,饮料类);break; num=s; cout输入商品名称:name; cout输入库存数量:stock; cout输入产品单价:price; cout输入生产厂家:shop; q=new Person(num,name,type,stock,price,shop); q-next=p-next; p-next=q; s+; cout插入成功!endl; else cout无此商品!endl; else cout无此商品!endl; coutt如果继续按类别添加请按 ych; while(ch=y);查询函数void Administrator:Inquiry() int t; char ch; do cout-endl; cout- 查询系统-endl; cout-按类别查询,请按1-endl; cout-按名称查询,请按2-endl; cout-按厂家查询,请按3-endl; cout-退出,请按0-endl; cout-endl; cout请输入1至3,选择适当的查询endl; cout t; switch(t) case 1: Inquiry_type(); break; case 2: Inquiry_name(); break; case 3: Inquiry_shop(); break; case 0: exit(0); default: cout对不起,你的选择是错误的!; break; coutt如果继续查询请按 ych; while(ch=y);按类别查询void Administrator:Inquiry_type() Information *p; char type120; p=head-next; cout输入你想查询商品的类名type1; while(p!=NULL) if(strcmp(p-get_type(),type1)=0) p-show(); p=p-next; 按名称查询void Administrator:Inquiry_name() Information *p; char name120; p=head-next; cout输入你想查询商品的名称name1; while(p!=NULL) if(strcmp(p-get_name(),name1)=0) p-show(); p=p-next; 按厂家查询void Administrator:Inquiry_shop() Information *p; char shop120; p=head-next; cout输入你想查询商品的名称shop1; while(p!=NULL) if(strcmp(p-get_shop(),shop1)=0) p-show(); p=p-next; 修改函数void Administrator:Revise() Information *p,*q,*t; int num; char name20; char type20; double price; int stock; char shop20; int num1; int j; char ch; do p=head; cout你想修改哪个,请输入编号num1; while(p-get_num()!=num1&p-next!=NULL) t=p; p=p-next; if(p-get_num()=num1) couttt选择不同的商品进行创建endl; couttt食品类请按1endl; couttt化妆品类请按2endl; couttt日用品类请按3endl; couttt饮料类请按4endl; coutttendl; cout j; switch(j) case 1: strcpy(type,食品类); break; case 2: strcpy(type,化妆品类); break; case 3: strcpy(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论