文档库 最新最全的文档下载
当前位置:文档库 › c语言超市管理系统课程设计

c语言超市管理系统课程设计

课程设计

课程设计名称:高级语言程序设计

专业班级:计算机科学与技术0802班

学生姓名:李旭

学号: 200848140202

指导教师:范艳峰

课程设计时间: 2009年7月2号

计算机科学与技术专业课程设计任务书

1 需求分析:

随着现代生活质量的提高,超市这种便利的服务开始走进我们的生活,同时随着超市涌入我们的生活,如何更便利的对超市进行系统和有序的操作,成为了我们需要考虑的问题,本程序运用C语言程序设计了一个超市管理系统。关系系统的的功能主要有新购物品入库、物品信息删除、物品信息修改、物品信息查询、物品信息浏览功能,在相应的硬盘上面进行存盘以防止部分数据的丢失。为了更加人性化使用此管理系统,还在MENU选项总添加了系统颜色设置功能,使用户可以根据自己的喜好修改操作界面。

2 概要设计

(1)数据结构

依据给定的物品信息和数据形式,数组必须用结构体实现。结构类型的层次结构:

struct ima

{

int id;

char name[20];

char produce[30];

int number;

float price;

};

(2)模块划分

依据程序的结构反和功能,遵照“自顶而下”的原则,描述该程序的层次结构图一显示了该程序的层次结构,共 5层:

如下图:

图一

图一的层次结构(3)原函数清单:

1、创建函数

void chushihua()

2、增加物品函数

Tianjia();

3、删除物品信息函数

Shanchu();

4、修改物品信息函数

Xiugai();

5、查询物品信息函数

Chazhao();

6、浏览物品信息函数

Liulan();

7、系统颜色设置函数

yanseshezhi();

8、应用程序退出函数

Jieshu();

3 运行环境:

Win2003, WinXP, Win2000, 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.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 \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 按任意键继续 \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 \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 \3");

getch();

system("cls");

menu();

chushihua();

menu();

}

5、选择菜单

void menu()

{

int choice;

printf("\n∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞【超市库存管理系统】∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞\n");

printf("--------------------------------系统菜单显示如下--------------------------------");

printf("\n\t①=====================【新购物品入库】\n");

printf("\n\t②=====================【物品信息删除】\n");

printf("\n\t③=====================【物品信息修改】\n");

printf("\n\t④=====================【物品信息查询】\n");

printf("\n\t⑤=====================【物品信息浏览】\n");

printf("\n\t⑥=====================【系统颜色设置】\n");

printf("\n\t⑦=====================【应用程序退出】\n");

printf("\n\t请输入您要选择的菜单......");

scanf("%d",&choice);

switch(choice)

{

case 1:

Tianjia();

break;

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();

}

}

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);

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请您输入要入库物品的信息...\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",https://www.wendangku.net/doc/7d6699433.html,);

printf("\t\t\t\t 物品的生产地:");

scanf("%s",i.produce);

printf("\t\t\t\t 物品的数量:");

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("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(struct 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

{

if(i[j].id!=delID)

{

fwrite(&i[j],sizeof(struct ima),1,fp);

}

}

fclose(fp);

printf("\t\t\t\t\t物品信息已清除!!!\n");

printf("\n您想继续吗?(y/n)");

scanf(" %c",&choice);

if(choice=='Y'||choice=='y')

{

Shanchu();

}

else

{

system("cls");

menu();

}

}

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(!feof(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].id!=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);

}

}

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 ima 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))

相关文档
相关文档 最新文档