数据结构课程设计报告设计题目:专业软件工程班级0902班学生周雷学号********指导教师张雪21.客户消费积分管理系统问题描述:针对客户的消费情况,进行客户管理,根据客户的消费积分对客户实施不同程度的打折优惠。
1.采用一定存储结构进行客户信息存储。
2.对客户信息可以修改、删除、添加。
3.能够根据消费情况进行客户积分计算。
4.根据积分情况实行不同程度的打折优惠。
1.本程序对于客户消费积分管理系统利用线性表的链表存储方式,使用结构体指针将每一个用户联系起来。
使用结构体指针的链表动态链接形式将便于客户的封装,节省空间,便于插入和删除。
2.程序中设计了①添加用户②查找用户③修改用户④删除用户⑤统计客户数量的功能。
3.①添加用户:函数void Getelem (cnode *head);添加用户中,采用结构体将每个用户的信息封装,其中包括用户姓名name、用户省份证号ID、用户消费金额consume、积分integer 的信息。
输入一个客户信息后再开辟新的节点连接。
开一个空间加一个用户可以节省空间,解决实现开辟的空间不够的问题。
4.②void Search(cnode *head,char ID[]);查找用户利用指针一个一个用户比对信息知道,直到找到正确信息并显示。
5③void Amend(cnode *head,char ID[]);查找并显示然后修改。
6④void Delete(cnode *head,char ID[]);查找显示并删除。
7⑤void Showall(cnode *head);遍历链表并显示客户。
8⑥void count(cnode *head);遍历统计客户数量显示9⑦double display_discount(double integer);计算客户折扣,每次显示用户信息调用一次保证客户为最新打折信息。
主函数主菜单①添加用户②查找用户③修改用户④删除用户⑤统计客户数量⑥退出。
各个函数通过调用头结点连接。
4.功能模块详细设计、运行结果。
源代码:#include "stdio.h"#include "stdlib.h"#include "string.h"typedef struct cnode{char name[20];char ID[20];double consume;double integer;struct cnode *next;}cnode;void Initstack(cnode * &head)/*初始化链表*/{head= (cnode*)malloc(sizeof(cnode)); //开辟节点空间head->next=NULL;}void Getelem (cnode *head);void Search(cnode *head,char ID[]);void Amend(cnode *head,char ID[]);void Delete(cnode *head,char ID[]);void Showall(cnode *head);void count(cnode *head);double display_discount(double integer);void main(){cnode *head;int choice;char y[20];Initstack(head);do{printf("\n");printf(" 客户消费积分管理系统\n\n");printf(" ****************************");printf("\n * *\n");printf("\n * 主菜单*\n");printf("\n * 1 添加客户*\n");printf("\n * 2 查找客户*\n");printf("\n * 3 修改客户*\n");printf("\n * 4 删除客户*\n");printf("\n * 5 显示客户*\n");printf("\n * 6 统计客户*\n");printf("\n * 7 退出*\n");printf("\n * *\n");printf(" ***************************");printf("\n 请输入您的选择(1,2,3,4,5,6):");scanf("%d",&choice);if(choice==1){Getelem(head); } //添加else if(choice==2){printf("\n 请输入您查找客户的身份证号:");scanf("%s",y);while(strlen(y)!=18){printf("身份证号码位数有误请重新输入(18位):");scanf("%s",y);}Search(head,y); } //查找else if(choice==3){printf("\n 请输入您想修改客户的身份证号:");scanf("%s",y);while(strlen(y)!=18){printf("身份证号码位数有误请重新输入(18位):");scanf("%s",y);}Amend(head,y); } //修改else if(choice==4){printf("\n");printf(" 请输入你想要删除的客户的身份证号:");scanf("%s",y);Delete(head,y); }//删除else if(choice==5){printf("\n");Showall(head); } //显示else if(choice==6){printf("\n");count(head); } //统计else if(choice==7)exit(1);}while(choice<=7);}void Getelem (cnode *head) { //添加客户函数以头节点为参数cnode *p;double y;p=(cnode*)malloc(sizeof(cnode));/*申请空的节点空间*/printf("请输入姓名:");scanf("%s",&p->name);printf("请输入身份证号(18位):");scanf("%s",&p->ID);while(strlen(p->ID)!=18){printf("身份证号码位数有误请重新输入(18位):");scanf("%s",&p->ID);}printf("请输入消费金额:");scanf("%lf",&p->consume);p->integer=p->consume/100;y=display_discount(p->integer); //调用函数计算折扣printf("折扣:");printf("%.1lf",y);printf("折\n");p->next=head->next;head->next=p;}void Search(cnode *head,char ID[]){cnode *p;double y;p=head;if(p->next==NULL)printf("没有客户!\n");else{while(p->next!=NULL){p=p->next;if(strcmp(ID,p->ID)==0) { //判断身份证号是否相同printf("姓名:");printf("%s\n",p->name);printf("身份证号:");printf("%s\n",p->ID);printf("消费:");printf("%.2lf\n",p->consume);printf("积分:");printf("%lf\n",p->integer);y=display_discount(p->integer);printf("折扣:");printf("%.1lf",y);printf("折\n");}}}}void Amend(cnode *head,char ID[]){ //修改客户函数cnode *p;double y,z;int choose,x;p=head;if(p->next==NULL)printf("没有客户!\n");else{while(p->next!=NULL){p=p->next;if(strcmp(ID,p->ID)==0) { //判断身份证号是否相同printf("姓名:");printf("%s\n",p->name);printf("身份证号:");printf("%s\n",p->ID);printf("消费:");printf("%.2lf\n",p->consume);printf("积分:");printf("%lf\n",p->integer);y=display_discount(p->integer);printf("折扣:");printf("%.1lf",y);printf("折\n");}}printf("请选择你要修改的1、姓名。