1、中北大学数据结构课 程 设 计 说 明 书学生姓名:学 号:学 院:电子与计算机科学技术学院专 业:软件工程题 目:客户消费积分管理系统成 绩:指导教师:秦品乐、梁志剑2023 年 6 月 24 日1. 设计目的数据结构课程设计的目的是,通过设计掌握数据结构课程中学到的基本理论和算法并综合运用于解决实际问题中,它是理论与实践相结合的重要过程。设计规定学会如何对实际问题定义相关数据结构,并采用恰当的设计方法和算法解决问题,同时训练学生进行复杂程序设计的技能和培养良好的程序设计习惯。2. 设计内容和规定问题描述:针对客户的消费情况,进行客户管理,根据客户的消费积分对客户实行不同限度的打折优惠。基本
2、规定:1. 采用一定的存储结构进行客户信息的存储;2. 对客户的信息可以进行修改、删除、添加;3. 可以根据消费情况进行客户积分的计算;4. 根据积分情况实行不同限度的打折优惠。3本设计所采用的数据结构本系统用到的重要数据结构为数组和文献。一个数组相应一个客户,里面用3个字符串分别存储着用户的客户号、姓名和消费情况。然后将数组写入文献,查询时读取文献,提取相应信息。4功能模块具体设计积分打折操作系统 录入删除查看修改删除文献读取文献修改信息存入文献 4.1 具体设计思想在数组中定义3个字符串gukehao、xingming、xiaofei,分别存储客户的顾客号、姓名、消费额。通过录入函数对3个
3、字符串循环进行赋值,然后根据消费额使用if语句判断其折扣区间,复制完毕后存入文献s_score.txt。修改函数一方面按照用户输入的客户号找到相应存储文献,然后输出相应信息供客户阅览,最后提供修改命令,修改完毕后删除原文献,用新文献替代原文献。查找函数一方面读取文献,然后根据用户输入客户号找到相应文献输出客户信息(顾客号、姓名、消费额、积分、折扣)。删除函数根据用户输入客户号找到相应文献进行删除。主函数为用户界面,1-4分别相应录入、修改、查找、删除函数,5为退出。 4.2 源代码#include stdio.h#include stdlib.h#include string.h#includ
4、e conio.h#include mem.h#include ctype.h#include alloc.hstruct score char gukehao8; /*定义3个存储客户信息的字符串*/ char mingzi20; float score6;data,info1000; /*定义数组*/ int i,j,k=0; float n; /*n为折扣值*/ char temp20,ch; FILE *fp,*fp1;void luru() if(fp=fopen(s_score.txt,ab+)=NULL) printf(cannot open this file.n); getc
5、h();exit(0); for(i=0;i=0;i+) /*无限循环知道用户选择停止*/ printf(Please input gukehao:); gets(data.gukehao); printf(please input mingzi:); gets(data.mingzi); printf(Please input xiaofei:); gets(temp);data.score0=atof(temp); /*不能直接赋值,采用转换函数*/ if(data.score0=5000) /*判断折扣区间*/ n=1; else if(data.score05000)n=0.95; e
6、lse n=0.9; 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 i
7、nput shuru xiugai gukehao:); scanf(%d,&i); getchar(); while(fread(&data,sizeof(data),1,fp)=1) /*读取文献*/ j=atoi(data.gukehao); if(j=i) /*根据输入数值拟定客户号*/ printf(gukehao:%snmingzi:%sn,data.gukehao,data.mingzi); printf(Please input mingzi:); gets(data.mingzi); printf(Please input xiaofei:); gets(temp);data
8、.score0=atof(temp); 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 chazhao() if(fp=fopen(s_score.txt,rb)=NULL) printf(nCannot open this file.n); exit(0); print
9、f(nPlease input gukehao chakan:); scanf(%d,&i); while(fread(&data,sizeof(data),1,fp)=1) j=atoi(data.gukehao); if(i=j) printf(gukehao:%snmingzi:%snxiaofei:%fnjifen:%fnzhekou:%fn,data.gukehao,data.mingzi,data.score0,data.score0,n); getch();void shanchu()if(fp=fopen(s_score.txt,rb+)=NULL|(fp1=fopen(tem
10、p.txt,wb+)=NULL) printf(nopen score.txt was failed!); getch(); exit(0); printf(nPlease input gukehao which you want to del:); scanf(%d,&i);getchar(); while(fread(&data,sizeof(data),1,fp)=1) j=atoi(data.gukehao); if(j=i) printf(Anykey will delet it.n); getch(); continue; fwrite(&data,sizeof(data),1,f
11、p1); 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(* 1luru 2xiugai * n); printf(* 3shanchu 4chazhao * n); printf(* 5exit * 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:shanchu(); break; case 4:chazhao(); break; case 5:exit(0); default: continue; 5.结论 通过对系统的设计,发现文献相对于其他数据结构更便于修改和删除。