C语言 会员管理系统

 大一上学期期末项目设计;

思路参考:【千锋教育新版C语言程序设计视频教程(适合自学,c语言初学者入门教程)】 https://www.bilibili.com/video/BV1id4y1375a/?p=119&share_source=copy_web&vd_source=a6401c9820869ff8ca006c68478cde72

C语言 会员管理系统_第1张图片 

 

 C语言 会员管理系统_第2张图片

代码段:

#include
#include
#include
#include
#include
//创建数据域 
struct Date{
	int year;
	int month;
	int day;
};
struct Goods{
	int goods1cost;
	int goods2cost;
	int goods3cost;
	int totalcost;
};

struct Other{
	char likes[10];
	int integral;//积分为消费额的两倍; 
	char coupon[20];
};

struct number {
	 char rank;//等级分 A/B/C/D/E 500积分为D,1000积分为C,2000积分积分为B,4000积分为A; 
	 char name[10];
	 char phonenumber[20]; 
	 char gender[5];//性别分 男 / 女 
	 struct Date link;
	 struct Goods cost;
	 struct Other thing2; 
	 
};

//创建节点 
struct Node{
	struct number data;
	struct Node *pnext;
};


//头部指针全局化 
struct Node *list=NULL;

//功能选项总开关; 
int key=0;


//函数声明区域 
struct Node* CreatHead();//初始化头部指针 
void gotoxy(int x,int y);//光标定位 
void changeColors();//改变控制台颜色函数 
struct Node* createNode(struct number data);//创建新节点函数 
void insertInfo(struct Node* headNode,struct number data);//插入新数据节点函数 
void saveInfo(char *filename,struct Node *headNode);//同步文件数据函数 
void readInfo(char *filename,struct Node*headNode);//读取文件函数 
void showlist(struct Node*headNode);//总体打印函数 
void showlistplus(struct Node*headNode);//筛选函数 
void showlistplus2(struct Node*headNode);//筛选函数 
void analysis(struct number *temp);//分析函数 
void analysisplus(struct Node *temp);//分析函数 
void menu();//总菜单 
struct Node* SearchByName(struct Node* headNode,char *name);//根据姓名查找函数 
struct Node* SearchByphonenumber(struct Node* headNode,char *number);//根据手机号码查找函数 
void deleteByname(struct Node* headNode, char *name);//删除数据函数 
void menuone();//修改会员信息菜单 
void keyEvent();//选择功能 
//函数声明区域结束 

//主函数 
int main()
{
	changeColors();
	//初始化头部指针 
	list=CreatHead();
	//读取原来文件的数据 
	readInfo("numberInfo.txt",list);
	while(1){
		menu();
		keyEvent();
		if(key==0)break;
		system("pause");
		system("cls"); //清屏
	}
	system("cls"); //清屏
	return 0;
}


