资源描述
中北大学
数据结构
课 程 设 计 说 明 书
学生姓名:
学 号:
学 院:
电子与计算机科学技术学院
专 业:
软件工程
题 目:
客户消费积分管理系统
成 绩:
指导教师:
秦品乐、梁志剑
2023 年 6 月 24 日
1. 设计目的
数据结构课程设计的目的是,通过设计掌握数据结构课程中学到的基本理论和算法并综合运用于解决实际问题中,它是理论与实践相结合的重要过程。设计规定学会如何对实际问题定义相关数据结构,并采用恰当的设计方法和算法解决问题,同时训练学生进行复杂程序设计的技能和培养良好的程序设计习惯。
2. 设计内容和规定
问题描述:针对客户的消费情况,进行客户管理,根据客户的消费积分对客户实行不同限度的打折优惠。
基本规定:
1. 采用一定的存储结构进行客户信息的存储;
2. 对客户的信息可以进行修改、删除、添加;
3. 可以根据消费情况进行客户积分的计算;
4. 根据积分情况实行不同限度的打折优惠。
3.本设计所采用的数据结构
本系统用到的重要数据结构为数组和文献。
一个数组相应一个客户,里面用3个字符串分别存储着用户的客户号、姓名和消费情况。
然后将数组写入文献,查询时读取文献,提取相应信息。
4.功能模块具体设计
积分打折操作系统
录入
删除
查看
修改
删除文献
读取文献
修改信息
存入文献
4.1 具体设计思想
在数组中定义3个字符串gukehao、xingming、xiaofei,分别存储客户的顾客号、姓名、消费额。
通过录入函数对3个字符串循环进行赋值,然后根据消费额使用if语句判断其折扣区间,复制完毕后存入文献s_score.txt。
修改函数一方面按照用户输入的客户号找到相应存储文献,然后输出相应信息供客户阅览,最后提供修改命令,修改完毕后删除原文献,用新文献替代原文献。
查找函数一方面读取文献,然后根据用户输入客户号找到相应文献输出客户信息(顾客号、姓名、消费额、积分、折扣)。
删除函数根据用户输入客户号找到相应文献进行删除。
主函数为用户界面,1-4分别相应录入、修改、查找、删除函数,5为退出。
4.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 gukehao[8]; /*定义3个存储客户信息的字符串*/
char mingzi[20];
float score[6];
}data,info[1000]; /*定义数组*/
int i,j,k=0;
float n; /*n为折扣值*/
char temp[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 gukehao:");
gets(data.gukehao);
printf("please input mingzi:");
gets(data.mingzi);
printf("Please input xiaofei:");
gets(temp);data.score[0]=atof(temp); /*不能直接赋值,采用转换函数*/
if(data.score[0]<=5000) /*判断折扣区间*/
n=1;
else
if(data.score[0]<=10000&&data.score[0]>5000)
n=0.95;
else
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 input shuru xiugai gukehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1) /*读取文献*/
{
j=atoi(data.gukehao);
if(j==i) /*根据输入数值拟定客户号*/
{
printf("gukehao:%s\nmingzi:%s\n",data.gukehao,data.mingzi);
printf("Please input mingzi:");
gets(data.mingzi);
printf("Please input xiaofei:");
gets(temp);data.score[0]=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);
}
printf("\nPlease input gukehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.gukehao);
if(i==j)
{
printf("gukehao:%s\nmingzi:%s\nxiaofei:%f\njifen:%f\nzhekou:%f\n",data.gukehao,data.mingzi,data.score[0],data.score[0],n);
}
}getch();
}
void shanchu()
{
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 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,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>shanchu 4>chazhao * \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':shanchu(); break;
case '4':chazhao(); break;
case '5':exit(0);
default: continue;
}
}
}
5.结论
通过对系统的设计,发现文献相对于其他数据结构更便于修改和删除。
展开阅读全文