当前位置:文档之家› c语言网吧计费系统源代码

c语言网吧计费系统源代码

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>#define N 5struct user{char ID_card[30];char user_card[10];char user_level[50];float add_money; //充值};struct LinkList{struct user struct_user;LinkList *pNext;};struct control{char control_name[20];char control_password[15];}control_person={"apollo","apollo"};//管理员账户和密码设置////////////////////////////////void enter(int x);void tab(int x);void start();void login();void mainmenu();void submenu1();void submenu2();void submenu3();void submenu4();void xian_shi(LinkList *pHead);LinkList *adduser(LinkList *pHead);LinkList *addmoney(LinkList *pHead); //充值LinkList *shang_wang(LinkList *pHead); //上网LinkList *zhu_xiao(LinkList *pHead); //注销会员void save(LinkList *pTemp);LinkList *readsave();void cha_xun_shen(LinkList *pHead);void cha_xun_hui(LinkList *pHead);///////////////////////启动void start(){system("cls");for(int k=0;k<2;k++){for(int i=0;i<N;i++){system("color B");enter(7);tab(3);printf(" 星星网吧计费管理系统");enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 1 endenter(7);tab(3);printf(" 星星网吧计费管理系统");enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 2 endenter(7);tab(3);printf(" 星星网吧计费管理系统");enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 3 endenter(7);tab(3);printf(" 星星网吧计费管理系统"); enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 4 endenter(7);tab(3);printf(" 星星网吧计费管理系统"); enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 5 endenter(7);tab(3);printf(" 星星网吧计费管理系统"); enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 6 endenter(7);tab(3);printf(" 星星网吧计费管理系统"); enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 7 endenter(7);tab(3);printf(" 星星网吧计费管理系统");enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 8 endenter(7);tab(3);printf(" 星星网吧计费管理系统");enter(2);tab(4);printf(" ■");enter(1);tab(4);for(i=0;i<100000000;i++){}system("cls"); //circle 9 end }}login();}//登陆函数void login(){char name[20];char password[15];while(1){system("cls");enter(7);tab(3);printf(" 管理员登录");enter(2);tab(4);printf("Count:");fflush(stdin);if(strcmp(gets(name),control_person.control_name)==0){leap: system("cls");enter(7);tab(3);printf(" 管理员登录");enter(2);tab(4);printf("Password:");fflush(stdin);if(strcmp(gets(password),control_person.control_password)==0){mainmenu();break;}else{char ch;tab(4);printf("Your password is error!\n");tab(4);printf("Do you want to try again?(Y/N):");scanf("%c",&ch);if(ch=='Y' || ch=='y')goto leap;else if(ch=='N' || ch=='n')exit(0);else{system("cls");enter(7);tab(1);printf("Error!Please check your code then login again,thank you!\n");tab(3);exit(0);}}}else{char i;system("cls");enter(7);tab(4);printf("Your count is erorr!\n");tab(4);printf("Do you want to try again?(Y/N):");scanf("%c",&i);if(i=='Y' || i=='y')continue;else if(i=='N' || i=='n')exit(0);else{system("cls");enter(7);tab(1);printf("Error!Please check your code then login again,thank you!\n");tab(3);exit(0);}}}}//enter函数void enter(int x){for(int i=0;i<x;i++)printf("\n");}//tab函数void tab(int x){for(int i=0;i<x;i++)printf("\t");}//mainmenu主菜单void mainmenu(){struct LinkList *pHead=NULL; //初始化while(1){int i;system("cls");printf("\n\n\n\n\n\t\t\t********星星网吧计费管理系统*********\n");printf("\t\t\t** 1.注册会员**\n");printf("\t\t\t** **\n");printf("\t\t\t** 2.会员管理**\n");printf("\t\t\t** **\n");printf("\t\t\t** 3.注销**\n");printf("\t\t\t** **\n");printf("\t\t\t** 4.重启**\n");printf("\t\t\t** **\n");printf("\t\t\t** 5.关闭系统**\n");printf("\t\t\t*************************************\n");printf("\t\t\t请选择:");fflush(stdin);scanf("%d",&i);switch(i){case 1:pHead=adduser(pHead);break;case 2:submenu1();break;case 3:login();break;case 4:start();break;case 5:submenu2();break;default:printf("输入错误!\n");for(int j=0;j<100000000;j++){}break;}}}//submenu1会员管理菜单void submenu1(){struct LinkList *pHead=NULL;while(1){int i;system("cls");printf("\n\n\n\n\n\t\t\t**************会员管理***************\n");printf("\t\t\t** 1.会员消费**\n");printf("\t\t\t** **\n");printf("\t\t\t** 2.注销会员**\n");printf("\t\t\t** **\n");printf("\t\t\t** 3.查找会员信息**\n");printf("\t\t\t** **\n");printf("\t\t\t** 4.查询所有会员信息**\n");printf("\t\t\t** **\n");printf("\t\t\t** 5.返回上一级菜单**\n");printf("\t\t\t*************************************\n");printf("\t\t\t请选择:");fflush(stdin);scanf("%d",&i);switch(i){case 1:submenu3();break;case 2:pHead=zhu_xiao(pHead);break;case 3:submenu4();break;case 4:;xian_shi(pHead);break;case 5:mainmenu();break;default:printf("输入错误!\n");for(int j=0;j<100000000;j++){}break;}}}//submenu2关闭系统void submenu2(){system("cls");printf("\n\n\n\n\n\t\t\t********星星网吧计费管理系统*********\n");printf("\t\t\t** 谢谢您的使用! **\n");printf("\t\t\t** **\n");printf("\t\t\t** 欢迎再次使用! **\n");printf("\t\t\t** **\n");printf("\t\t\t** 技术支持: **\n");printf("\t\t\t** **************************\n");printf("\t\t\t** 版权所有: **\n");printf("\t\t\t** 湖南长沙英泰学院09081A班**\n");printf("\t\t\t** 2009.10 **\n");printf("\t\t\t*************************************\n");exit(0);}//submenu3消费菜单void submenu3(){int i;LinkList *pHead=NULL;while(1){system("cls");printf("\n\n\n\n\n\t\t\t**********消费内容*******************\n");printf("\t\t\t** 1.充值**\n");printf("\t\t\t** **\n");printf("\t\t\t** 2.上网**\n");printf("\t\t\t** **\n");printf("\t\t\t** 3.返回上一级菜单**\n");printf("\t\t\t*************************************\n");printf("\t\t\t请选择:");fflush(stdin);scanf("%d",&i);switch(i){case 1:pHead=addmoney(pHead);break;case 2:pHead=shang_wang(pHead);break;case 3:submenu1();break;default:printf("输入错误!请重新输入!\n");for(int j=0;j<100000000;j++){}break;}}}//submenu4会员查找函数void submenu4(){int i;LinkList *pHead=NULL;while(1){system("cls");printf("\n\n\n\n\n\t\t\t**************查找会员***************\n");printf("\t\t\t** 1.按身份证号码查找**\n");printf("\t\t\t** **\n");printf("\t\t\t** 2.按会员卡号号码查找**\n");printf("\t\t\t** **\n");printf("\t\t\t** 3.返回上一级菜单**\n");printf("\t\t\t*************************************\n");printf("\t\t\t请选择:");fflush(stdin);scanf("%d",&i);switch(i){case 1:cha_xun_shen(pHead);break;case 2:cha_xun_hui(pHead);break;case 3:submenu1();break;default:printf("输入错误!请重新输入!\n");for(int j=0;j<100000000;j++){}break;}}}//新会员注册LinkList *adduser(LinkList *pHead){LinkList *pTemp,*p;system("cls");pTemp=(LinkList *)malloc(sizeof(struct LinkList));if(pTemp==NULL)return pHead;leap:printf("\n\n\n\n\t\t");printf("输入第二代身份证号码(18位):");fflush(stdin);gets(pTemp->struct_user.ID_card);for(int i=0;i<17;i++){if(pTemp->struct_user.ID_card[i]>'9' || pTemp->struct_user.ID_card[i]<'0') //如果输入的信息大于9小于0的范围(输入的不是数字){system("cls");printf("输入的不是纯数字!\n请重新输入!\n");goto leap;}else if(strlen(pTemp->struct_user.ID_card)!=18 || strlen(pTemp->struct_user.ID_card)==0){system("cls");printf("输入不合法!\n请重新输入!\n");goto leap;}}loop:printf("\n\t\t");printf("请输入卡号(8位):");fflush(stdin);gets(pTemp->struct_er_card);for(i=0;i<8;i++){if(pTemp->struct_er_card[i]>'9' || pTemp->struct_er_card[i]<'0') //如果输入的信息大于9小于0的范围(输入的不是数字){system("cls");tab(3);printf("输入的不是纯数字!\n请重新输入!\n");goto loop;}else if(strlen(pTemp->struct_er_card)!=8 || strlen(pTemp->struct_er_card)==0){system("cls");printf("输入不合法!\n请重新输入!\n");goto loop;}}k: printf("\n\n\t\t|-----------会员优惠活动------------|\n");printf("\t\t| 普通会员>0 <=10元|\n");printf("\t\t| 铜卡会员>10 <=20元+10元|\n");printf("\t\t| 银卡会员>20 <=30元+20元|\n");printf("\t\t| 金卡会员>30 <=50元+30元|\n");printf("\t\t| VIP会员充100元送80元|\n");printf("\t\t|-----------------------------------|\n");printf("\t\t");printf("充值:");fflush(stdin);scanf("%f",&(pTemp->struct_user.add_money)); //充值if(pTemp->struct_user.add_money>1000 || pTemp->struct_user.add_money<=0) //如果输入的信息大于9小于0的范围(输入的不是数字){system("cls");printf("输入错误!\n请重新输入!\n");goto k;}else if(pTemp->struct_user.add_money>0 && pTemp->struct_user.add_money<=10){tab(2);strcpy(pTemp->struct_er_level,"普通会员");printf("■恭喜你!你已成为本网吧普通会员!■\n");}else if(pTemp->struct_user.add_money>10 && pTemp->struct_user.add_money<=20){tab(2);strcpy(pTemp->struct_er_level,"铜卡会员");printf("■恭喜你!你已成为本网吧铜卡会员!■\n");pTemp->struct_user.add_money+=10;}else if(pTemp->struct_user.add_money>20 && pTemp->struct_user.add_money<=30) {tab(2);strcpy(pTemp->struct_er_level,"银卡会员");printf("■恭喜你!你已成为本网吧银卡会员!■\n");pTemp->struct_user.add_money+=20;}else if(pTemp->struct_user.add_money>=30 && pTemp->struct_user.add_money<100) {tab(2);strcpy(pTemp->struct_er_level,"金卡会员");printf("■恭喜你!你已成为本网吧金卡会员!■\n");pTemp->struct_user.add_money+=30;}else if(pTemp->struct_user.add_money>=100){tab(2);strcpy(pTemp->struct_er_level,"VIP会员");printf("■恭喜你!你已成为本网吧VIP会员!■\n");pTemp->struct_user.add_money+=80;}pTemp->pNext=NULL;//////////////////if(pHead==NULL)pHead=pTemp;else{p=pHead;while(p->pNext!=NULL)p=p->pNext;p->pNext=pTemp;}save(pTemp);return pHead;}//保存会员注册void save(LinkList *pTemp){FILE *fp=fopen("user","ab");if(fp==NULL){tab(3);printf("读取失败!\n");exit(0);}tab(3);printf("开始保存文件!\n");if(fwrite(pTemp,sizeof(struct LinkList),1,fp)==1){tab(3);printf("文件保存成功!\n");getch();}else{tab(3);printf("文件保存失败!\n");getch();}fclose(fp);}//读取保存LinkList *readsave(){LinkList *pHead=NULL,*p;FILE *fp;fp=fopen("user","rb");if(fp==NULL){tab(3);printf("文件打开失败!\n");getch();return pHead;}while(!feof(fp)){LinkList *pTemp=(LinkList*)malloc(sizeof(LinkList));int t=fread(pTemp,sizeof(struct LinkList),1,fp);pTemp->pNext=NULL;if(t>0){if(pHead==NULL){pHead=pTemp;}else{p=pHead;while(p->pNext!=NULL)p=p->pNext;p->pNext=pTemp;}}elsebreak;}fclose(fp);return pHead;}//显示所有会员信息void xian_shi(LinkList *pHead){FILE *fp=fopen("user","rb");if(fp==NULL){system("cls");printf("\n\n\n\n\n\n\n\n\t\t\t\t");printf("没有会员信息!\n");getch();return;}LinkList *pTemp,*p;pTemp=(LinkList *)malloc(sizeof(LinkList));int count=0;system("cls");enter(5);printf(" -----------------------|-------------|--------------|--------------\n");printf("\t身份证号码\t\t会员卡号\t卡上余额\t会员级别\n");printf(" -----------------------|-------------|--------------|--------------\n");while(!feof(fp)){int t=fread(pTemp,sizeof(LinkList),1,fp);pTemp->pNext=NULL;//////////////////if(t>0){count++;if(pHead==NULL){pHead=pTemp;}else{p=pHead;while(p->pNext!=NULL)p=p->pNext;p->pNext=pTemp;}}else{break;}printf("\t%-20s\t%-10s\t%-5.1f元\t\t%-6s\n",pTemp->struct_user.ID_card,pTemp->struct_er_card,pTemp->struct_user.add_ money,pTemp->struct_er_level);}printf(" -----------------------|-------------|--------------|--------------\n");printf("\n\t\t共有会员%d个\n",count);getch();fclose(fp);}//查找会员信息(按身份证号码查找)void cha_xun_shen(LinkList *pHead){LinkList *pTemp;char shen_fen[100];system("cls");enter(9);tab(3);printf("身份证号码:");fflush(stdin);gets(shen_fen);if(strlen(shen_fen)!=18){tab(3);printf("输入错误!\n");getch();return;}pHead=readsave();if(pHead==NULL){tab(3);printf("没有找到会员信息或会员不存在!\n");getch();return;}pTemp=pHead;while(pTemp){if(strcmp(pTemp->struct_user.ID_card,shen_fen)==0){system("cls");enter(5);printf(" -----------------------|-------------|--------------|--------------\n");printf("\t身份证号码\t\t会员卡号\t卡上余额\t会员级别\n");printf(" -----------------------|-------------|--------------|--------------\n");printf("\t%-20s\t%-10s\t%-5.1f元\t\t%-6s\n",pTemp->struct_user.ID_card,pTemp->struct_er_card,pTemp->struct_user.add_ money,pTemp->struct_er_level);printf(" -----------------------|-------------|--------------|--------------\n");getch();break;}pTemp=pTemp->pNext;}}//查找会员信息(按会员卡号查找)void cha_xun_hui(LinkList *pHead){LinkList *pTemp;char shen_fen[100];system("cls");enter(9);tab(3);printf("卡号(8位:");fflush(stdin);gets(shen_fen);if(strlen(shen_fen)!=8){tab(3);printf("输入错误!\n");getch();return;}pHead=readsave();if(pHead==NULL)tab(3);printf("没有找到会员信息或会员不存在!\n");getch();return;}pTemp=pHead;while(pTemp){if(strcmp(pTemp->struct_er_card,shen_fen)==0){system("cls");enter(5);printf(" -----------------------|-------------|--------------|--------------\n");printf("\t身份证号码\t\t会员卡号\t卡上余额\t会员级别\n");printf(" -----------------------|-------------|--------------|--------------\n");printf("\t%-20s\t%-10s\t%-5.1f元\t\t%-6s\n",pTemp->struct_user.ID_card,pTemp->struct_er_card,pTemp->struct_user.add_ money,pTemp->struct_er_level);printf(" -----------------------|-------------|--------------|--------------\n");getch();break;}pTemp=pTemp->pNext;}}//保存充值、注销和上网消费后的后的会员信息void save_chong(LinkList *pHead){FILE *fp=fopen("user","wb");if(fp==NULL){tab(3);printf("文件打开失败!\n");getch();return;}LinkList *pTemp;pTemp=pHead;if(pHead==NULL){printf("没有找到会员信息!\n");getch();return;printf("开始保存修改!\n");while(pTemp){fwrite(pTemp,sizeof(LinkList),1,fp);pTemp=pTemp->pNext;}printf("保存成功!\n");getch();fclose(fp);}//充值LinkList *addmoney(LinkList *pHead){LinkList *pTemp;char shen_fen[100];system("cls");enter(9);tab(3);printf("卡号(8位):");fflush(stdin);gets(shen_fen);if(strlen(shen_fen)!=8){tab(3);printf("输入错误!\n");getch();return pHead;}pHead=readsave(); //very importantif(pHead==NULL){tab(3);printf("没有找到会员信息或会员不存在!\n");getch();return pHead;}pTemp=pHead;while(pTemp){if(strcmp(pTemp->struct_er_card,shen_fen)==0){system("cls");enter(5);printf(" -----------------------|-------------|--------------|--------------\n");printf("\t身份证号码\t\t会员卡号\t卡上余额\t会员级别\n");printf(" -----------------------|-------------|--------------|--------------\n");printf("\t%-20s\t%-10s\t%-5.1f元\t\t%-6s\n",pTemp->struct_user.ID_card,pTemp->struct_er_card,pTemp->struct_user.add_ money,pTemp->struct_er_level);printf(" -----------------------|-------------|--------------|--------------\n");float m=pTemp->struct_user.add_money;printf("请输入充值金额:");scanf("%f",&(pTemp->struct_user.add_money));pTemp->struct_user.add_money+=m;save_chong(pHead);break;}pTemp=pTemp->pNext;}return pHead;}//上网LinkList *shang_wang(LinkList *pHead){LinkList *pTemp;char shen_fen[100];system("cls");enter(2);printf("\n\n\n\n\t\t\t**********网吧计费管理系统***********\n");printf("\t\t\t** 1.普通会员3元/时**\n");printf("\t\t\t** **\n");printf("\t\t\t** 2.铜卡会员 2.5元/时**\n");printf("\t\t\t** **\n");printf("\t\t\t** 3.银卡会员2元/时**\n");printf("\t\t\t** **\n");printf("\t\t\t** 4.金卡会员 1.5元/时**\n");printf("\t\t\t** **\n");printf("\t\t\t** 5.VIP会员1元/时**\n");printf("\t\t\t*************************************\n");printf("请输入会员卡号码(8位数字):");fflush(stdin);gets(shen_fen);if(strlen(shen_fen)!=8){tab(3);printf("输入错误!\n");getch();return pHead;}pHead=readsave(); //读取文件if(pHead==NULL) //如果头指针为空,说明没有该链表{tab(3);printf("没有找到会员信息或会员不存在!\n");getch();return pHead;}pTemp=pHead; //头指针不为空while(pTemp) //访问节点{if(strcmp(pTemp->struct_er_card,shen_fen)==0) //如果找到与输入的会员卡号相同{ //则输出该会员信息printf(" -----------------------|-------------|--------------|--------------\n");printf("\t身份证号码\t\t会员卡号\t卡上余额\t会员级别\n");printf(" -----------------------|-------------|--------------|--------------\n");printf("\t%-20s\t%-10s\t%-5.1f元\t\t%-6s\n",pTemp->struct_user.ID_card,pTemp->struct_er_card,pTemp->struct_user.add_ money,pTemp->struct_er_level);printf(" -----------------------|-------------|--------------|--------------\n");float m=pTemp->struct_user.add_money;//上网前的卡上余额float time;printf("请输入上网时间(时):");fflush(stdin);scanf("%f",&time);if(strcmp(pTemp->struct_er_level,"普通会员")==0) //按会员级别来管理{ //每小时上网的费用pTemp->struct_user.add_money=m-3*time; //上网后的卡上余额save_chong(pHead); //保存修改后的内容break;}else if(strcmp(pTemp->struct_er_level,"铜卡会员")==0){pTemp->struct_user.add_money=m-2.5f*time;save_chong(pHead);break;}else if(strcmp(pTemp->struct_er_level,"银卡会员")==0){pTemp->struct_user.add_money=m-2*time;save_chong(pHead);break;}else if(strcmp(pTemp->struct_er_level,"金卡会员")==0){pTemp->struct_user.add_money=m-1.5f*time;save_chong(pHead);break;}else if(strcmp(pTemp->struct_er_level,"VIP会员")==0){pTemp->struct_user.add_money=m-1*time;save_chong(pHead);break;}}pTemp=pTemp->pNext;//指针指向下一个查找,直到找到满足上面条件为止}return pHead;}//注销会员LinkList *zhu_xiao(LinkList *pHead){LinkList *pTemp,*p;char shen_fen[100];system("cls");enter(9);tab(3);printf("卡号:");fflush(stdin);gets(shen_fen);pHead=readsave(); //读取文件if(pHead==NULL) //如果头节点为空,表示这条链表没有内容,或者没有这条链表{tab(3);printf("没有找到会员信息或会员不存在!\n");return pHead;}pTemp=pHead; //指针指向头节点while(pTemp)//访问节点{if(strcmp(pTemp->struct_er_card,shen_fen)==0)//寻找要删除的会员卡号,找到后输出{system("cls");enter(5);printf(" -----------------------|-------------|--------------|--------------\n");printf("\t身份证号码\t\t会员卡号\t卡上余额\t会员级别\n");printf(" -----------------------|-------------|--------------|--------------\n");printf("\t%-20s\t%-10s\t%-5.1f元\t\t%-6s\n",pTemp->struct_user.ID_card,pTemp->struct_er_card,pTemp->struct_user.add_ money,pTemp->struct_er_level);printf(" -----------------------|-------------|--------------|--------------\n");char ch;printf("\n你要注销该会员吗?(Y/N)\n");scanf("%c",&ch);switch(ch){case 'Y':case 'y':{if(pTemp==pHead) //如果要删除的是头节点{pHead=pTemp->pNext; //把头节点指针指向第二个节点,并把头节点覆盖printf("注销成功!\n");getch();break;}p=pHead;//不是头节点,把指针指向头节点while(1){if(p->pNext==pTemp) //如果p的指针域指向找到的节点pTemp{p->pNext=pTemp->pNext;//则把pTemp的指针域指向的下一个节点付给p的指针域printf("注销成功!\n");//删除成功getch();break;}p=p->pNext;//寻找p->pNext和要删除节点pTemp的交合}}break;case 'N':case 'n':break;}}pTemp=pTemp->pNext;//寻找shen_fen和节点的交合}save_chong(pHead);system("cls");return pHead;}//主函数void main(){start();mainmenu();}。

相关主题