1、 c语言超市管理系统报告书C语言课程设计 65 2020年5月29日 文档仅供参考 课 程 设 计 课程设计名称: 高级语言程序设计 专 业 班 级 : 计算机科学与技术0802班 学 生 姓 名 : 李旭 学 号 : 48140202 指 导 教 师 : 范艳峰 课程设计时间: 7月2号 计算机科学
2、与技术 专业课程设计任务书
学生姓名
李旭
专业班级
计科0802
学号
题 目
超市管理系统
课题性质
其它
课题来源
自拟课题
指导教师
范艳峰
同组姓名
无
主要内容
用
3、n();
5) 系统颜色设置———yanseshezhi();
6) 应用程序退出———Jieshu();
任务要求
1) 每条信息至包含 :编号(id)物品名称(name)物品产地(produce)物品数量(number)物品单价(prize)
2) 作为一个完整的系统,应具有友好的界面和较强的容错能
3) 上机能正常运行,并写出课程设计报告
参考文献
4、超市这种便利的服务开始走进我们的生活,同时随着超市涌入我们的生活,如何更便利的对超市进行系统和有序的操作,成为了我们需要考虑的问题,本程序运用C语言程序设计了一个超市管理系统。关系系统的的功能主要有新购物品入库、物品信息删除、物品信息修改、物品信息查询、物品信息浏览功能,在相应的硬盘上面进行存盘以防止部分数据的丢失。为了更加人性化使用此管理系统,还在MENU选项总添加了系统颜色设置功能,使用户能够根据自己的喜好修改操作界面。 2 概要设计 (1)数据结构 依据给定的物品信息和数据形式,数组必须用结构体实现。结构类型的层次结构: struct ima { int id;
5、 char name[20]; char produce[30]; int number; float price; }; (2)模块划分 依据程序的结构反和功能,遵照”自顶而下”的原则,描述该程序的层次结构图一显示了该程序的层次结构,共 5层: 如下图: Main函数 程序主菜单 1 新购物品入库 2 物品信息删除 3 物品信息修改 4 物品信息浏览 5 系统颜色设置 1 红底黑字 2 白底黑字 3 黑底红字 4 绿底蓝字 5 黄底紫字 6 系统默认 4 物品信息查询 4
6、 应用程序退出 判断所输编号是否存在 是:此编号已被使用,请重新输入 否: 输入物品信息 图一 图一的层次结构 (3)原函数清单: 1、 创立函数 void chushihua() 2、 增加物品函数 Tianjia(); 3、删除物品信息函数 Shanchu(); 4、修改物品信息函数 Xiugai(); 5、查询物品信息函数 Chazhao(); 6、浏览物品信息函数 Liulan(); 7、系统颜色设置函数 yanseshezhi(); 8、应用程序退出函数 Jieshu(); 3
7、运行环境: Win , WinXP, Win , NT, WinME, Win9X 4 开发工具和编程语言: 编程语言:C语言 开发工具:microsoft visual C++ 6.0 5 详细设计: 1、结构体变量的定义: struct ima { int id; char name[20]; char produce[30]; int number; float price; }; 3、 文件的初始化: void chushihua() { FILE *fp; struct ima i={1,"花生牛奶","湖北武汉",1200,2.
8、5}; fp=fopen("ima.dat","w"); if(fp==NULL) { printf("\t\t\t系统错误,请重试........"); exit(0); } fwrite(&i,sizeof(struct ima),1,fp); fclose(fp); } 4、 欢迎菜单(主函数): void main() { printf("\n\n"); system("color 1a"); printf("\t\3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \
9、3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3\n"); printf("\t\3 \3\n"); printf("\t\3 \3\n"); printf("\t\3 欢迎使用 \3\n");
10、 printf("\t\3 \3\n"); printf("\t\3 \3\n"); printf("\t\3 超市库存管理系统 \3\n"); printf("\t\3 按任意键继续
11、 \3\n"); printf("\t\3 \3\n"); printf("\t\3 \3\n"); printf("\t\3 \3\n"); printf("\t\3
12、 \3\n"); printf("\t\3 \3\n"); printf("\t\3 \3\n"); printf("\t\3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \
13、3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3"); getch(); system("cls"); menu(); chushihua(); menu(); } 5、 选择菜单 void menu() { int choice; printf("\n∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞【超市库存管理系统】∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞\n"); printf("--------------------------------系统菜单显示如下--------------------------------");
14、 printf("\n\t①=====================【 新购物品入库 】\n"); printf("\n\t②=====================【 物品信息删除 】\n"); printf("\n\t③=====================【 物品信息修改 】\n"); printf("\n\t④=====================【 物品信息查询 】\n"); printf("\n\t⑤=====
15、 物品信息浏览 】\n"); printf("\n\t⑥=====================【 系统颜色设置 】\n"); printf("\n\t⑦=====================【 应用程序退出 】\n"); printf("\n\t请输入您要选择的菜单......"); scanf("%d",&choice); switch(choice) { case 1: Tianjia(); break
16、 case 2: Shanchu(); break; case 3: Xiugai(); break; case 4: Chazhao(); break; case 5: Liulan(); break; case 6: yanseshezhi(); break; case 7: Jieshu(); break; default: printf("\n\t\t\t\t\t输入无效,请您重新输入......"); getch(); system("cls"); menu(
17、); } } 6、 新购物品入库函数: int panduanID(int id) /*判断所输编号是否已存在*/ { FILE *fp; struct ima i; fp=fopen("ima.date","r"); if(fp==NULL) { printf("\t\t\t系统错误,请您重试........"); exit(0); } fread(&i,sizeof(struct ima),1,fp); while(!feof(fp)) { if(i.id==id) { fclose(fp)
18、 return 1; break; } fread(&i,sizeof(struct ima),1,fp); } fclose(fp); return 0; } void Tianjia() { struct ima i; char choice; FILE *fp; fp=fopen("ima.date","ab"); if(fp==NULL) { printf("\t\t\t系统错误,请您重试........"); exit(0); } labID: printf("\n\t请您输入要入库
19、物品的信息...\n"); printf("\t\t\t\t 物品的编号:"); scanf("%d",&i.id); if(panduanID(i.id)==1) { printf("\t\t\t\t此编号已被使用,请您重新输入......"); goto labID; } printf("\t\t\t\t 物品的名称:"); scanf("%s",i.name); printf("\t\t\t\t 物品的生产地:"); scanf("%s",i.produce); printf("\t\t\t\t 物品的数量:");
20、scanf("%d",&i.number); printf("\t\t\t\t 物品的单价:"); scanf("%f",&i.price); fwrite(&i,sizeof(struct ima),1,fp); fclose(fp); printf("\t\t\t\t\t\t 物品信息已入库成功!!!\n"); printf("\n您想继续吗?(y/n)"); scanf(" %c",&choice); if(choice=='Y'||choice=='y') { Tianjia(); } else { system(
21、"cls"); menu(); } } 7、 物品信息删除函数: void Shanchu() { struct ima i[1000]; struct ima temp; int delID; char choice; int index=0; int j=0; FILE *fp; fp=fopen("ima.date","r"); if(fp==NULL) { printf("\t\t\t系统错误,请您重试........"); exit(0); } fread(&temp,sizeof(s
22、truct ima),1,fp); while(!feof(fp)) { i[index]=temp; index++; fread(&temp,sizeof(struct ima),1,fp); } fclose(fp); printf("\n\t请输入要删除的物品的编号:"); scanf("%d",&delID); fopen("f:\\ima.date","w"); if(fp==NULL) { printf("\t\t\t系统错误,请您重试........"); exit(0); } for( j=0;j
23、 24、}
8、 物品信息修改函数:
void Xiugai()
{ int index=0;
int ID,j;
char choice;
struct ima i[1000];
struct ima temp;
FILE *fp;
fp=fopen("ima.dat","r");
if(fp==NULL)
{
printf("\t\t\t系统错误,请您重试........");
exit(0);
}
fread(&temp,sizeof(struct ima),1,fp);
while(!fe 25、of(fp))
{
i[index]=temp;
index++;
fread(&temp,sizeof(struct ima),1,fp);
}
fclose(fp);
fp=fopen("ima.dat","w");
if(fp==NULL)
{
printf("\\t\t\t系统错误,请您重试........");
exit(0);
}
printf("\n\t请输入要修改的信息的物品的编号:");
scanf("%d",&ID);
for(j=0;j<=index-1;j++)
{
if(i[j].i 26、d!=ID)
{
fwrite(&i[j],sizeof(struct ima),1,fp);
}
else
{
printf("\t\t物品名称修改为:");
scanf("%s",i[j].name);
printf("\t\t物品生产地修改为:");
scanf("%s",i[j].produce);
printf("\t\t物品数量修改为:");
scanf("%d",&i[j].number);
printf("\t\t物品单价修改为:");
scanf("%f",&i[j].price) 27、
}
}
fclose(fp);
printf("\t\t\t\t物品信息已修改......");
printf("\n您想继续吗?(y/n)");
scanf(" %c",&choice);
if(choice=='Y'||choice=='y')
{
Xiugai();
}
else
{
system("cls");
menu();
}
}
9、 物品信息查询函数:
void Chazhao()
{
FILE *fp;
int findID;char choice;struct im 28、a i;
fp=fopen("ima.date","r");
if(fp==NULL)
{
printf("\t\t\t系统错误,请你重试........");
exit(0);
}
finID:
printf("\n\t请输入要查询的物品的编号..");
scanf("%d",&findID);
fread(&i,sizeof(struct ima),1,fp);
while(!feof(fp))
{
if(i.id==findID)
{
printf("\n\n\t***************物 29、品信息******************");
printf("\n\t物品编号...%30d\n",i.id);
printf("\n\t-----------------------------------------");
printf("\n\t物品名称...%30s\n",i.name);
printf("\n\t-----------------------------------------");
printf("\n\t生产厂家...%30s\n",i.produce);
printf("\n\t---------------- 30、");
printf("\n\t进口数量...%30d\n",i.number);
printf("\n\t-----------------------------------------");
printf("\n\t批发价格...%30.3f\n",i.price);
printf("\n\t-----------------------------------------");
printf("\n您想继续吗?(y/n)");
scanf(" %c",&choice);
if(ch 31、oice=='Y'||choice=='y')
{
Chazhao();
}
else
{
system("cls");
menu();
}
}
fread(&i,sizeof(struct ima),1,fp);
}
fclose(fp);
printf("\t\t\t\t\t输入的编号不存在,请您重新输入......");
goto finID;
}
10、 物品信息浏览函数:
void Liulan()
{ struct ima i;
int index=0; 32、
char choice;
FILE *fp;
fp=fopen("ima.date","r");
if(fp==NULL)
{
printf("\t\t\t系统错误,请你重试........");
exit(0);
}
fread(&i,sizeof(struct ima),1,fp);
while(!feof(fp))
{
index++;
printf("\n\n\t****************物品信息%d*****************",index);
printf("\n\t物品编号...%30 33、d\n",i.id);
printf("\n\t-----------------------------------------");
printf("\n\t物品名称...%30s\n",i.name);
printf("\n\t-----------------------------------------");
printf("\n\t生产厂家...%30s\n",i.produce);
printf("\n\t-----------------------------------------");
printf("\n\t进口数量...%30d\ 34、n",i.number);
printf("\n\t-----------------------------------------");
printf("\n\t批发价格...%30.3f\n",i.price);
printf("\n\t-----------------------------------------");
getch();
fread(&i,sizeof(struct ima),1,fp);
}
fclose(fp);
printf("\n您想继续吗?(y/n)");
scanf(" %c",&choice);
35、if(choice=='Y'||choice=='y')
{
Liulan();
}
else
{
system("cls");
menu();
}
}
11、 系统颜色设置函数:
void yanseshezhi()
{ int a;
char choice;
system("cls");
printf("\n\n\t\t选择以下方案\n");
printf("\n\n\t\t1**************红底黑字\n");
printf("\n\n\t\t2**************白底黑字\n");
prin 36、tf("\n\n\t\t3**************黑底红字\n");
printf("\n\n\t\t4**************绿底蓝字\n");
printf("\n\n\t\t5**************黄底紫字\n");
printf("\n\n\t\t6**************系统默认\n");
printf("\n\n\t\t\t\t\t请挑选您喜爱的颜色<1-5>......");
scanf("%d",&a);
switch(a)
{
case 1:
system("color 40");
break;
37、
case 2:
system("color 70");
break;
case 3:
system("color 04");
break;
case 4:
system("color 21");
break;
case 5:
system("color 65");
break;
case 6:
system("color 1a");
break;
default:
printf("\n\n\t\t\t\t\t输入无效,重新输入......");
getch();
38、 yanseshezhi();
}
printf("\n选择的颜色您还满意吗?(y返回主菜单/n继续选择)");
scanf(" %c",&choice);
if(choice=='Y'||choice=='y')
{
system("cls");
menu();
}
else
{
yanseshezhi();
}
}
12、 应用程序退出函数:
void Jieshu()
{char choice;
system("cls");
printf("\n\n\n\n\n\n\n\t\t\t您确定要退 39、出系统吗?\n\n\n\t\t\t如果您想退出请按'y',其它键将返回主菜单.....");
scanf(" %c",&choice);
if(choice=='Y'||choice=='y')
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t谢谢您的使用!!!");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
}
else
{
system("cls");
menu();
}
}
6 调试分析:
在此程序的编程前,我上网搜集 40、了一些关于超市管理系统的资料,然后大致决定了编程的大致算法,即利用函数贯穿整个程序,经过SWITCH函数进行各个函数的选择;同时,进过查阅,我添加了系统颜色设置功能,同是应用了清屏函数,课下讲程序大致写好后,我上机进行了调试;但却出现了80几处错误,大都是提示 miss ”;” before tybe;经过分析,程序算法并无错误;后来询问老师,才发现原来在我所编的程序中,有需要变量时,都是用的时候才定义,但正确的方法是应该在函数的开头就应该将所要用的变量进行生命,否则就出现了编译错误。
7测试结果:
1、欢迎界面
2、系统选择界面:
3、新购物品入库:
4、物品信息删除:
41、
5、物品信息修改:
6、物品信息查询
7、物品信息浏览:
8、系统颜色设置:
9、应用程序退出:
8 参考文献:
1. 42、着书上的例题去理解,去套用!才能略有小成的把结构体链表版的程序做出来,当然缺陷百出!怎么讲呢?总觉得时间过的很快!一眨眼的工夫,就已经结束了,每天要消化的东西很多!
为期一周的C语言课程设计结束了,经过这一个星期的课设,使我对C语言有了更深入、更全面的了解,同时也发现自己的英文和函数基础不是很好,对很多地方不是特别懂,甚至对有些概念都还很模糊,但经过这次课程设计,使我对C语言有了新的认识,在这一周的时间里,经过不断的与同学之间进行探讨以及老师的指导,使我的C语言水平有了很大程度的提高。
经过课设我还发现C语言是一门非常实用的学科,像我的题目----书店图书销售系统,是与实际生活紧密相关 43、的,在以后的工作当中都有可能会用的到。
平常在书上学的这些知识在我看来是些最基本的知识!其实C语言应该还包括很多,但就这些基本的知识我们学起来还是很辛苦的,我个人认为C语言的语句块中无非是3个东西,顺序,判断与循环,在一个多星期的代码打下来,编写的语句块中没发现过超出这3种东西的,就算调用的函数,在函数里面还是这3个东西,能够说是极其简单,但就这3种东西拼凑在一起时,就能发挥强大的功能与作用。可谓三个臭皮匠顶个诸葛亮!一般在没有多数的嵌套下还是能很清晰明了的读写代码,可一旦嵌套一多,就开始晕晕眩眩了。
函数的话,我的理解比较浅,我只能说它的作用除了被人调来调去之外,没有别的功能了!当然 44、使用函数会是程序别的清晰明了,这点在编写超市管理系统时也体会到了!,
我认为还有比较重要的是算法,虽然算法并不是代码,但算法能让我们更好的去编写代码,有了算法程序才有灵魂,这是书上说的…….个人认为这是个比喻~算法是事物解决的方法,不但仅编程我们生活中也经常见到算法,只是自身没发现而已!当我们的算法到达到一种境界时,我们的思维就会变的灵活,思路就会变的清晰!当然我也没到这种境界,正在努力中……
这次课设使我对C语言产生了极大的兴趣,相信经过我以后的学习,我的C语言水平一定会有很大的提高。
源程序:
#include 45、clude 46、uct ima i={1,"花生牛奶","湖北武汉",1200,2.5};
fp=fopen("ima.dat恶","w");
if(fp==NULL)
{
printf("\t\t\t系统错误,请重试........");
exit(0);
}
fwrite(&i,sizeof(struct ima),1,fp);
fclose(fp);
}
void menu()
{
int choice;
printf("\n∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞【超市库存管理系统】∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞\n");
printf("------- 47、系统菜单显示如下--------------------------------");
printf("\n\t①=====================【 新购物品入库 】\n");
printf("\n\t②=====================【 物品信息删除 】\n");
printf("\n\t③=====================【 物品信息修改 】\n");
printf("\n\t④====== 48、 物品信息查询 】\n");
printf("\n\t⑤=====================【 物品信息浏览 】\n");
printf("\n\t⑥=====================【 系统颜色设置 】\n");
printf("\n\t⑦=====================【 应用程序退出 】\n");
printf("\n\t请输入您要选择的菜单......");
scanf 49、"%d",&choice);
switch(choice)
{
case 1:
Append();
break;
case 2:
Selldelete();
break;
case 3:
Amend();
break;
case 4:
Findin();
break;
case 5:
Browse();
break;
case 6:
colorsetting();
break;
case 7:
Endprogram();
break;
default:
print 50、f("\n\t\t\t\t\t输入无效,请您重新输入......");
getch();
system("cls");
menu();
}
}
void colorsetting()
{ int a;
char choice;
system("cls");
printf("\n\n\t\t选择以下方案\n");
printf("\n\n\t\t1**************红底黑字\n");
printf("\n\n\t\t2**************白底黑字\n");
printf("\n\n\t\t3**************黑底红
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4009-655-100 投诉/维权电话:18658249818