资源描述
实验题目:超市管理系统
一、 实验目的
1. 熟悉c语言的编译连接和运行过程。
2. 掌握c语言的数据类型,熟悉整型、实型、字符型变量的定义方式及如何给它们赋值。
3. 掌握if语句及switch语句的运用方法及嵌套应用方法。
4. 掌握实现循环结构的三种语句while、 do-while.、for 的使用。
5. 掌握函数的定义方法和调用方法。
6. 能够采用模块化思想调试程序。
二.实验内容
1. 编写程序并进行调试运行。
2. 输入商品资料,并保存于文件。每件商品包含信息如:商品号、商品名、商品类别、商品总量、商品上限和下限、商品价格、进货日期、生产日期、保质期等。
3. 对已存入的商品信息进行更新操作,包括添加一件商品信息、删除某件商品信息和修改商品信息。
4. 通过按商品名、商品种类、商品进货量的方式查询商品信息。
5.输入某商品号后对其利润进行统计、对进货价格相同的商品进行统计。
6 对商品的库存量和利润进行排序。
7.最后输出商品信息,供需要时打印。
二、 需求分析
1. 该程序可用于对商品的基本信息的存储、更新、查询、输出、统计、排序等操作,以实现管理者对商品的管理和消费者对商品的了解。
2. 其中更新功能包括:添加信息、删除信息、修改信息、可根据需要添加一个或多件商品信息,也可对个别商品信息进行适当的删除或修改。以便随时更新商品信息。
3. 程序中设计的查询功能可根据需要从若干数据中查询某件商品信息,并且可根据三种不同的方法查询:按商品名查询、按商品种类查询和按商品进货量查询。以满足不同的需要。
四、概要设计
1、方案设计
对系统进行分析,给出结构图
分析:系统要求实现许多的功能,因此遵循结构化程序设计思想来进行本系统的设计—自顶向下、逐步细化,将系统设计任务分解出许多子功能模块进行设计
结构图如下:
超市管理管理系统
退出系统
消费者管理系统
管理者系统
统计模块
排序模块
查询模块
退出系统
利润排行
退出系统
录入信息
退
出
系
统
添加商品信息
按进货量查询
按商品种类查
按商品名查询
退出系统
查询模块
排序模块询模块
退出系统
输出信息
更新模块
退出系统
第一类商品
第二类商品
按商品名查询
按进货量查询
退出系统
按商品
种类
查
寻
利润排行
库存量排行
退出系统
第三类商品
修改商品信息
删除商品信息
库存量排行
2.功能模块说明:
对各个模块进行功能的描述
(1).输入模块:
录入需要管理的商品信息并将信息保存于文件中,以方便日后进行打印、读取、更新等操作。
(2).添加模块:
可添加一件或多件商品信息,并将所添加商品信息保存,方便查找。
(3).删除模块:
可对过期的商品做删除处理。
(4).修改模块:
可根据需要对多件商品信息进行修改,也可随时对个别项进行修改。
(5).查询模块:
可对已建立的商品信息进行查询,并且可根据需要选择按商品名查询或按商品种类查询或按商品进货量查询。
(6).保存模块:
用于对信息进行保存。
(7).输出模块:
将所有商品信息或想要查询的商品信息显示于屏幕,用于打印商品信息或查找某些商品信息。
(8) 排序模块:
根据商品的利润和进货量进行排序。
(9) 统计模块:
统计商品的利润和对进货价格相同的商品进行统计。
(10).退出系统:
选择该项,自动退出该系统。
五、详细设计及运行结果
流程图, 函数之间相互调用的图示 ,程序设计及编码, 运行结果。
开 始
输入i值
判断i值
退出系统
消费者系统
管理者系统
退出系统
排序模块
查询模块
输入模块
查询模块
统计模块
排序模块
更新模块
输出模块
退出系统
输入统计值
输入查询
值
输入排序值
输入更新值
输入查询
值
输入排序值
退出系统
添加信息
删除信息
修改信息
退出系统
利润排序
库存排序
退出系统
一类商品
二类商品
三类商品
退出系统
按名查询
按种类查
按进货量
库存排序
利润排序
退出系统
按种类查
按名查询
按进货量
退出系统
六. 调试情况及运行结果
1、 对自己设计进行评价,指出合理和不足之处,提出改进的方案。
此次实践课编写的是一个应用程序,相对于以前我们见到的程序,它要大得多,于是就按课本上的例子编了超市管理系统,先把界面弄好然后再添加各模块,而且各模块也出现了不少问题,在同学们和老师的帮助下,我很有耐心的一次又一次的进行修改,最后运行的结果基本上达到了预期的目的。可结果还不是太理想。
由于时间很短,在选题报告中设想到的好多功能都没有实现。已有的那些功能虽已能基本上满足管理者和消费者的需要,但如果还有更多的功能程序就会更加完美。如:进入系统时没有设制密码,保护性不够强;在输入商品号时没有出错提示,如果商品号输入负值
2、在设计过程中的感受。
本次C 语言的实习课让我对C 语言的学习又有了更深入的了解,也让我更深刻地领悟到了“实践出真理”这个道理,在上机实践过程中学到的知识远远超过了在课堂上十几周学到的,学校组织的这次实习让我们这些实践知识匮乏的大学生增添了许多社会经验,为我们将来走上工作岗位其了不小的铺垫作用。
本次实习中遇到了很多以前没有遇到过的问题,也曾想过要放弃,但看到那些同学都在那认真的写程序,给了我继续的信心。在同学的帮助下,我顺利的结束了本次实习,让我知道原来凭借自己努力取得的成功会让自己这么欣慰,也让我知道了友谊和团结的重要性。
七.参考文献
《C语言程序设计》 王曙燕 曹锰 科学出版社
八。附录:
#include <stdio.h>
#include <string.h>
#define MAX 3
#define N 3
#define PAGE 2
#define PRINTF1 printf("---------------------------------------------------------------------\n")
#define PRINTF2 printf("num----name----kind----out_price----pro_time(year-month-day)----save_time\n");
#define PRINTF3 printf("%d%8s %7s %8d %5d-%2d-%2d %10d\n",goods[i].num,goods[i].name,goods[i].kind,goods[i].out_price,goods[i].pro_time.year,goods[i].pro_time.month,goods[i].pro_time.day,goods[i].save_day);
int sum;
/*data struct kind*/
struct data
{
int year;
int month;
int day;
};
/*goods struct kind*/
struct goods
{
int num;
char name[10];
char kind[10];
int amount;
int goods_up;
int goods_down;
int in_price;
int out_price;
int in_num;
struct data in_time;
struct data pro_time;
char factory[10];
int save_day;
float profit;
}goods[MAX];
/*save message*/
save_message(int sum)
{
FILE *fp;
int i;
if((fp=fopen("goods.txt","wb"))==NULL)
{
printf("read the file error!\n");
return;
}
for(i=0;i<sum;i++)
if(fwrite(&goods[i],sizeof(struct goods),1,fp)!=1)
printf("write the file error!\n");
fclose(fp);
}
/*input message*/
input_message()
{
int i=0,s=MAX;
system("cls");
printf("\n\n input goods message the most%d\n\n",s);
do
{
printf("\n di%dgoods",i+1);
printf("\n num:");
scanf("%d",&goods[i].num);
if(goods[i].num==0)
break;
printf("\n name:");
scanf("%s",goods[i].name);
printf("\n kind:");
scanf("%s",goods[i].kind);
printf("\n amount:");
scanf("%d",&goods[i].amount);
printf("\n goods_up:");
scanf("%d",&goods[i].goods_up);
printf("\n goods_down:");
scanf("%d",&goods[i].goods_down);
printf("\n in_price:");
scanf("%d",&goods[i].in_price);
printf("\n out_price:");
fflush(stdin);
scanf("%d",&goods[i].out_price);
printf("\n in_num:");
scanf("%d",&goods[i].in_num);
printf("\n in_time:");
scanf("%d-%d-%d",&goods[i].in_time.year,&goods[i].in_time.month,
&goods[i].in_time.day);
printf("\n pro_time:");
scanf("%d-%d-%d",&goods[i].pro_time.year,&goods[i].pro_time.month,
&goods[i].pro_time.day);
printf("\n factory:");
scanf("%s",goods[i].factory);
printf("\n save_time:");
scanf("%d",&goods[i].save_day);
i++;
}while(i<MAX);
printf("\n***** %d goods message input over!--\n",i);
sum=i;
printf("\n press any key to return!");
bioskey(0) ;
}
/*read message*/
int read_message()
{
FILE *fp;
int i=0;
if((fp=fopen("goods.txt","rb"))==NULL)
{
printf("\n\n ******there is no any message,press any key to return !******\n");
return;
}
while(feof(fp)!=1)
{
fread(&goods[i],sizeof(struct goods),1,fp);
if(goods[i].num==0)
break;
else
i++;
}
fclose(fp);
return(i);
}
/*output message*/
output_message()
{
int i=0,j=0,count,page=1;
system("cls");
printf("\n\n --goods message,di %d page\n\n",page);
PRINTF2;
PRINTF1;
do
{
if(goods[i].num!=0)
{
j++;
if(j%PAGE!=0)
{
PRINTF3;
PRINTF1;
}
else
{
PRINTF3;
PRINTF1;
if(goods[i+1].num!=0)
{
printf("press any key to return!");
getch();
system("cls");
printf("\n\n --goods message,di%d page\n\n",++page);
PRINTF2;
PRINTF1;
}
}
}
i++;
} while(i<sum);
printf("press any key return!");
bioskey(0);
}
/*insert goods message*/
insert_message()
{
int i=sum,j,flag=0;
char choice;
system("cls");
printf("\n\n insert a new goods\n");
printf(" ----------------------\n");
do
{
goods[i].num=++sum;
printf("\n new num:");
scanf("%d",&goods[i].num);
printf("\n new name:");
scanf("%s",goods[i].name);
printf("\n new kind:");
scanf("%s",goods[i].kind);
printf("\n new amount:");
scanf("%d",&goods[i].amount);
printf("\n new goods_up: ");
scanf("%d",&goods[i].goods_up);
printf("\n new goods_down:");
scanf("%d",&goods[i].goods_down);
printf("\n new in_price: ");
scanf("%d",&goods[i].in_price);
printf("\n new out_price:");
scanf("%d",&goods[i].out_price);
printf("\n new in_num:");
scanf("%d",&goods[i].in_num);
printf("\n new in_time:");
scanf("%d-%d-%d",&goods[i].in_time.year,
&goods[i].in_time.month,
&goods[i].in_time.day);
printf("\n new pro_time:");
scanf("%d-%d-%d",&goods[i].pro_time.year,
&goods[i].pro_time.month,
&goods[i].pro_time.day);
printf("\n new factory: ");
scanf("%s",goods[i].factory);
printf("\n new save_time: ");
scanf("%d",&goods[i].save_day);
printf("\n go on or not?(Y/N)");
choice=getch();
if(choice=='Y'||choice=='y')
{
printf("\n go on!\n");
i++;
flag=1;
}
else flag=0;
}while(flag==1);
printf("\n press any key return!");
bioskey(0);
}
/*renew goods message*/
renew_message()
{
int choice;
do
{ system("cls");
printf("\n\n\n *******renew goods message*******\n\n");
printf(" 1: insert goods message\n\n");
printf(" 2: del goods message\n\n");
printf(" 3: revise goods message\n\n");
printf(" 0: return\n\n ");
printf(" please choose(0-3):");
scanf("%d",&choice);
switch(choice)
{
case 1: insert_message();
break;
case 2: del_message();
break;
case 3: revise_message();
break;
case 0: break;
}
}while(choice!=0);
}
/*del goods message*/
del_message()
{
int i=0,del_num,flag,k;
char choice,choice1;
do
{
system("cls");
printf("\n --please input the del goods num:--\n");
scanf("%d",&del_num);
printf("\n --really del the goods?(Y/N)");
choice1=getch();
if(choice1=='Y'||choice1=='y')
printf("\n --continue!--\n");
for(i=0;i<sum;i++)
if(goods[i].num==del_num)
{
printf("\n --goods message--\n");
PRINTF1;
PRINTF2;
PRINTF3;
for(k=i;k<sum-1;k++)
goods[k]=goods[k+1];sum--;
printf("\n --after delete--\n");
PRINTF1;
PRINTF2;
PRINTF3;
break;
}
if(i==sum)
{
printf("\n --the goods is not exist!--\n");
getch();
}
printf("\n\n --go on or not?Y/N--\n");
choice=getch();
if(choice=='Y'||choice=='y')
{
flag=1;
printf("\n --go on--\n");
}
else flag=0;
}while(flag==1);
printf("\n --press any key return--\n");
bioskey(0);
}
/*revise goods message*/
revise_message()
{
int i=0,choice,revise_num,flag;
char choice1;
do
{
system("cls");
printf("\n please input the revise goods num:");
scanf("%d",&revise_num);
for(i=0;i<sum;)
{if(goods[i].num==revise_num)
{
printf("\n ----goods message---- \n");
PRINTF1;
PRINTF2;
PRINTF3;
printf("\n which item you want to revise?\n ");
printf("\n 1: name\n");
printf("\n 2: kind\n");
printf("\n 3: out_price\n");
printf("\n 4: pro_time\n");
printf("\n 5: save_day\n");
printf("\n please choose(1-5)");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\n after revise num: ");
scanf("%s",goods[i].name);
break;
case 2: printf("\n after revise kind: ");
scanf("%s",goods[i].kind);
break;
case 3: printf("\n after revise out_price:");
scanf("%d",&goods[i].out_price);
break;
case 4: printf("\n after revise pro_time:");
scanf("%d-%d-%d",&goods[i].pro_time.year,
&goods[i].pro_time.month,
&goods[i].pro_time.day);
break;
case 5: printf("\n after revise save_time:");
scanf("%d",&goods[i].save_day);
break;
}
PRINTF1;
PRINTF2;
PRINTF3;
break;
}
else i++;}
if(i==sum)
{
printf("\n this goods is not exist!");
getch();
}
printf("\n\n continue revise?(Y/N)");
choice1=getch();
if(choice1=='Y'||choice1=='y')
{
flag=1;
printf("\n continue!\n");
}
else flag=0;
}while(flag==1);
printf("\n press any key return\n");
bioskey(0);
}
/*inquire goods message*/
inquire_message()
{
int choice;
do
{
system("cls");
printf("\n\n **********inquire goods message***********\n\n");
printf(" 1: inquire goods according to name \n\n");
printf(" 2: inquire goods according to kind\n\n") ;
printf(" 3: inquire goods according to in_num\n\n");
printf(" 0: return\n\n");
printf(" please choose (0-3): ");
scanf("%d",&choice);
switch(choice)
{
case 1: inquire_name();
break;
case 2: inquire_kind();
break;
case 3: inquire_count();
break;
case 0: break;
}
}while(choice!=0);
}
/*inquire according to name*/
inquire_name()
{
int i,choice,j=0,inquire_in_price;
char inquire_name[10];
system("cls");
printf("\n input the inquire goods name:");
scanf("%s",inquire_name);
for(i=0;i<sum;i++)
{
if(strcmp(goods[i].name,inquire_name)==0&&goods[i].num!=0)
{
printf("\n --goods message-- \n");
PRINTF1;
PRINTF2;
PRINTF3;
}
else j++;
if(j==sum)
printf("\n the good is not exist!");
bioskey(0);
}
}
/* inquire accordingto kind */
inquire_kind()
{int i,j=0;
char inquire_kind[10];
clrscr();
printf("\n please input the inquire goods kind:");
scanf("%s",inquire_kind);
for(i=0;i<sum;i++)
if(strcmp(goods[i].kind,inquire_kind)==0&&goods[i].num!=0)
{printf("\n ----goods message---- \n");
PRINTF1;
PRINTF2;
PRINTF3;}
else j++;
if(j==sum) printf("\n this goods is not exist!");
bioskey(0);
}
/*inquire according to in_num*/
inquire_count()
{int i,inquire_count,j=0;
clrscr();
printf("\n please input the inquire in_num:");
scanf("%d",&inquire_count);
for(i=0;i<sum;i++)
if(strcmp(goods[i].in_num,inquire_count)==0&&goods[i].num!=0)
{printf("\n ----goods message----");
PRINTF1;
PRINTF2;
PRINTF3;}
else j++;
if(j==sum) printf("\n this goods is not exist!");
bioskey(0);
}
/*count goods message*/
count_message()
{
int choice;
do
{
sy
展开阅读全文