//用于初始化头部指针 
struct Node* CreatHead(){
	struct Node *pHeadNode = (struct Node*)malloc(sizeof(struct Node));
	if(pHeadNode == NULL)return NULL;
	pHeadNode->pnext=NULL;
	return pHeadNode;
}
//用于输出 " Nice to meet you " 
void gotoxy(int x,int y)
{// 光标定位函数
	COORD p;//定义结构体变量p
	HANDLE handle=GetStdHandle(STD_OUTPUT_HANDLE);// 获取当前函数句柄
	p.X=x;p. Y=y;//将光标的目标移动位置传递给结构体
	SetConsoleCursorPosition(handle,p);//移动光标
}
void changeColors(){
	system("color F4");//改变屏幕的背景色和前景色
	gotoxy(8,8);//光标定位到指定位置
	printf("Nice to meet you!\n");
	getch( );
}
//创建新的节点 
struct Node* createNode(struct number data){
	struct Node *newNode=(struct Node*)malloc(sizeof(struct Node));
	if(newNode==NULL)return NULL;
	newNode->data=data;
	newNode->pnext=NULL;
	return newNode;
}
void insertInfo(struct Node* headNode,struct number data){
	//根据传来的temp,创建一个新的Node 的结构体; newNode
	struct Node *newNode= createNode(data);
	newNode->pnext = headNode -> pnext;
	headNode->pnext=newNode;
}
//同步文件操作 
void saveInfo(char *filename,struct Node *headNode){
	//打开文件
	FILE *fp=fopen(filename, "w");
	//写入文件 fprintf
	
	struct Node *move = headNode->pnext;
	//fprintf(fp,"等级 姓名 性别 手机号 生日 商品1消费额 商品2消费额 商品3消费额 总消费额 积分 偏好 优惠券\n");
	while(move!=NULL){
		fprintf(fp,"%c %s %s %s %d/%d/%d %d %d %d %d %d %s %s\n",move->data.rank,move->data.name,move->data.gender,move->data.phonenumber,move->data.link.year,move->data.link.month,move->data.link.day,move->data.cost.goods1cost,move->data.cost.goods2cost,move->data.cost.goods3cost,move->data.cost.totalcost,move->data.thing2.integral,move->data.thing2.likes,move->data.thing2.coupon);
		move=move->pnext;
	}
	
	//关闭文件 
	fclose(fp);
}
//读取文件操作 
void readInfo(char *filename,struct Node*headNode){
	//fscanf 返回EOF 
	FILE *fp = fopen(filename,"r");
	if(fp==NULL){
		fp = fopen(filename,"w");
		fclose(fp);
		return;
	}
	struct number temp;
	//"等级 姓名 性别 手机号码 生日 商品1消费额 商品2消费额 商品3消费额 总消费额 积分 偏好 优惠券\n"
	while(fscanf(fp,"%c %s %s %s %d/%d/%d %d %d %d %d %d %s %s\n",&temp.rank,temp.name,temp.gender,&temp.phonenumber,&temp.link.year,&temp.link.month,&temp.link.day,&temp.cost.goods1cost,&temp.cost.goods2cost,&temp.cost.goods3cost,&temp.cost.totalcost,&temp.thing2.integral,temp.thing2.likes,temp.thing2.coupon)!=EOF){
		insertInfo(list,temp);	
	}
	
	fclose(fp);
}
//总览全部信息 
void showlist(struct Node*headNode){
	struct Node *move = headNode->pnext;
	//printf("等级 姓名 性别 手机号码 生日 商品1消费额 商品2消费额 商品3消费额 总消费额 积分 偏好 优惠券\n");
	while(move!=NULL){
		printf("%c\t%s\t%s\t%s\t%d/%d/%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\n",move->data.rank,move->data.name,move->data.gender,move->data.phonenumber,move->data.link.year,move->data.link.month,move->data.link.day,move->data.cost.goods1cost,move->data.cost.goods2cost,move->data.cost.goods3cost,move->data.cost.totalcost,move->data.thing2.integral,move->data.thing2.likes,move->data.thing2.coupon);
		move=move->pnext;
	}
}
//筛选优质会员信息 
void showlistplus(struct Node*headNode){
	struct Node *move= headNode->pnext;
	
	while(move!=NULL){
		if(move->data.cost.totalcost>=4000){
			printf("%c\t%s\t%d\t%d\t优质会员\n",move->data.rank,move->data.name,move->data.cost.totalcost,move->data.thing2.integral);
		}
		move=move->pnext;
	}
}
//筛选信息 
void showlistplus2(struct Node*headNode){
	struct Node *move= headNode->pnext;
	
	while(move!=NULL){
		if(move->data.cost.totalcost>=4000){
			printf("%c\t%s\t%d\t%d\t%s\t优质会员\n",move->data.rank,move->data.name,move->data.cost.totalcost,move->data.thing2.integral,move->data.thing2.likes);
		}
		move=move->pnext;
	}
}
//进行数据分析 
void analysis(struct number *temp){
	temp->cost.totalcost=(temp->cost.goods1cost)+(temp->cost.goods2cost)+(temp->cost.goods3cost);
	temp->thing2.integral=(temp->cost.totalcost)*2;
	if(temp->thing2.integral>=500&&temp->thing2.integral<1000){
		temp->rank='D';
		strcpy(temp->thing2.coupon,"30元代金券3张"); 
	}else if(temp->thing2.integral>=1000&&temp->thing2.integral<2000){
		temp->rank='C';
		strcpy(temp->thing2.coupon,"40元代金券4张");
	}else if(temp->thing2.integral>=2000&&temp->thing2.integral<4000){
		temp->rank='B';
		strcpy(temp->thing2.coupon,"80元代金券5张");
	}else if(temp->thing2.integral>=4000){
		temp->rank='A';
		strcpy(temp->thing2.coupon,"200元代金券6张");
	}else{
		temp->rank='E';
		strcpy(temp->thing2.coupon,"10元代金券5张"); 
	}
	if(temp->cost.goods1cost>temp->cost.goods2cost){
		if(temp->cost.goods3cost>temp->cost.goods1cost){
			strcpy(temp->thing2.likes,"商品3"); 
		}else{
			strcpy(temp->thing2.likes,"商品1"); 
		}
	}else{
		if(temp->cost.goods3cost>temp->cost.goods2cost){
			strcpy(temp->thing2.likes,"商品3"); 
		}else{
			strcpy(temp->thing2.likes,"商品2"); 
		}
	}
	
}
//进行修改数据后的数据分析 
void analysisplus(struct Node *temp){
	temp->data.cost.totalcost=(temp->data.cost.goods1cost)+(temp->data.cost.goods2cost)+(temp->data.cost.goods3cost);
	temp->data.thing2.integral=(temp->data.cost.totalcost)*2;
	if(temp->data.thing2.integral>=500&&temp->data.thing2.integral<1000){
		temp->data.rank='D';
		strcpy(temp->data.thing2.coupon,"30元代金券3张");
	}else if(temp->data.thing2.integral>=1000&&temp->data.thing2.integral<2000){
		temp->data.rank='C';
		strcpy(temp->data.thing2.coupon,"40元代金券4张");
	}else if(temp->data.thing2.integral>=2000&&temp->data.thing2.integral<4000){
		temp->data.rank='B';
		strcpy(temp->data.thing2.coupon,"80元代金券5张");
	}else if(temp->data.thing2.integral>=4000){
		temp->data.rank='A';
		strcpy(temp->data.thing2.coupon,"200元代金券6张");
	}else{
		temp->data.rank='E';
		strcpy(temp->data.thing2.coupon,"10元代金券5张"); 
	}
	
	if(temp->data.cost.goods1cost>temp->data.cost.goods2cost){
		if(temp->data.cost.goods3cost>temp->data.cost.goods1cost){
			strcpy(temp->data.thing2.likes,"商品3"); 
		}else{
			strcpy(temp->data.thing2.likes,"商品1"); 
		}
	}else{
		if(temp->data.cost.goods3cost>temp->data.cost.goods2cost){
			strcpy(temp->data.thing2.likes,"商品3"); 
		}else{
			strcpy(temp->data.thing2.likes,"商品2"); 
		}
	}
	
	 
}
//打印菜单 
void menu(){
	 printf("|*============================================*|\n");
	 printf("|*            欢迎使用会员管理系统            *|\n");
	 printf("|*============================================*|\n");
	 printf("|*    1.录入会员信息                          *|\n");
	 printf("|*    2.查找会员信息                          *|\n");
	 printf("|*    3.修改会员信息                          *|\n");
	 printf("|*    4.删除会员                              *|\n");
     printf("|*    5.会员消费奖励                          *|\n");
	 printf("|*    6.优质会员筛选                          *|\n");
	 printf("|*    7.优质会员商品推荐                      *|\n");
	 printf("|*    8.速览会员信息                          *|\n");
	 printf("|*    0.退出系统                              *|\n");
	 printf("|*============================================*|\n");
	 printf("     请输入功能选项0-8\n");
	 
}
//姓名查找函数 
struct Node* SearchByName(struct Node* headNode,char *name){
	struct Node *move = headNode->pnext;
	
