中北大学数据结构课程设计说明书学生姓名:郭世杰学号: 1021011743学院: 软件学院专业: 软件开发与测试题目: 客户消费积分管理系统指导教师李瑞红2011年12月20日1. 设计任务概述(包括系统总体框图及功能描述)功能描述:针对客户的消费情况,进行客户管理,根据客户的消费积分对客户实行不同程度的打折优惠。
1.采用数组和文件存储结构进行客户信息的存储; 2.对客户的信息可以进行修改、删除、添加; 3.能够根据消费情况进行客户积分的计算; 根据积分情况实行不同程度的打折优惠。
2. 本设计所采用的数据结构(如:链表、栈、树、图等)本系统用到的主要数据结构为数组和文件。
一个数组对应一个客户,里面用3个字符串分别存储着用户的客户号、姓名和消费情况。
然后将数组写入文件,查询时读取文件,提取相应信息。
3.功能模块详细设计3.1 详细设计思想在数组中定义3个字符串number 、name 、xiaofei ,分别存储客户的顾客号、积分打折操作系统插 入修 改查看删除存 入 文 件修改 信 息读取 文 件删除文件姓名、消费额。
通过录入函数对3个字符串循环进行赋值,然后根据消费额使用if语句判断其折扣区间,复制完毕后存入文件s_score.txt。
修改函数首先按照用户输入的客户号找到相应存储文件,然后输出相应信息供客户阅览,最后提供修改命令,修改完毕后删除原文件,用新文件替代原文件。
查找函数首先读取文件,然后根据用户输入客户号找到相应文件输出客户信息(顾客号、姓名、消费额、积分、折扣)。
删除函数根据用户输入客户号找到相应文件进行删除。
主函数为用户界面,1-4分别对应录入、修改、查找、删除函数,5为退出。
3.2 核心代码#include "stdio.h"#include "stdlib.h"#include "string.h"#include "conio.h"#include "mem.h"#include "ctype.h"#include "alloc.h"struct score{char number[8]; /*定义3个存储客户信息的字符串*/char name[10];float score[6];float discount[8];}data,info[100]; /*定义数组*/int i,j,k=0;char temp[20],temp1[20],ch;FILE *fp,*fp1;void luru(){if((fp=fopen("s_score.txt","ab+"))==NULL){printf("cannot open this file.\n");getch();exit(0);}for(i=0;i>=0;i++) /*无限循环直到用户选择停止*/{printf("Please input number:");gets(data.number);printf("please input name:");gets();printf("Please input xiaofei:");gets(temp);data.score[0]=atof(temp); /*不能直接赋值,采用转换函数*/ if(data.score[0]<=5000) /*判断折扣区间*/data.discount[0]=1;else if(data.score[0]<=10000&&data.score[0]>5000)data.discount[0]=0.9;elsedata.discount[0]=0.8;fwrite(&data,sizeof(data),1,fp); /*写入文件*/printf("another?(input n to main/anykey to continue)\n"); /*循环停止判断*/ch=getch();if(ch=='n'||ch=='N')break;} fclose(fp);}void xiugai(){if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+" ))==NULL){printf("Cannot open this file.\n");exit(0);}printf("\nPlease input shuru xiugai number:");scanf("%d",&i); getchar();while((fread(&data,sizeof(data),1,fp))==1) /*读取文件*/{j=atoi(data.number);if(j==i) /*根据输入数值确定客户号*/{printf("number:%s\nname:%s\n",data.number,);printf("Please input name:");gets();printf("Please input xiaofei:");gets(temp1);data.score[0]=atof(temp1);if(data.score[0]<=5000) /*判断折扣区间*/ data.discount[0]=1;else if(data.score[0]<=10000&&data.score[0]>5000)data.discount[0]=0.9;elsedata.discount[0]=0.8;} fwrite(&data,sizeof(data),1,fp1);}fseek(fp,0L,0); /*0位移*/fseek(fp1,0L,0);while((fread(&data,sizeof(data),1,fp1))==1){fwrite(&data,sizeof(data),1,fp); /*取代原文件*/}fclose(fp);fclose(fp1);}void find(){if((fp=fopen("s_score.txt","rb"))==NULL){printf("\nCannot open this file.\n");exit(0);}printf("\n Please input number chakan:");scanf("%d",&i);while(fread(&data,sizeof(data),1,fp)==1){j=atoi(data.number);if(i==j){printf("number: %s\nname: %s\nspend: %f\nscore: %f\ndiscount: %f\n",data.number,,data.score[0],data.score[0],data.discount[0]);}}getch();}void delete(){if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+" ))==NULL){printf("\nopen score.txt was failed!");getch();exit(0);}printf("\nPlease input number which you want to del:");scanf("%d",&i);getchar();while((fread(&data,sizeof(data),1,fp))==1){j=atoi(data.number);if(j==i){printf("Anykey will delet it.\n");getch();continue;}fwrite(&data,sizeof(data),1,fp1);}fclose(fp);fclose(fp1);remove("s_score.txt"); /*删除文件*/rename("temp.txt","s_score.txt");printf("Data delet was succesful!\n");printf("Anykey will return to main.");getch();}main(){while(1){clrscr(); /*清屏*/printf("*============================================================* \n");printf("* 1>luru 2>xiugai * \n");printf("* 3>delete 4>find * \n");printf("* 5>exit * \n");printf("** \n");printf("*-----------------------------------------------------------* \n");printf(" Please input which you want(1-5):\n");ch=getch();switch(ch){case '1':luru();break;case '2':xiugai(); break;case '3':delete(); break;case '4':find(); break;case '5':exit(0);default: continue;}}}3.3 程序运行结果(拷屏)运行程序初始界面,具有5个功能,如上图所示功能1,输入客户001的信息功能4(查找),查找客户001的具体信息功能2(修改)修改客户001的信息输出修改后客户001的信息功能3(删除),删除客户001的信息3.课程设计心得、存在问题及解决方法心得体会:设计了这个系统之后,我深刻的体会到了文件相对于其他数据结构更便于修改和删除。