/*极限俱乐部会员信息系统* #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; jsex, &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;jn+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) {
printf("%20s%10s%10s"p->unit, p->name, p->sex) printf("%10d%10d%10d"p->age, p->height p->weight ); printf("n p=p->next /*将下一结点的指针值赋予当前指针,从而不断向前推进 按姓名排序函数 struct staff *SortAge(struct staff*head) struct staff header=NULL, p, q: while(head=0) q(struct staff*)malloc(Len) (。q)=(*head); header=lnsertAge(header, q) /*将 InsertAgeo的返回值赋予指针 header*/ p=head free(p) /释放p所占空间,实现动态功能* printf("n完成年龄排序!ln"), /*****幸******幸本*家春*亲***本****本*本*幸****幸*客*春*** 选择法按身高排序函数 struct staff *SortHeight( struct staff*head) struct staff*header=nULL, *p, *q; while(head!=0) q(struct staff")malloc(Len) header= nsertHeight(header, q),将 InsertHeightO的返回值赋予指针 header*/ head=head->next free(p); printi("n完成身高排序!n")
printf("%20s%10s%10s",p->unit,p->name,p->sex); printf("%10d%10d%10d",p->age,p->height,p->weight); printf("\n"); p=p->next; /*将下一结点的指针值赋予当前指针,从而不断向前推进*/ } } /**********************************************************\ 按姓名排序函数 \**********************************************************/ struct staff *SortAge(struct staff *head) { struct staff *header=NULL,*p,*q; while(head!=0) { q=(struct staff *)malloc(Len); (*q)=(*head); header=InsertAge(header,q); /*将 InsertAge()的返回值赋予指针 header*/ p=head; head=head->next; free(p); /*释放 p 所占空间,实现动态功能*/ } printf("\n 完成年龄排序!\n"); return header; } /**********************************************************\ 选择法按身高排序函数 \**********************************************************/ struct staff *SortHeight(struct staff *head) { struct staff *header=NULL,*p,*q; while(head!=0) { q=(struct staff *)malloc(Len); (*q)=(*head); header=InsertHeight(header,q); /*将 InsertHeight()的返回值赋予指针 header*/ p=head; head=head->next; free(p); } printf("\n 完成身高排序!\n");
return header: 选择法按体重排序函数 struct staff *SortWeight( struct staff*head) struct staff*header=NULL, "p, *q; while(head!=O q=(struct staff*)malloc(Len); header=Insert Weight(header, q);/*将 Insert Weight(的返回值赋予指针 header* p=head head=head free(p); printf("n完成体重排序!n"); return header: 本***亲幸幸春本****亲幸本幸率李*家率***亲率本幸*幸**家春料 修改信息函数 亲本***率率*本**幸本**亲**幸本**家举****亲幸率幸*幸**/ truct staff"pl, p2 char name[20] pI=p2=head printi("请输入会员姓名:"), scanf("%s", name) while(strcmp(name, pl->name)!=0 && p2->next=O) /*逐个比较,查找信息* p2=pI pl→pl->next if (strcmp( name, pI->name)==0) /找到后修改信息* printf("请输入新信息:n"), printi("单位:")
return header; } /**********************************************************\ 选择法按体重排序函数 \**********************************************************/ struct staff *SortWeight(struct staff *head) { struct staff *header=NULL,*p,*q; while(head!=0) { q=(struct staff *)malloc(Len); (*q)=(*head); header=InsertWeight(header,q); /*将 InsertWeight()的返回值赋予指针 header*/ p=head; head=head->next; free(p); } printf("\n 完成体重排序!\n"); return header; } /**********************************************************\ 修改信息函数 \**********************************************************/ void Modify(struct staff *head) { struct staff *p1,*p2; char name[20]; p1=p2=head; printf("请输入会员姓名:"); scanf("%s",name); while (strcmp(name,p1->name)!=0 && p2->next!=0) /*逐个比较,查找信息*/ { p2=p1; p1=p1->next; } if (strcmp(name,p1->name)==0) /*找到后修改信息*/ { printf("请输入新信息:\n"); printf("单位:");
scanf("%s",p1->unit) printi("姓名:") scanf("%s"pl->name) printi("性别:"), printf("年龄:"), scanf("%d", &pl->age); printi("身高(cm)") scanf("%d", &p1->height); printi("体重(kg):") t); printf("hn修改已完成!n") 删除信息函数 struct staff *Delete(struct staff*head) struct staff*pl, *p2 char name] printf("n请输入会员姓名") canf("%s", name); pI=p2=head while( strcmp(name,pl->name)l=0&&pl->next!=0)/*逐个比较,查找信息* if(strcmp(name, pl->name)==0) if(pl=head) 删除链首* head=head->next p2->next=pl->next /*删除pl所指结点 free(p1); /*释放pl所占内存*
scanf("%s",p1->unit); printf("姓名:"); scanf("%s",p1->name); printf("性别:"); scanf("%s",p1->sex); printf("年龄:"); scanf("%d",&p1->age); printf("身高(cm):"); scanf("%d",&p1->height); printf("体重(kg):"); scanf("%d",&p1->weight); printf("\n 修改已完成!\n"); } } /**********************************************************\ 删除信息函数 \**********************************************************/ struct staff *Delete(struct staff *head) { struct staff *p1,*p2; char name[20]; printf("\n 请输入会员姓名:"); scanf("%s",name); p1=p2=head; while (strcmp(name,p1->name)!=0 && p1->next!=0) /*逐个比较,查找信息*/ { p2=p1; p1=p1->next; } if(strcmp(name,p1->name)==0) { if (p1==head) /*删除链首*/ { head=head->next; } else { p2->next=p1->next; /*删除 p1 所指结点*/ } free(p1); /*释放 p1 所占内存*/
printf("n%s已删除!n",name), printf("%s没有找到,请再次确认输入信息!",name), 本幸本本本率*客本*本*家*布**********家**家*家*家********家***料 按姓名检索函数 void Search(struct staff *head) struct staff *pl, *p2 char name 201 pI=p2=head printf("hn请输入会员姓名") while(strcmp(name, pl-name)!=0 && pl->next!=o) pl=pl->next if(strcmp(name, pl->name==0) /*逐个比较,查找信息* printi("hn%20s%0s%10s”"单位","姓名"”性别") printi("%10s%l0s%l0s","年龄"”身高","体重") printf("Inn printf("%20s %10s %10s"pI->unit, pl->name, pI->sex) printf("%10d %10d %10dpI->age, p1->height p1->weight) printf("\n"); printf("%s没有找到,请再次确认输入信息!",name) 保存文件函数 *春家举幸**********本本本**幸本*****亲***幸本****/
n=n-1; printf("\n %s 已删除!\n",name); } else printf("%s 没有找到,请再次确认输入信息!",name); return head; } /**********************************************************\ 按姓名检索函数 \**********************************************************/ void Search(struct staff *head) { struct staff *p1,*p2; char name[20]; p1=p2=head; printf("\n 请输入会员姓名:"); scanf("%s",name); while (strcmp(name,p1->name)!=0 && p1->next!=0) { p2=p1; p1=p1->next; } if(strcmp(name,p1->name)==0) /*逐个比较,查找信息*/ { printf("\n %20s %10s %10s","单位","姓名","性别"); printf(" %10s %10s %10s","年龄","身高","体重"); printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("%20s %10s %10s",p1->unit,p1->name,p1->sex); printf("%10d %10d %10d",p1->age,p1->height,p1->weight); printf("\n"); } else printf("%s 没有找到,请再次确认输入信息!",name); } /**********************************************************\ 保存文件函数 \**********************************************************/
void SaveFile(struct staff*head) FILE fpl struct staff*p=head if(fpI=fopen("d: staff 4 new. txt", "W"))=NULL) *以文本方式生成并"写打开"”文件* printi("不能打开文件!n") exit(l) while(p =NULL) fprintf(fpl, %10s %10s %10s %10d %10d %10d \n", p->unit, p->name, p->sex, p->age, p->height, p->weight) p=p->nex printf("n文件已保存!hn"); fclose(fp1); /*****幸******幸本*家春*亲***本****本*本*幸****幸*客*春*** 插入姓名文件函数 struct staff*InsertAge( struct staff *head, struct staff*p)/*按年龄由大到小插入链表*/ struct staff pl, 'p2 pI=p2=head if (head==0) return head while((p->ageage)&&(pl->next!=o)) if(p->age>=pI->age if(pl=head) head=p
void SaveFile(struct staff *head) { FILE *fp1; struct staff *p=head; if((fp1=fopen("d:\\staff_4_new.txt","w"))==NULL) { /*以文本方式生成并"写打开"文件*/ printf("不能打开文件!\n"); exit(1); } while(p!=NULL) { fprintf(fp1,"%10s %10s %10s %10d %10d %10d \n",p->unit,p->name, p->sex,p->age,p->height,p->weight); p=p->next; } printf("\n 文件已保存!\n"); fclose(fp1); } /**********************************************************\ 插入姓名文件函数 \**********************************************************/ struct staff *InsertAge(struct staff *head, struct staff *p)/*按年龄由大到小插入链表*/ { struct staff *p1,*p2; p1=p2=head; if (head==0) { head=p; p->next=0; return head; } else while((p->ageage) && (p1->next!=0)) { p2=p1; p1=p1->next; } if(p->age>=p1->age) { if(p1==head) { head=p;