/*极限俱乐部会员信息系统* #include "string. h #include "stdlib. h" #define Len sizeof (struct staff *自动求取sta结构的字节长度* struct staff char unit[60] char name[20] char sex[ 201 Int age, int weight truct staff *next int Inter face( char(*x)[20], int n); /*操作界面* struct staff*Add(struct staff) /增加会员数* struct staff*InsertAge( struct staff, struct staff ); /*按年龄由大到小插入链表* struct staff * InsertHeight(struct staf, struct staf);/*按身高由高到矮插入链表* struct staff *Insert Weight(struct staff*, struct staff) /*按体重由重到轻插入链表* struct staff*SortAge(struct staff*); /*按年龄大小排序* struct staff*SortHeight(struct staff /*按身高排序* struct staff*SortWeight(struct staff ) *按体重排序* void Display(struct staff ) /*显示已存在或者经操作后改变的数据* void Search(struct staff*); /*信息查找* void Modify(struct staff") /信息修改* struct staff*Delete(struct staff*) /*信息删除* oid Save File(struct staff ); /*信息存盘* struct staff *Load File(struct staff) /*加载文件* har password 8=7654321 设置系统管理员密码* struct staff *head=NULL. /*设置链首为空* nts;,/*设置变量,以用于用户输入信息的接收,并将其作为转向函数的参数* ar char menu[20}={"添加","显示”按年龄排序","按身高排序”, 按体重排序”,"检索","修改"”"删除""存盘""返回"}; /*****幸*幸**系统密码管理***幸本**幸幸春**
/*极限俱乐部会员信息系统*/ #include "stdio.h" #include "string.h" #include "stdlib.h" #define Len sizeof (struct staff) /*自动求取 staff 结构的字节长度*/ struct staff { char unit[60]; char name[20]; char sex[20]; int age; int height; int weight; struct staff *next; } ; int Interface(char (*x)[20],int n); /*操作界面*/ struct staff *Add(struct staff*); /*增加会员数*/ struct staff *InsertAge(struct staff*,struct staff*); /*按年龄由大到小插入链表*/ struct staff *InsertHeight(struct staff*,struct staff*); /*按身高由高到矮插入链表*/ struct staff *InsertWeight(struct staff*,struct staff*); /*按体重由重到轻插入链表*/ struct staff *SortAge(struct staff *); /*按年龄大小排序*/ struct staff *SortHeight(struct staff*); /*按身高排序*/ struct staff *SortWeight(struct staff*); /*按体重排序*/ void Display(struct staff*); /*显示已存在或者经操作后改变的数据*/ void Search (struct staff*); /*信息查找*/ void Modify(struct staff*); /*信息修改*/ struct staff *Delete(struct staff*); /*信息删除*/ void SaveFile(struct staff*); /*信息存盘*/ struct staff *LoadFile(struct staff*); /*加载文件*/ int n=0; char password[8]="7654321"; /*设置系统管理员密码*/ void main() { struct staff *head=NULL; /*设置链首为空*/ int s; /*设置变量,以用于用户输入信息的接收,并将其作为转向函数的参数*/ char openfile[10]; char choice; char menu[][20]={ "添加","显示","按年龄排序", "按身高排序", "按体重排序","检索","修改","删除","存盘","返回"}; /**********************系统密码管理********************/
do f printf("请输入管理员密码:n") scanf("%s"pass); if(lstrcmp(pass, password)) printf("PASSIn'n\n"); flag=1: break- printf("密码错误,请重新输入n") W-- i while(w>0) if( flag) printf("你已连续三次输入错误请确认后再使用本系统谢谢!n") exit(O) /****幸*幸***幸**幸*打开已有文件**春幸*幸本* printf("n打开已有的文件" 'staff4txt"?(y/n)”) if(strcmp(openfile, y)==NULL)) head=Load File( head) /*输入y,则调用 Loadfile(函数 输入n,则系统自动创建一个新文件* printi("系统自动创建一个新文件\" staff4.txt":Ⅶn"); system("cls"); /*用 system调用dos命令,清屏 printf(". ~~t pr It\tittle ~~~n printf("t欢迎进入极限俱乐部会员信息系统") pint%8%6%89%89%8%9898%98ot%898% %%%%‰%%%‰%%%%%%%%i") printf(
char pass[8]; int flag = 0; int w = 3; do{ printf("请输入管理员密码:\n"); scanf("%s",pass); if(!strcmp(pass,password)) { printf("PASS\n\n\n"); flag = 1; break; } else { printf("密码错误,请重新输入:\n"); w--; } }while(w>0); if(!flag) { printf("你已连续三次输入错误,请确认后再使用本系统,谢谢!\n"); exit(0); } /**********************打开已有文件********************/ printf ("\n 打开已有的文件\"staff_4.txt\"?(y/n)"); scanf("%s",openfile); if((strcmp(openfile,"y")==NULL)) { head=LoadFile(head); /*输入 y,则调用 LoadFile()函数*/ } else /*输入 n,则系统自动创建一个新文件*/ printf("系统自动创建一个新文件\"staff_4.txt\".\n"); system("cls"); /*用 system 调用 dos 命令,清屏*/ printf("~~~~~~~~~~~~~\t\t\t\t\t~~~~~~~~~~~~~\n"); printf("~~~~~~~~~~~~~\t\t\t\t\t~~~~~~~~~~~~~\n"); printf("\t\t 欢迎进入极限俱乐部会员信息系统\n"); printf("%%%%%%%%%%%%%%%%%%%%%%%%%%%\t\t\t\t\t%%%%%%%%%%% %%%%%%%%%%%%%%%%\n"); printf("-------------------------------");
printf("InInInin") printi("单位:北京极限俱乐部n"), printf("地址:北京西城区西四n”), printf("会员热线:010-6688668 printf("\ninInIn"); printf("= printf("本系统由“天地人和软件有限公司”开发n"), printi("地址:北京市海淀区学院路n") printf(“作者:天天n) printf("nIn"); printf"t请任意输入一个值并回车进入系统n) if(choice==n choice=N) t(1) system("cls"),/*用 system调用dos命令,清屏* sInterface(menu, 10) /*调用 Interface函数* switch(s) *转向语句,选择以实现不同的功能* case 0: head=Add(head) break case 1: Display (head); break; case 3: head-SortHeight(head); break; case 4: head=Sort Weight(head); break case 5: Search(head) break: case 6: Modify (head); break; case 7: Delete(head); break case 8: SaveFile(head) while(s>=0&&s<=8); 操作界面函数 ****本本家*******亲**幸幸本本*客*******举*幸幸******/
printf("\n\n\n\n"); printf("单位:北京极限俱乐部\n"); printf("地址:北京西城区西四\n"); printf("会员热线:010-66886688"); printf("\n\n\n\n"); printf("==============\t\t==============\n"); printf("本系统由“天地人和软件有限公司”开发\n"); printf("地址:北京市海淀区学院路\n"); printf(“作者:天天\n”); printf("==============\t\t==============\n"); printf("\n\n"); printf("\t\t 请任意输入一个值并回车进入系统\n"); scanf("%s",&choice); if(choice=='n'||choice=='N') { exit(1); } system("cls"); /*用 system 调用 dos 命令,清屏*/ do { s=Interface(menu,10); /*调用 Interface()函数*/ switch (s) /*转向语句,选择以实现不同的功能*/ { case 0: head=Add(head);break; case 1: Display(head);break; case 2: head=SortAge(head);break; case 3: head=SortHeight(head);break; case 4: head=SortWeight(head);break; case 5: Search(head);break; case 6: Modify(head);break; case 7: Delete(head);break; case 8: SaveFile(head); } } while(s>=0&&s<=8); } /**********************************************************\ 操作界面函数 \**********************************************************/
int Inter face( char(*x)[20], int n) printf("hn××××××x极限俱乐部会员信息系统X×××x××h") for (=0; j<n: j++) printf("%2d %sIn"j+l xlD printi("请从上述选项中选择:n") scanf("%d", &i) *接收键盘输入的字符* return(int)i-I struct staff *Load File(struct staff *head) FILE * struct staff *sta if(fp= - fopen(" d \staff4txt",")=NUL)/*判断能否以只读方式打开文件* printi("不能打开文件!mn") exit(o) while(feof(fp)==0) fscanf(fp. sta->sex, &sta->age, &sta->height, &sta->weight) head= InsertAge(head, sta) /*调用 InsertAge(函数* printi("本链表装载%d个结点n"n) /显示载入的结点数,即有几个人的信息* fclose(fp) return head 添加信息函数 *春家举幸**********本本本**幸本*****亲***幸本****/
int Interface(char (*x)[20],int n) { int i; int j; printf("\n×××××××极限俱乐部会员信息系统×××××××\n"); do { for (j=0;j<n;j++) printf("%2d.%s\n",j+1,x[j]); printf("请从上述选项中选择:\n"); scanf("%d",&i); /*接收键盘输入的字符*/ } while (i<0||i>n+1); return (int)i-1; } struct staff *LoadFile(struct staff *head) { FILE *fp; struct staff *sta; if((fp=fopen("d:\\staff_4.txt","r"))==NULL) /*判断能否以只读方式打开文件*/ { printf("不能打开文件!\n"); exit(0); } while (feof(fp)==0) { sta = (struct staff *)malloc(Len); fscanf(fp,"%s%s%s%d%d%d\n",sta->unit,sta->name, sta->sex,&sta->age,&sta->height,&sta->weight); head = InsertAge(head,sta); /*调用 InsertAge()函数*/ n++; } printf("本链表装载%d 个结点.\n",n); /*显示载入的结点数,即有几个人的信息*/ fclose(fp); return head; } /**********************************************************\ 添加信息函数 \**********************************************************/
struct staff*Add( struct staff *head) struct staff p=(struct staff")malloc(Len) printi("n××××××××输入会员信息×××××x×X(按e退出)") printf("n[%d]请输入会员信息(按e键退出):n",n+1) printi("单位:") scanf("%s"p->unit); if(strcmp(p->unit, "e")==0) /若要退出输入,则按e*/ printi("姓名:"); scanf("%s",p->name); printi("性别(Male/ Female):") scanf("%s"p->sex) printi("年龄:"), scanf("%d", &p->age) printi("身高(cm)"), scanf("%od", &p->height) print"体重(kg):"); scanf("%d", &p->weight) head=lnsertAge(head, p) 本本**亲本本**幸本本**容*本本客本本本本*本幸本*亲本客***\ 显示信息函数 void Display (struct staff*p) printf("n%20s%10s%10s","单位”"姓名","性别") 显示标题* printf("%10s%10s%10s"年龄","身高""体重") /显示数据信息* printf("n n"); while(pl=0)
struct staff *Add(struct staff *head) { struct staff *p; while(1) { p=(struct staff *)malloc(Len); printf("\n×××××××××输入会员信息××××××××(按 e 退出)"); printf("\n [%d]请输入会员信息(按 e 键退出):\n",n+1); printf("单位:"); scanf("%s",p->unit); if (strcmp(p->unit,"e")==0) /*若要退出输入,则按 e*/ { free(p); break; } printf("姓名:"); scanf("%s",p->name); printf("性别(Male/Female):"); scanf("%s",p->sex); printf("年龄:"); scanf("%d",&p->age); printf("身高(cm):"); scanf("%d",&p->height); printf("体重(kg):"); scanf("%d",&p->weight); head=InsertAge(head,p); } return head; } /**********************************************************\ 显示信息函数 \**********************************************************/ void Display(struct staff *p) { printf("\n%20s%10s%10s","单位","姓名","性别"); /*显示标题*/ printf("%10s%10s%10s","年龄","身高","体重"); /*显示数据信息*/ printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~\n"); while(p!=0) {