资源描述
西安邮电大学
高级语言课程设计报告
题 目: 超市管理系统
院系名称: 理学院
专业名称: 应用物理学
班 级: 1301
学生姓名: 王松
学号(8位): 07132022
指导教师: 王西龙
设计起止时间:2014年06月19日~2014年06月27日
1:程序模型
2:原函数概况
1:创建函数
void start(); /*启动界面*/
void input(); /*商品数据信息输入函数*/
void change(); /*商品数据信息修改函数*/
void dele(); /*给定指定商品名称,删除商品信息*/
void output(); /*商品信息输出*/
void search(); /*商品信息查找*/
void mima();/*密码程序*/
void colour();//颜色选择
void huanying();
2:商品信息录入
input()
3:商品信息的修改
Change()
4:商品信息的删除
Dele()
5:商品信息的查询
Seaerch()
6:系统颜色选择
Colour()
7:退出系统
3:详细设计过程
1:结构体变量的定义
struct MarketGoods /*存数商品信息的结构体*/
{
char goods_id[30]; /*商品编号*/
char goods_name[30]; /*商品名称*/
double goods_price; /*商品价格*/
double goods_discount;/*商品折扣*/
int goods_amount;/*商品总数目*/
int goods_remain;/*商品剩余数目*/
}goods[COUNT];
int count=0; /*全局变量,用于保存实际上有多少个商品*/
2:欢迎界面
void huanying()
{
printf("\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\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");
printf("\t\3 超市管理系统 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \4\4\4\4\4\4 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \5\5\5\5\5\5\5\5\5 \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\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
}
3:密码登陆
void mima()
{
// char pass[6]={'1','2','3','4','5','6'};/*假设密码长度是6*/
char pass[]={"123456"};/*假设密码长度是6*/
char str[6],ch;
int i=0;
int flag=0;
printf(" 请输入密码:");
fflush(stdin);
for(i=0;i<6;i++)
{
ch=getch(); /*读取字符,不显示*/
str[i]=ch;
putchar('*');
}
for(i=0;i<6;i++)
{
if(str[i]!=pass[i])
{
flag=1;
break;
}
}
if(flag)
{
printf("\n密码错误,登录失败!请重新登录\n");
mima();
}
else printf("\n登录成功\n");
getch();
system("cls");
start();
}
4:系统选择界面
void start() /*启动菜单*/
{
int chi;
printf(" 超市商品管理系统\n");
printf(" ********************************************\n");
printf(" ********************************************\n");
printf(" 1.商品信息的录入:\n");
printf(" 2.商品信息的修改:\n");
printf(" 3.删除某个商品信息:\n");
printf(" 4.查找商品信息:\n");
printf(" 5.颜色选择:\n");
printf(" 0.退出程序\n");
printf(" ********************************************\n");
printf(" ********************************************\n");
printf(" 输入你的选择: ");
scanf("%d",&chi); /*根据你的选择执行相应的函数*/
if(chi==1) input();
else
if(chi==2) change();
else if(chi==3) dele();
else if(chi==4) search();
else if(chi==5) colour();
else if(chi==0)
{
printf("你已经退出超市商品管理系统!谢谢您的使用,再见\n");
exit(0);
}
else
{
printf(" You Enter The Choice Is Not valid ! \n");
getch();
system("cls");
start();
}
}
void huanying()
{
printf("\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\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");
printf("\t\3 超市管理系统 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \4\4\4\4\4\4 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \5\5\5\5\5\5\5\5\5 \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\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
}
5:商品信息的录入
void input() /*数据录入*/
{
FILE *fp;
char flag[20];
fp=fopen("e:/student.txt","wt");
do
{
printf("请输入你的商品信息:\n"); /*录入商品的信息*/
printf("商品编号:");
scanf("%s",goods[count].goods_id);
printf("商品名字:");
scanf("%s",goods[count].goods_name);
printf("商品价格:");
scanf("%lf",&goods[count].goods_price);
printf("商品折扣:");
scanf("%lf",&goods[count].goods_discount);
printf("商品总数目:");
scanf("%d",&goods[count].goods_amount);
printf("商品剩余数目:");
scanf("%d",&goods[count].goods_remain);
count++; /*存数的商品数加一*/
printf("是否继续输入数据 y是 n否 : "); /*是否还想继续输入数据*/
scanf("%s",flag);
}while(strcmp(flag,"y")==0||strcmp(flag,"Y")==0);
fwrite(&goods,sizeof(struct MarketGoods),count,fp);
fclose(fp);
output(); /*调用显示商品数据*/
getch();
system("cls");
start();
}
6:商品信息的修改
void change() /*数据修改*/
{
FILE *fp;
int i,m=0;
char ch[20],a[20];
fp=fopen("e:/student.txt","rt");
while(fread(&goods[m],sizeof(struct MarketGoods),1,fp)!=NULL)
{
m++;
}
fclose(fp);
printf("\nyou sure want change goodsInfor y/n): "); /*根据商品的id来修改数据*/
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
printf("\nenter you want change goods_id:");
scanf("%s",a);
for(i=0;i<count;i++)
{
if(strcmp(goods[i].goods_id,a)==0)
{
printf("\nyou sure want change goods name(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
printf("\nname:");
scanf("%s",goods[i].goods_name);
}
printf("\nyou sure want change goods price(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
printf("\nprice");
scanf("%lf",&goods[i].goods_price);
}
printf("\nyou sure want goods discount(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
printf("\ndiscount");
scanf("%lf",&goods[i].goods_discount);
}
printf("\nyou sure want goods amount(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
printf("\namount");
scanf("%d",&goods[i].goods_amount);
}
printf("\nyou sure want goods remain(y/n): ");
scanf("%s",ch);
if(strcmp(ch,"y")==0||strcmp(ch,"Y")==0)
{
printf("\nremain"); scanf("%d",&goods[i].goods_remain);
}
}
}
}
fwrite(&goods,sizeof(struct MarketGoods),count,fp);
fclose(fp);
output();
getch();
system("cls");
start();
}
7:商品信息的删除
void dele() /*数据删除*/
{
FILE *fp;
int i,m=0,j;
char ch[20],c[20];
fp=fopen("e:/student.txt","rt");
while(fread(&goods[m],sizeof(struct MarketGoods),1,fp)!=NULL)
{
printf("%s",goods[m].goods_id);
m++;
}
fclose(fp);
printf("\nenter you want delete name :\n"); /*根据商品的名称来删除数据*/
printf("name:");
scanf("%s",c);
for(i=0;i<count;i++)
{
if(strcmp(c,goods[i].goods_name)==0)
break; /*找到,即跳出循环*/
for(j=i;j<count-1;j++)
goods[j]=goods[j+1];
}
printf("\t\t\tyou had delete %s\n",c);
count--;
fp=fopen("e:/student.txt","wt");
fwrite(&goods,sizeof(struct MarketGoods),count,fp);
fclose(fp);
output();
getch();
system("cls");
start();
}
8:商品信息查询
void search() /*数据查找*/
{
FILE *fp;
int i,m=0;
char a[20];
fp=fopen("e:/student.txt","rt");
while(fread(&goods[m],sizeof(struct MarketGoods),1,fp)!=NULL)
{
printf("%s",goods[m].goods_name);
m++;
}
printf("\nenter you want look name:"); /*根据商品的名称来查找数据*/
scanf("%s",a);
for(i=0;i<m;i++)
{
if(strcmp(goods[i].goods_name,a)==0)
printf("%s %s %lf %lf %d %d \n",goods[i].goods_id,goods[i].goods_name,goods[i].goods_price,goods[i].goods_discount,goods[i].goods_amount,goods[i].goods_remain);
}
getch();
system("cls");
start();
}
9:系统颜色选择
void colour()
{
int a;
printf("\n\n\t\t选择以下方案\n");
printf("\n\n\t\t1**********红底黑字\n");
printf("\n\n\t\t2**********白底黑子");
printf("\n\n\t\t3**********黑底红字");
printf("\n\n\t\t4**********绿底蓝字");
printf("\n\n\t\t5**********黄底蓝字");
printf("\n\n\t\t6**********系统默认");
printf("\n\n\t\t\t\t请挑选您喜欢的颜色<1-6>....");
scanf("%d",&a);
switch(a)
{
case 1:system("color 40"); break;
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 la"); break;
default:printf("\n\n\t\t\t\t输入无效");
{
getch();
colour();
}
}
start();
}
10:商品信息输出
void output() /*数据输出*/
{ FILE *fp;
int i,m=0;
fp=fopen("e:/student.txt","rt");
while(fread(&goods[m],sizeof(struct MarketGoods),1,fp)!=NULL)
{
m++;
}
fclose(fp);
printf(" 编号 名称 价格 折扣 总数目 剩余数目 \n");
for(i=0;i<m;i++)
{
printf("%s %s %lf %lf %10d %10d \n",goods[i].goods_id,
goods[i].goods_name,
goods[i].goods_price,goods[i].goods_discount,
goods[i].goods_amount,
goods[i].goods_remain);
}
getch();
system("cls");
start();
}
11:退出系统
void start() /*启动菜单*/
{
int chi;
printf(" 超市商品管理系统\n");
printf(" ********************************************\n");
printf(" ********************************************\n");
printf(" 1.商品信息的录入:\n");
printf(" 2.商品信息的修改:\n");
printf(" 3.删除某个商品信息:\n");
printf(" 4.查找商品信息:\n");
printf(" 5.颜色选择:\n");
printf(" 0.退出程序\n");
printf(" ********************************************\n");
printf(" ********************************************\n");
printf(" 输入你的选择: ");
scanf("%d",&chi); /*根据你的选择执行相应的函数*/
if(chi==1) input();
else
if(chi==2) change();
else if(chi==3) dele();
else if(chi==4) search();
else if(chi==5) colour();
else if(chi==0)
{
printf("你已经退出超市商品管理系统!谢谢您的使用,再见\n");
exit(0);
4:调试分析
调试过程中,会有很多的错误。语句和函数的运用不到位,还存在许多的小错误。
5:测试结果
通过我想同学求助,向老师咨询,查找书籍,在网络上查找,最终使得程序顺利运行。
1:欢迎界面
2:密码输入
3:系统菜单选择界面
4:商品信息录入及保存
5:商品信息的修改
6:商品信息的删除及剩余物品记录
7:物品信息的查询
8:商品信息输出
9:系统环境颜色的选择
10:退出系统
课程设计总结
上学期学习了C语言,所以对于C语言有了初步和基础的认识。这次做程序设计,许多的程序过程都是通过咨询老师,同学,查询网络,查找书籍做的。感到自己的C语言知识还是很欠缺。程序中许多都是自己设计的简单的语句,很少有精彩的部分,但是很知足,毕竟是自己第一次做,感觉挺好。但是总结下来,自己可是漏洞百出。
通过一周多的实习设计,使我对于C语言有了更深刻,更多的了解,也是我认识到C语言的难度,但是,我又感觉到了这门课程的乐趣,看着自己的成果一天天出现,那种喜悦是不可言语的。过程中,我发现自己的基础知识薄弱,英语很多不认识,知识做的过程中还要上查询英语方面的知识,很是费事。还有就是有些概念很模糊,但是通过这次实习,我对于C语言有了新的认识。在这一周时间里,经过不断的与同学和老师的讨论,是我的C语言水平有了很大的提高。
此次我还感觉到,C语言是一门实用性很强的课程。其实真正的程序过程就是头文件,主函数,模块函数。这些东西的组合才构成了一个完整的函数体系。虽然说只有这几项,但是就是这简单的几项,在一起通过逻辑,顺序,等关系罗列开来,构成了复杂的函数体。我就是在程序作业工程中老是在各种逻辑顺序中迷糊,所以浪费了很长时间。
这次的实验设计,让我对C语言有了很大的兴趣。我相信我还会去自学的,因为我知道只是一门可以武装子的课程。相信,通过这次的学习,还有以后的学习,会是我的C语言有很大的提高。
源程序
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#define COUNT 30 /*声明商品的种类为30中*/
#define N 30
void start(); /*启动界面*/
void input(); /*商品数据信息输入函数*/
void change(); /*商品数据信息修改函数*/
void dele(); /*给定指定商品名称,删除商品信息*/
void output(); /*商品信息输出*/
void search(); /*商品信息查找*/
void mima();/*密码程序*/
void colour();//颜色选择
void huanying();
void paixu();
struct MarketGoods /*存数商品信息的结构体*/
{
char goods_id[30]; /*商品编号*/
char goods_name[30]; /*商品名称*/
double goods_price; /*商品价格*/
double goods_discount;/*商品折扣*/
int goods_amount;/*商品总数目*/
int goods_remain;/*商品剩余数目*/
}goods[COUNT];
int count=0; /*全局变量,用于保存实际上有多少个商品*/
void main() /*主函数*/
{ huanying();
mima();
start();
}
void start() /*启动菜单*/
{
int chi;
printf(" 超市商品管理系统\n");
printf(" ********************************************\n");
printf(" ********************************************\n");
printf(" 1.商品信息录入:\n");
printf(" 2.商品信息修改:\n");
printf(" 3.商品信息删除:\n");
printf(" 4.商品信息查找:\n");
printf(" 5.系统颜色选择:\n");
printf(" 6.商品信息输出:\n");
printf(" 0.退出程序\n");
printf(" ********************************************\n");
printf(" ********************************************\n");
printf(" 输入你的选择: ");
scanf("%d",&chi); /*根据你的选择执行相应的函数*/
if(chi==1) input();
else
if(chi==2) change();
else if(chi==3) dele();
else if(chi==4) search();
else if(chi==5) colour();
else if(chi==6) output();
else if(chi==0)
{
printf("你已经退出超市商品管理系统!谢谢您的使用,再见\n");
exit(0);
}
else
{
printf(" You Enter The Choice Is Not valid ! \n");
getch();
system("cls");
start();
}
}
void huanying()
{
printf("\t\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\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");
printf("\t\3 超市管理系统 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \4\4\4\4\4\4 \3\n");
printf("\t\3 \3\n");
printf("\t\3 \5\5\5\5\5\5\5\5\5 \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\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
}
void mima()
{
// char pass[6]={'1','2','3','4','5','6'};/*假设密码长度是6*/
char pass[]={"123456"};/*假设密码长度是6*/
char str[6],ch;
int i=0;
int flag=0;
printf(" 请输入密码:");
fflush(stdin);
for(i=0;i<6;i++)
{
ch=getch(); /*读取字符,不显示*/
str[i]=ch;
putchar('*');
}
for(i=0;i<6;i++)
{
if(str[i]!=pass[i])
{
flag=1;
break;
}
}
if(flag)
{
printf("\n密码错误,登录失败!请重新登录\n");
mima();
}
else printf("\n登录成功\n");
getch();
system("cls");
start();
}
void input() /*数据录入*/
{
FILE *fp;
char flag[20];
fp=fopen("e:/student.txt","wt");
do
{
printf("请输入你的商品信息:\n"); /*录入商品的信息*/
printf("商品编号:");
scanf("%s",goods[count].goods_id);
printf("商品名字:");
scanf("%s",goods[count].goods_name);
printf("商品价格:");
scanf("%lf",&goods[count].goods_price);
printf("商品折扣:");
scanf("%lf",&goods[count].goods_discount);
printf("商品总数目:");
scanf("%d",&g
展开阅读全文