南京工程学院课程设计说明书(论文) 题目小型超市商品销售管理系统课程名称面向对象程序设计院(系、部、中心)专业班级学生姓名学号设计地点指导教师设计起止时间:2007 年12 月22日至2007年12 月28日目录课程设计任务书 (2)1 功能描述 (7)2 概要设计 (7)2.1 类的设计 (7)2.2 流程图 (8)3 详细设计 (11)4 效果及存在问题 (23)4.1 效果截屏 (23)4.2 存在问题 (27)5 心得体会 (28)6 参考文献 (28)南京工程学院课程设计任务书课程名称面向对象程序设计院(系、部、中心)专业班级起止日期2007 年12月22 日至28日指导教师教师许可或无故不到者,缺勤率达50%的学生不能参加答辩。
答辩时,设计者在5分钟内阐述自己的设计过程和最终结果,突出设计中遇到的主要问题和解决方法,然后回答教师提问。
每位学生答辩总时间一般不超过15分钟。
4.主要参考文献[1] 谭浩强. C++程序设计[M] . 北京:清华大学出版社,2004.[2] 吴乃陵.C++程序设计实践教程[M].北京: 高等教育出版社,2003.[3] 谭浩强. C++程序设计题解与上机指导[M]. 北京:清华大学出版社,1999.[4] 廖雷,罗代忠. C语言程序设计基础实验教程. 北京:高等教育出版社,2005.5.课程设计进度安排起止日期工作内容一.功能描述某小型公司,主要有四类人员:经理、兼职技术人员、销售经理和兼职推销员。
现在,需要存储这些人员的姓名、编号、级别、当月薪水,计算月薪总额并显示全部信息。
要求:(1)其中,人员编号在生成人员信息时同时生成,每输入一个人员信息编号顺序加1。
(2)程序对所有人员有提升级别的功能(3)月薪的计算方法是:经理拿固定月薪,兼职技术人员按工作小时数领取月薪,兼职推销员的报酬按该推销员当月销售额提成,销售经理既拿固定月薪也领取销售提成。
(4)能按姓名或者编号显示、查找、增加、删除和保存各类人员的信息。
二.概要设计2.1 类的设计2.2 流程图(1)主函数流程图(2)添加函数(左图)和删除函数(右图)的流程图(3)查询函数流程图三.详细设计1. 主函数设计#include<iostream.h>#include<conio.h>#include<stdio.h>#include<process.h>#include<fstream.h>#include<string.h>#include<dos.h>void main(){ system("cls");cout<<"\n\n\n\n\t\t********************************************\n"<<"\t\t* *\n"<<"\t\t* *\n"<<"\t\t* 欢迎使用小型超市商品销售管理系统(HYY) *\n"<<"\t\t* *\n"<<"\t\t* Desined by 韩永扬 206050529 *\n"<<"\t\t* *\n"<<"\t\t* (按任意键进入) *\n"<<"\t\t* *\n"<<"\t\t* *\n"<<"\t\t********************************************\n"<<endl;getch();food f;makeup m;drink d;live l;while(1){A:system("cls");int choice;int x;cout<<"\n\n\t\t\t\t主菜单"<<"\n\n\t\t\t\t(1)添加商品品种\n" <<"\n\t\t\t\t(2)查询商品\n"<<"\n\t\t\t\t(3)删除商品"<<"\n\n\t\t\t\t(4)退出"<<"\n\n\n请选择:";cin>>x;switch(x){ case 1:{system("cls");cout<<"\n\n\n\n\n\n\t\t请选择添加哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t(5)返回"<<endl;cin>>choice;switch(choice){case 1:system("cls");f.addf();break;case 2:system("cls");m.addm();break;case 3:system("cls");d.addd();break;case 4:system("cls");l.addl();break;case 5:system("cls");break;}break;}case 2:{system("cls");cout<<"\n\n\n\n\n\n\t\t请选择查询哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t(5)返回"<<endl;cin>>choice;switch(choice){case 1:system("cls");f.searchf();break;case 2:system("cls");m.searchm();break;case 3:system("cls");d.searchd();break;case 4:system("cls");l.searchl();break;case 5:system("cls");break;}break;}case 3:{system("cls");cout<<"\n\n\n\n\n\n\t\t请选择删除哪一类:"<<"\n\n\t\t\t\t(1)食品类"<<"\n\t\t\t\t(2)化妆品类"<<"\n\t\t\t\t(3)饮料类"<<"\n\t\t\t\t(4)生活用品类"<<"\n\t\t\t\t(5)返回"<<endl;cin>>choice;switch(choice){ case 1:system("cls");f.removef();break;case 2:system("cls");m.removem();break;case 3:system("cls");d.removed();break;case 4:system("cls");l.removel();break;case 5:system("cls");break;}break;}case 4:{system("cls");cout<<"\n\n\n\n\n\n\t\t\t\t谢谢使用!"<<"\n\n\t\t\t\t再见!\n";exit(1);}break;default:{cout<<"输入有误,请重选!";goto A;}}}}上面即为主函数,通过switch语句来选择操作:添加,查询,删除,退出。
在每项操作中又用switch语句来选择对哪一类商品进行操作,分别有食品,化妆品,饮料,生活用品四类。
该函数没有把“显示商品利润”作为一项单独操作,而是把该功能加进了“查询”操作中,查询的同时直接显示商品利润。
2. 商品基类设计class spbase{public:int t;float oprice;float iprice;float prof;int quantity;char name[10];void getdate();void showdate();void add();void search();void remove();gett(){return t;}};oid spbase::getdate() //输入函数的设计{ cout<<"\n\t\t请输入商品名称:";cin>>name;cout<<"\n\t\t请输入商品售价:";cin>>oprice;cout<<"\n\t\t请输入商品进价:";cin>>iprice;cout<<"\n\t\t请输入商品库存量:";cin>>quantity;}void spbase::showdate() //输出函数的设计{ cout<<"\n\n商品基本信息如下:";cout<<"\n\n\t\t商品名称:";cout<<name;cout<<"\n\n\t\t商品售价:";cout<<oprice;cout<<"\n\n\t\t商品进价:";cout<<iprice;cout<<"\n\n\t\t商品库存量:";cout<<quantity;prof=(oprice-iprice)*quantity;cout<<"\n\n\t\t商品利润为 :";cout<<prof;}void spbase::add() //添加函数的设计{ t=1;ofstream file("HYY.txt",ios::out|ios::ate);if(!file){cout<<"文件打开失败!";getch();exit(1);}spbase p1;p1.getdate();file.write(reinterpret_cast<char*>(&p1),sizeof(spbase)); // reinterpret_cast强制转换file.close();}void spbase::search() //查询函数的设计{char name4[10];cout<<"\n请输入生活用品名称:";cin>>name4;fstream file("HYY.txt",ios::in);if (!file){cout<<"文件打开失败!";getch();exit(1);}char flag='a'; //设标志位spbase p1;file.read(reinterpret_cast<char*>(&p1),sizeof(spbase));while(!file.eof()) //正确显示,指针还没到末尾继续{ if((strcmp(,name4)==0)&&gett()){p1.showdate();getch();flag='z';break;}file.read(reinterpret_cast<char*>(&p1),sizeof(spbase));}if(flag!='z'){ cout<<("该商品已被删除!");getch();}file.close();}void spbase::remove() //删除函数的设计{ t=0;search();}3. 食品类设计(food)class food:public spbase{ private:char pfs[10];public:void getdatef(){ spbase::getdate();cout<<"\n\t\t请输入商品批发商:";cin>>pfs;}void showdatef(){ spbase::showdate();cout<<"\n\n\t\t商品批发商:";cout<<pfs;}void addf(){ t=1;ofstream file("HYY1.txt",ios::out|ios::ate);if(!file){cout<<"文件打开失败!";getch();exit(1);}food f;f.getdatef();file.write(reinterpret_cast<char*>(&f),sizeof(food)); file.close();}void searchf(){ char name1[10];cout<<"\n请输入食品名称:";cin>>name1;fstream file("HYY1.txt",ios::in);if (!file){cout<<"文件打开失败!";getch();exit(1);}char flag='a';food f;file.read(reinterpret_cast<char*>(&f),sizeof(food)); while(!file.eof()){ if((strcmp(,name1)==0)&&gett()){f.showdatef();getch();flag='z';break;}file.read(reinterpret_cast<char*>(&f),sizeof(food));}if(flag!='z'){ cout<<("该商品已被删除!");getch();}file.close();}void removef(){ t=0;searchf();}};4. 化妆品类设计(makeup)class makeup:public spbase{ private:char pp[10];public:void getdatem(){ spbase::getdate();cout<<"\n\t\t请输入商品品牌:";cin>>pp;}void showdatem(){ spbase::showdate();cout<<"\n\n\t\t商品品牌:";cout<<pp;}void addm(){ t=1;ofstream file("HYY2.txt",ios::out|ios::ate);if(!file){cout<<"文件打开失败!";getch();exit(1);}makeup m;m.getdatem();file.write(reinterpret_cast<char*>(&m),sizeof(makeup)); file.close();}void searchm(){ char name2[10];cout<<"\n请输入化妆品名称:";cin>>name2;fstream file("HYY2.txt",ios::in);if (!file){cout<<"文件打开失败!";getch();exit(1);}char flag='a';makeup m;file.read(reinterpret_cast<char*>(&m),sizeof(makeup)); while(!file.eof()){ if((strcmp(,name2)==0)){m.showdatem();getch();flag='z';break;}file.read(reinterpret_cast<char*>(&m),sizeof(makeup));}if(flag!='z'){ cout<<("该商品已被删除!");getch();}file.close();}void removem(){ t=0;searchm();}};5. 饮料类设计(drink)class drink:public spbase{ private:char factory[10];public:void getdated(){ spbase::getdate();cout<<"\n\t\t请输入商品生产厂家:";cin>>factory;}void showdated(){ spbase::showdate();cout<<"\n\n\t\t商品生产厂家:";cout<<factory;}void addd(){ t=1;ofstream file("HYY3.txt",ios::out|ios::ate);if(!file){cout<<"文件打开失败!";getch();exit(1);}drink d;d.getdated();file.write(reinterpret_cast<char*>(&d),sizeof(drink)); file.close();}void searchd(){ char name3[10];cout<<"\n请输入饮料名称:";cin>>name3;fstream file("HYY3.txt",ios::in);if (!file){cout<<"文件打开失败!";getch();exit(1);}char flag='a';drink d;file.read(reinterpret_cast<char*>(&d),sizeof(drink)); while(!file.eof()){ if((strcmp(,name3)==0)){d.showdated();getch();flag='z';break;}file.read(reinterpret_cast<char*>(&d),sizeof(drink));}if(flag!='z'){ cout<<("该商品已被删除!");getch();}file.close();}void removed(){ t=0;searchd();}};6. 生活用品类设计(live)class live:public spbase{public:void getdatel(){ spbase::getdate();}void showdatel(){ spbase::showdate();}void addl(){ spbase::add();}void searchl(){ spbase::search();}void removel(){spbase::remove();} };四.效果及存在问题4.1 效果截屏进入主界面按任意键进入主菜单后,选择“1”,添加商品进入”添加商品品种”的自菜单,选择“3“,添加”饮料类“写入添加的商品基本信息返回上一层主菜单后,选“2”,查询商品选择“3”,查询“饮料类”输入查询的饮料名称查询到该商品,基本信息如下:返回主菜单,选“3”,删除商品选“3”,删除“饮料类”写入删除的商品名称删除后查询显示:选“4”后,退出4.2存在问题“添加商品品种”的操作还存在不完善之处,进入主菜单选了“添加商品品种”的操作,当添加完一种商品后,不能继续添加商品;必须选择“返回”操作返回到主菜单重新选择“添加商品品种”后,才能添加第二种商品,也就是说不能够连续添加。