	while(move!=NULL){
		if(strcmp(move->data.name,name)==0)break;
		move=move->pnext;
	}
	return move;
}
//手机号码查找函数 
struct Node* SearchByphonenumber(struct Node* headNode,char *number){
	struct Node *move = headNode->pnext;
	
	while(move!=NULL){
		if(strcmp(move->data.phonenumber,number)==0)break;
		move=move->pnext;
	}
	return move;
}
//删除函数 
void deleteByname(struct Node* headNode, char *name){
	struct Node *move = headNode->pnext;
	struct Node *pre = headNode;
	
	while(move!=NULL){
		if(strcmp(move->data.name,name)==0)break;
		pre = move;
		move=move->pnext;
	}
	if(move==NULL){
		return ;
	}else{
		printf("----------删除成功!------------\n"); 
		pre->pnext=move->pnext;
		free(move);
		move=NULL;
	}
	
	
}
//修改信息功能菜单 
void menuone(){
	printf("请问要修改的会员信息:\n");
	printf("1.姓名\n");
	printf("2.手机号码\n");
	printf("3.商品1消费额\n");
	printf("4.商品2消费额\n");
	printf("5.商品3消费额\n");
}

//总体的key事件,用于功能选择 

void keyEvent(){

	 struct number temp;
	 struct Node* result;
	 int key2=0;
	 printf("请输入选项:"); 
	 scanf("%d", &key);
	 switch (key) {
	 case 1: 
	    printf("您选择的功能是 [录入会员信息] \n");
	    printf("录入的会员信息 姓名,性别,手机号码,生日(Year/Month/Day),商品1消费额,商品2消费额,商品3花费消费额\n");
	    printf("请输入姓名:");
	    scanf("%s",temp.name);
	    
	    printf("请输入性别:");
	    scanf("%s",temp.gender);
	    getchar();
	    
	    printf("请输入手机号码:");
	    scanf("%s",temp.phonenumber);
	    
	    printf("请输入生日:");
	    scanf("%d/%d/%d",&temp.link.year,&temp.link.month,&temp.link.day);
	    
	    printf("请输入商品1消费额度:");
		scanf("%d",&temp.cost.goods1cost); 
		
		printf("请输入商品2消费额度:");
		scanf("%d",&temp.cost.goods2cost); 
		
		printf("请输入商品3消费额度:"); 
		scanf("%d",&temp.cost.goods3cost); 
		//分析数据 
		analysis(&temp);
		//同步到链表中
		insertInfo(list,temp);
		//同步文件
		saveInfo("numberInfo.txt",list);
		break;    
	 case 2: 
	 	printf("您选择的功能是 [查找会员信息] \n");
	 	printf("请选择以那种方式查找:\n");
	 	printf("1.姓名查找\n");
	 	printf("2.手机号码查找\n");
	 	printf("选择方式: ");
	 	scanf("%d",&key2);
	 	switch(key2){
	 		case 1:
	 			printf("查询的会员姓名:");
				scanf("%s",temp.name);
				result=SearchByName(list,temp.name);
				break;
	 		case 2:
				printf("查询的会员手机号码:");
				scanf("%s",temp.phonenumber);
				result=SearchByphonenumber(list,temp.phonenumber);
				break;
			default:break;
			}
		if(result==NULL){
			printf("----------未找到此会员----------\n");
		} else{
			printf("等级\t姓名\t性别\t手机号码\t生日\t\t商品1消费额\t商品2消费额\t商品3消费额\t总消费额\t积分\t偏好\t优惠券\n");
			printf("%c\t%s\t%s\t%s\t%d/%d/%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\n",result->data.rank,result->data.name,result->data.gender,result->data.phonenumber,result->data.link.year,result->data.link.month,result->data.link.day,result->data.cost.goods1cost,result->data.cost.goods2cost,result->data.cost.goods3cost,result->data.cost.totalcost,result->data.thing2.integral,result->data.thing2.likes,result->data.thing2.coupon);
		}
		break;                
	 case 3: 
	 	printf("您选择的功能是 [修改会员信息] \n");
	 	printf("请选择以那种方式查找:\n");
	 	printf("1.姓名查找\n");
	 	printf("2.手机号码查找\n");
	 	printf("选择方式: ");
	 	scanf("%d",&key2);
	 	switch(key2){
	 		case 1:
	 			printf("查询的会员姓名:");
				scanf("%s",temp.name);
				result=SearchByName(list,temp.name);
				break;
	 		case 2:
				printf("查询的会员手机号码:");
				scanf("%s",temp.phonenumber);
				result=SearchByphonenumber(list,temp.phonenumber);
				break;
			default:break;
			}
		if(result==NULL){
			printf("----------未找到此会员----------\n");
		} else{
			printf("等级\t姓名\t性别\t手机号码\t生日\t\t商品1消费额\t商品2消费额\t商品3消费额\t总消费额\t积分\t偏好\t优惠券\n");
			printf("%c\t%s\t%s\t%s\t%d/%d/%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\n",result->data.rank,result->data.name,result->data.gender,result->data.phonenumber,result->data.link.year,result->data.link.month,result->data.link.day,result->data.cost.goods1cost,result->data.cost.goods2cost,result->data.cost.goods3cost,result->data.cost.totalcost,result->data.thing2.integral,result->data.thing2.likes,result->data.thing2.coupon);
			
			menuone();
			printf("请选择: ");
			int key3=0;
			scanf("%d",&key3);
			int cost;
			switch(key3){
				case 1:
					printf("新名字:"); 
					char newname[10];
					scanf("%s",newname);
					strcpy(result->data.name,newname); 
					saveInfo("numberInfo.txt",list);
					break;
				case 2:
					printf("新手机号码:");
					char newnumber[20];
					scanf("%s",newnumber);
					strcpy(result->data.phonenumber,newnumber); 
					saveInfo("numberInfo.txt",list);
					break;
				case 3:
					printf("商品1新消费额:");
					scanf("%d",&cost);
					result->data.cost.goods1cost=cost;
					analysisplus(result);
					saveInfo("numberInfo.txt",list);
					break;
				case 4:
					printf("商品2新消费额:");
					scanf("%d",&cost);
					result->data.cost.goods2cost=cost;
					analysisplus(result); 
					saveInfo("numberInfo.txt",list);
					break;
				case 5:
					printf("商品3新消费额:");
					scanf("%d",&cost);
					result->data.cost.goods3cost=cost;
					analysisplus(result);
					saveInfo("numberInfo.txt",list);
					break;
				default:break;
			}
		}
		
		break;
	 case 4: 
	 	printf("您选择的功能是 [删除会员信息] \n");
	 	printf("等级\t姓名\t性别\t手机号码\t生日\t\t商品1消费额\t商品2消费额\t商品3消费额\t总消费额\t积分\t偏好\t优惠券\n");
	 	showlist(list); 
	 	printf("删除的会员的姓名:");
		scanf("%s",temp.name);
		deleteByname(list,temp.name); 
		saveInfo("numberInfo.txt",list);
		break;    
	 case 5: 
	 	printf("您选择的功能是 [会员消费奖励查询] \n");
	 	printf("请选择以那种方式查找:\n");
	 	printf("1.姓名查找\n");
	 	printf("2.手机号码查找\n");
	 	printf("选择方式: ");
	 	scanf("%d",&key2);
	 	switch(key2){
	 		case 1:
	 			printf("查询的会员姓名:");
				scanf("%s",temp.name);
				result=SearchByName(list,temp.name);
				break;
	 		case 2:
				printf("查询的会员手机号码:");
				scanf("%s",temp.phonenumber);
				result=SearchByphonenumber(list,temp.phonenumber);
				break;
			default:break;
			}
		if(result==NULL){
			printf("----------未找到此会员----------\n");
		} else{
			printf("等级\t姓名\t性别\t手机号码\t生日\t总消费额\t积分\t偏好\t优惠券\n");
			printf("%c\t%s\t%s\t%s\t%d/%d/%d\t%d\t%d\t%s\t%s\n",result->data.rank,result->data.name,result->data.gender,result->data.phonenumber,result->data.link.year,result->data.link.month,result->data.link.day,result->data.cost.totalcost,result->data.thing2.integral,result->data.thing2.likes,result->data.thing2.coupon);
		}
		break;  
	 case 6: 
	 	printf("您选择的功能是 [优质会员筛选] \n");
	 	printf("等级\t姓名\t总消费额\t积分\n");
	 	showlistplus(list);
		break;
	 case 7: 
	    printf("您选择的功能是 [优质会员商品推荐] \n");
		printf("等级\t姓名\t总消费额\t积分\t偏好\n");
	 	showlistplus2(list);
		break;           
	 case 8:
	 	printf("您选择的功能是 [速览会员信息] \n"); 
	 	printf("等级\t姓名\t性别\t手机号码\t生日\t\t商品1消费额\t商品2消费额\t商品3消费额\t总消费额\t积分\t偏好\t优惠券\n");
	 	showlist(list); 
	 	break;             
	 case 0: break;   
	 default:printf("选项不存在,请重新选择");break;
	 }
     
}

你可能感兴趣的:(项目设计,c语言,开发语言)