资源描述
超市管理系统C语言课程设计
62
2020年5月29日
文档仅供参考
C语言程序设计
超
市
管
理
系
统
目 录
第一章 课程设计目的要求
1.1设计目的 .............................................3
1.2 设计要求 ..............................................3
1.3设计思路 .............................................3
第二章 课程设计任务内容
2.1课程设计题目 ..........................................3
2.2课程设计任务 ..........................................4
2.2.1 设计内容 ..........................................4
2.2.2 各组员任务 ..........................................4
第三章 详细设计说明
3.1 系统模块图.................................................4
3.1.1.......................................................4
3.1.2.......................................................5
3.2 主要函数定义 ..............................................5
3.2.1主函数 ...............................................5
3.2.2其它函数...............................................7
3.3结构体的建立和文件的使用 ...................................8
3.3.1 结构体的建立..........................................8
3.3.2文件的使用.............................................9
第四章 课程设计心得与体会.......................................10
附录·程序源代码
参考文献
第一章 课程设计目的要求
设计”超市管理系统”的主要目的是锻炼学生综合运用所学的 C 语言程序设计知识的能力,独自利用 C 语言知识编写承训解决实际问题的能力,培养同学严谨的工作态度和良好的程序设计习惯,让同学们认识到必须重视实践环节,多读程序,多编写程序,多上机实践。进一步培养结构化程序设计的思想,加深对高级语言要素和控制结构的理解。经过课程设计的训练,学生能够了解程序设计的基本开发过程,掌握编写、调试和测试 C 语言程序的基本过程,掌握程序设计的技巧的大致流程。本次程序设计主要侧重于知识的运用,把平时学到的运用到实践中去。
1.1 设计目标:
1. 熟悉c语言的编译连接和运行过程。
2. 掌握c语言的数据类型,熟悉整型、实型、字符型变量的定义方式及如何给它们赋值。
3. 掌握if语句及switch语句的运用方法及嵌套应用方法。
4. 掌握实现循环结构的三种语句while、 do-while.、for 的使用。
5. 掌握函数的定义方法和调用方法。
6. 能够采用模块化思想调试程序。
7. 指针和文件的使用,结构体的使用
1.2 设计要求:
1. 源程序要有适当的注释,使程序容易阅读。
2. 必须用结构体和文件等数据结构。
3. 程序的运行结果要求使用文件作备份。
4. 至少输出一份报表,鼓励自行增加新功能。
第二章 课程设计任务内容
2.1 课程设计题目
超市管理系统
2.2 课程设计任务
系统为超市管理系统,在此系统当中需要用到许多函数,包括系统
函数以及自定义的函数,在这个系统当中,总共分为五个模块:管理员登陆、客户信息管理、商品管理、购物结算、销售结算。
2.2.1 设计内容
本次实习中,主要用到的C语言知识有结构体、指针、文件、数组。
层层镶嵌的思路将各个模块要实现的功能环环相扣。其中,在管理员登陆后,进入的是主菜单,在这个环节当中,我们将菜单设计为函数,并将菜单函数放入一个单独的C文件中管理,实现层层进入功能。主菜单函数又分为商品管理、客户管理、购物结算、销售结算等函数的管理,在此当中,主要采用结构体定义客户信息,文件访问等。
2.2.2各组员任务
为保证设计在规定时间内完成,我们将各模块分工到个人。确保任务有质量有效率的同时锻炼团队的团结协作能力。
第三章 详细设计说明
3.1 系统模块图(未完)
添加用户
修改用户
删除用户
查询用户
进入超市管理系统主界面
销售结算
商品管理
购物结算
客户管理
3.2 主要函数定义
3.2.1主函数
主函数主要包含的是登陆界面而且设置登陆界面其中包含:
1. 登录
2. 关于我们
3. 退出系统
实现其功能主要用到如下知识:
一.其中使用了多种系统自定义的头文件以及用户自定义的头文件如下:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include ”MyParams.h”
#include ”Mymenu.h”
#include ”common.h”
#include ”CustMan.h”
#include ”Goodsman.h”
二.使用了main()函数、aboutUs()函数,login()函数和pcontinue()函数
① void main(){
char choice='3'; //存储判断的选项
do{
system("cls"); //清屏命令
printf("\n\n************欢迎进入柠檬·5超市管理系统**********\n\n");
printf("\n请您选择操作选项:\n\n");
printf("\t\t\t1. 登录 \n");
printf("\t\t\t2. 关于我们\n");
printf("\t\t\t3. 退出系统\n");
printf("\n\n*******************************************\n\n");
printf("\n 请输入您的选项(1,2,3):");
choice=getch();}
② void aboutUs(){
system("cls");
BreakLine;
printf("\t\t版权所有@湖南工学院网络1101班柠檬·5\n\n");
printf("\t\t\t柠檬·5专属,翻版必究\n\n");
printf("\t\t技术扶持 Tell:");
BreakLine;
pcontinue();}
③ int login(){
char upwd[8];
int i;
system("cls");
for(i=1;i<4;i++){
BreakLine;
printf("请输入您的8位数密码");
scanf("%s",upwd);
if(strcmp (upwd,realpassword)==0)
return 1;
printf("您好,您的密码错误,请确认后重新输入\n");
printf("您还有%d次输入机会", (3-i));}
printf("\n系统郑重提示,您不是合法用户,强制退出\n");
exit(0);}
④ 在common.c定义void pcontinue()函数实现按任意键继续功能
void pcontinue(){
printf("\t按任意键继续\n");
getch();}
三.清屏语句,Do while,宏定义等的使用
⑴清屏语句:system("cls");
⑵使用了Do While 循环实现了在进入关于我们部分时能够再次返回登陆界面。
⑶使用了宏定义。在头文件MyParam.h中定义BreakLine
#define BreakLine
printf("\n\n***************************************************\n\n")
⑷使用了switch语句进行了选择而且在语句中使用了多种函数嵌套使功能完整。
switch(choice){
case '1':
if(login()==1){
showMainMenu();
}
break;
case '2': aboutUs(); break;
case '0': printf("\n\n系统安全退出\n\n");
exit(0);
break;
⑸在输入密码部分使用了For循环,实现了在登陆三次密码不正确的情况下强制退出系统:
for(i=1;i<4;i++){
BreakLine;
printf("请输入您的8位密码:");
scanf("%s",upwd); //数组名代表数组的首地址,因此不要&
if(strcmp(upwd,realpassword)==0){
return(1); //1表示登录成功
}
printf("\n您好,您的密码错误,请确认后重新输入··\n");
printf("\n您还有第%d次输入机会",(3-i));
}
printf("\n系统郑重提示,您不是合法用户,强制退出···\n");
pcontinue();
exit(0);
3.2.2其它函数部分
void showMainMenu();
再在 void showMainMenu();其中嵌套
void showGoodsMenu();
void showCustMenu();
void showShopMenu();
void showSaleMenu();
在这些函数中也就是商品管理,客户信息管理,购物结算, 和销售结算四大功能模块。依照前面的嵌套方法一一实现她的功能。
在四大模块菜单中有
void addGoods();
void findGoodsAll();
void updateGoods();
void delGoods();
void addcust();
void delcust();
void updatecust();
void findall();
void saveAll();
void saveall();
实现了客户管理中:添加客户、查询客户、删除客户、修改客户、返回上一级
商品管理中:添加商品、查询商品、删除商品、修改商品、返回上一级
等部分的功能。
在四大模块菜单中有
void showVIP();
void Goodseffect();
void Goodssave();
void Birthdayperson();
void showMymenue();
void shopping();
实现了购物结算中:商品交易信息、返回上一级
销售预算中: 显示最具有贡献精神VIP客户排行榜
显示最具有影响力的商品排行榜
显示库存商品量排行榜
当月生日的客户 以及返回上一级等功能
3.3 结构体的建立和文件的使用
在实现添加功能时使用了结构体、指针等对现阶段我们来说较难理解的内容。
3.3.1结构体语句的使用
我们会在程序中用到如下结构体语句:
Struct date/日期
int year/年
int month/月
int day/日
Struct cust/客户信息
int no/编号
char name[20]姓名
char sex/性别
int age/年龄
struct date birthday/生日
double expenditure/花费
char tel/电话号码
Struct goods/商品信息
nt num/商品代码
char name[50]/商品名字
int sale/商品数量
float price/商品单价
int lacation/商品位置
在整个程序中我们会如下用到结构体语句,不同的结构体类型:
struct cust{
int no;
char name[20];
char sex;
int age;
struct date birthday;
double expendituer;
char tel[20];
}cust[1000];
3.3.2文件的使用
客户信息管理和商品管理都有用到文件,它于我们是重点也是难点
⑴ 定义文件
FILE*fp;
int i;
if((fp=fopen("cust.dat","wb"))==NULL){
printf("\n无法打开文件\n");
return;
}
for(i=0;i<total;i++){
fwrite(&cust[i],sizeof(struct cust),1,fp);
}
fclose(fp);
⑵ 定义函数read_message()打开文件
int read_message(){
FILE*fp;
int i=0;//记数
//打开文件
if((fp=fopen("cust.dat","rb"))==NULL){
printf("\n*****暂无任何可读消息,按任意键继续**********\n");
getch();
return 0;
} //循环读取文件中的每一条记录
(3)结合循环语句,关闭文件
while(!feof(fp)){
fread(&cust[i],sizeof(struct cust), 1, fp);
if(cust[i].no=0){
break;}
else {i++;
}
}
fclose(fp);
return i;}
第四章 程序设计心得与体会
经过为期两周的课程设计,我们不但复习了课本上所学知识,还经过查阅资料、询问老师同学学到了很多课本上没有的只是,从而启发我们:要想写好程序,在学好课本只是的同时还需要多阅读和专业有关的书记,同时还需要多动脑子,要有缜密的逻辑思维能力和综合应用能力。简而言之,我们要做到三心:编写代码要细心;检查错误要耐心;完成任务要恒心。除此,在学到知识的同时锻炼了我们的团结合作精神,也使得我们小组成员之间有更深的交流。
因此,很感谢学校和老师给我们提供这样一个机会。在锻炼自己的同时让自己养成了良好的学习习惯。我希望自己能一直带着这份心态和习惯大步向前。
参考文献
[1]武爱平 卜耀华 孙东卫. C语言程序设计[M]. 长春:吉林大学出版社。
附录
柠檬·5supermarket管理系统源代码
Source Files
1. common.c
void pcontinue();
void pcontinue(){
printf("\t按任意键继续\n");
getch();}
2. Main.c
#include <stdio.h>
#include <string.h> //字符串 <先到系统的库找,再到用户库
#include <conio.h>
#include <stdlib.h>
#include "MyParams.h"
#include "common.h"
#include "mymenu.h"
void aboutUs();
int login();
char realpassword[8]="ningmeng"; //系统的真实登录密码
void main(){
char choice='3'; //存储判断的选项
do{
system("cls"); //清屏命令
//打印出程序欢迎界面
printf("\n\n******欢迎进入柠檬·5超市管理系统***\n\n");
printf("\n请您选择操作选项:\n\n");
printf("\t\t\t1. 登录 \n");
printf("\t\t\t2. 关于我们\n");
printf("\t\t\t3. 退出系统\n");
printf("\n\n*****************\n\n"); //完成输入操作
printf("\n 请输入您的选项(1,2,3):");
choice=getch(); //getch()从键盘输入一个字符
//判断 switch(变量){ case 值1: xxx; break; default xxx;};
switch(choice){
case '1': if(login()==1){
showMymenue(); }
break;
case '2': aboutUs();
break;
case '3': printf("\n\n系统安全退出\n\n");
exit(0);
break;}
} while(1);
}
void aboutUs(){
system("cls");
BreakLine;
printf("\t\t版权所有@湖南工学院网络1101班柠檬·5\n\n");
printf("\t\t\t柠檬·5专属,翻版必究\n\n");
printf("\t\t技术扶持 Tell:");
BreakLine;
pcontinue();}
int login(){
char upwd[8];
int i;
system("cls");
for(i=1;i<4;i++){
BreakLine;
printf("请输入您的8位数密码:");
scanf("%s",upwd);
if(strcmp (upwd,realpassword)==0)
return 1;
printf("您好,您的密码错误,请确认后重新输入\n");
printf("您还有%d次输入机会", (3-i));}
printf("\n系统郑重提示,您不是合法用户,为系统安全,强制退出\n");
exit(0);}
3. mymenu.c
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include "mymenu.h"
#include "common.h"
#include "MyParams.h"
#include "CustMan.h"
#include "Goodsman.h"
void showGoodsmenue();
void showCustmenue();
void showSales();
void showSell();
void showMymenue(){
char choice='5';
while(1){
system("cls");
BreakLine;
printf("\t\t1. 商品管理\n");
printf("\t\t2. 客户管理\n");
printf("\t\t3. 购物预算\n");
printf("\t\t4. 销售预算\n");
printf("\t\t5. 退出系统\n");
BreakLine;
printf("\n\n请输入您的选择(1,2,3,4,5):");
choice=getch();
switch (choice){
case'1': showGoodsmenue(); break;
case'2': showCustmenue(); break;
case'3': showSell(); break;
case'4': showSales(); break;
case'5':printf("\n\n系统安全退出\n\n");
exit(0);
break;
default: printf("\n您的输入有误,请检查后重新输入\n");
pcontinue();}
}
}
void showGoodsmenue(){
char choice='5';
while(1){
system("cls");
BreakLine;
printf("\t\t1. 添加商品\n");
printf("\t\t2. 查询商品\n");
printf("\t\t3. 更新商品\n");
printf("\t\t4. 删除商品\n");
printf("\t\t5. 返回上一级\n");
BreakLine;
printf("\n\n请输入您的选择(1,2,3,4,5):");
choice=getch();
switch (choice){
case'1': addgoods();break;
case'2': findgoods();break;
case'3': updategoods();break;
case'4': delgoods();break;
case'5': showMymenue();break;
default: printf("\n您的输入有误,请检查后重新输入\n");
pcontinue();}
}
}
void showCustmenue(){
char choice='5';
while(1){
system("cls");
BreakLine;
printf("\t\t1. 添加客户\n");
printf("\t\t2. 查找客户\n");
printf("\t\t3. 修改客户\n");
printf("\t\t4. 删除客户\n");
printf("\t\t5. 返回上一级\n");
BreakLine;
printf("\n\n请输入您的选择(1,2,3,4,5):");
choice=getch();
switch (choice){
case'1': addcust();break;
case'2': findall();break;
case'3': updatecust();break;
case'4': delcust();break;
case'5': showMymenue();break;
default: printf("\n您的输入有误,请检查后重新输入\n");
pcontinue();}
}
}
void showSales(){
char choice='5';
while(1){
system("cls");
BreakLine;
printf("\t\t1.显示最具有贡献精神VIP客户排行榜\n");
printf("\t\t2.显示最具有影响力的商品排行榜\n");
printf("\t\t3.显示库存商品量排行榜\n");
printf("\t\t4.当月生日的客户\n");
printf("\t\t5.返回上一级\n");
BreakLine;
printf("\n\t\t请输入您的选择(1,2,3,4,5):");
choice=getch();
switch(choice){
case '1': showVIP(); break;
case '2': Goodseffect(); break;
case '3': Goodssave(); break;
case '4': Birthdayperson(); break;
case '5': showMymenue(); break;
default: printf("\n\t\t您的输入有误,请确认重新输入.\n");
pcontinue();}//调用按任意键继续
}
}
void showSell(){
char choice='2';
while(1){
system("cls");
BreakLine;
printf("\t\t1.商品交易信息\n");
printf("\t\t2.返回上一级\n");
BreakLine;
printf("\n\t\t请输入您的选择(1,2,):");
choice=getch();
switch(choice){
case '1': shopping(); break;
case '2': showMymenue(); break;
default: printf("\n\t\t您的输入有误,请确认重新输入.\n");
pcontinue();} //调用按任意键继续
}
}
4. Custman.c
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#include "MyParams.h"
#include "common.h"
#include "mymenu.h"
#include "CustMan.h"
read_message();
struct data{
int year;
int month;
int day; };
struct cust{
int no; //编号
char name[20]; //名字
double expenditure; //总花费
char tel[20]; //电话号码
struct data birthday; //生日
}cust[1000]; //最多存1000个客户信息
int total; //现在cust.dat文件中总的纪录条数
void saveAll(){
FILE*fp;
int i;
if((fp=fopen("cust.dat","wb"))==NULL){
printf("\n无法打开文件\n");
return;
}
for(i=0;i<total;i++){
fwrite(&cust[i],sizeof(struct cust),1,fp);
}
fclose(fp);
}// 获取现有文件中客户的总人数
int read_message(){
FILE*fp;
int i=0;//记数 //打开文件
if((fp=fopen("cust.dat","rb"))==NULL){
printf("\n******暂无任何可读消息,按任意键继续*****\n");
getch();
return 0;
}
while(!feof(fp)){
fread(&cust[i],sizeof(struct cust), 1, fp);
if(cust[i].no==0){
break;
}else {i++;
}
} //循环读取文件中的每一条记录
fclose(fp);
return i; //存到cust结构中
}
void addcust(){ //定义增加的
struct cust newcust;
char choice='y';
FILE *fp;
int i=0;
do{
system("cls");
BreakLine;
printf("请输入客户的编号:");
scanf("%d",&newcust.no);
printf("\n");
printf("请输入客户的名字:");
scanf("%s",newcust.name);
printf("\n");
printf("请输入客户消费:");
scanf("%lf",&newcust.expenditure);
printf("\n");
printf("请输入客户的电话号码:");
scanf("%s",newcust.tel);
printf("\n");
printf("请输入客户的生日:(格式:1999-9-9)");
scanf("%d-%d-%d",&newcust.birthday.year,&newcust.birthday.month,&newcust.birthday.day);
printf("\n");
BreakLine;
if((fp=fopen("cust.dat","ab"))==NULL){
printf("\n对不起,不能打开指定的文件\n");
return ;
}
fwrite(&newcust,sizeof(struct cust),1,fp);
fclose(fp);
printf("您还要继续输入新客户信息吗?(y/n)");
choice=getch();
}
while(choice=='y');}
void findall(){ //定义查询所有的
int i;
struct cust c;
total= read_message();
system("cls");
printf("\n***************客户信息**************\n");
printf("\n客户总数:%d\n",total);
if(total>0){
printf("\n***********显示所有客户信息*************\n");
printf("\n 编号 \t 姓名 \t消费 \t\t 电话 \t\t 生日");
for(i=0;i<total;i++){
c=cust[i];
printf("\n %d\t %s\t %lf\t %s\t %d-%d-%d\t\n",c.no,c.name,c.expenditure,c.tel,c.birthday);
printf("\n\n\n\n\n");}
}else
{printf("\n********系统中暂无任何客户信息**********");}
pcontinue();
getch();}
void updatecust(){
int i;
int toupdateno; //要更新的编号
int j;
system("cls");
total=read_message(); // 读出信息
printf("\n请输入您要更新的客户编号:");
scanf("%d",&toupdateno); //查找
for(i=0;i<total;i++){
if(toupdateno==cust[i].no){
break;}
} //i里面记录了要更新的
展开阅读全文