#include//包含printf()、scanf()、gets()、puts()、getchar()函数#include//包含malloc()函数#include//包含strcmp()、strlen()、sizeof()、strcpy()函数#include//包含system()、sleep()函数#include//包含exit()函数
#definearrSize256
#definesleepTime50
voidfullScreen(){HWNDhwnd=GetForegroundWindow();intx=GetSystemMetrics(SM_CXSCREEN)+300,y=GetSystemMetrics(SM_CYSCREEN)+300;charsetting[30];//设置控制台行列数sprintf(setting,"modecon:cols=%dlines=%d",x,y);system(setting);//置顶SetWindowPos(hwnd,HWND_TOPMOST,0,0,x+200,y+200,NULL);//移动MoveWindow(hwnd,-5,-20,x+200,y+200,1);printf("\n\n");}
voidwait(){for(inti=0;i<24;i++){Sleep(sleepTime);printf(".");}puts("\n");}
voidhello(){for(inti=0;i<5;i++){Sleep(sleepTime);printf("X");}
Sleep(sleepTime);printf("");Sleep(sleepTime);printf("欢");Sleep(sleepTime);printf("迎");Sleep(sleepTime);printf("来");Sleep(sleepTime);printf("到");Sleep(sleepTime);printf("学");Sleep(sleepTime);printf("生");Sleep(sleepTime);printf("信");Sleep(sleepTime);printf("息");Sleep(sleepTime);printf("管");Sleep(sleepTime);printf("理");Sleep(sleepTime);printf("系");Sleep(sleepTime);printf("统");Sleep(sleepTime);printf("");
for(intk=0;k<5;k++){Sleep(sleepTime);printf("X");}puts("\n");}
voidcheckUsernamePassword(){charusername[]="xinke",username0[arrSize];charpassword[]="2016",password0[arrSize];for(inti=1;i<4;i++){printf("请输入用户名:");gets(username0);if(strcmp(username,username0)!=0){puts("用户名错误!");printf("3次输入错误将退出程序,错误%d次!\n\n",i);if(i==3){printf("程序即将退出");wait();system("cls");//调用倒计时函数countBackwards();}}else{i=3;puts("用户名正确!\n");for(inta=1;a<4;a++){printf("请输入密码:");gets(password0);if(strcmp(password,password0)!=0){puts("密码错误!");printf("3次输入错误将退出程序,错误%d次!\n\n",a);if(a==3){puts("程序即将退出");wait();system("cls");//调用倒计时函数fcountBackwards();break;}}else{a=3;printf("密码正确,即将进入程序");wait();system("cls");}}}}}
voidmenu(){puts("::::::请输入您要选择的操作编码::::::");puts("1.添加新学生的信息");puts("2.根据学号查找学生信息功能");puts("3.根据姓名查找学生信息功能");puts("4.根据学号修改学生信息功能");puts("5.根据学号删除学生信息功能");puts("6.根据姓名删除学生信息功能");puts("7.输入0退出");puts("::::::::::::::::::::::::::::::::::::");}
structstudent*next;};
staticstructstudent*head=NULL;
structstudent*createStudent(intnum,charname[arrSize],charbirthday[arrSize],charsex[arrSize],charadress[arrSize],charphone[arrSize],structstudent*next){structstudent*tmp;tmp=(structstudent*)malloc(sizeof(structstudent));tmp->num=num;strcpy(tmp->name,name);strcpy(tmp->birthday,birthday);strcpy(tmp->sex,sex);strcpy(tmp->adress,adress);strcpy(tmp->phone,phone);
tmp->next=next;
returntmp;}
voidaddStudent(intnum,charname[arrSize],charbirthday[arrSize],charsex[arrSize],charadress[arrSize],charphone[arrSize]){structstudent*tmp=head->next;structstudent*tmp1=head;structstudent*newnode=createStudent(num,name,birthday,sex,adress,phone,NULL);while(tmp!=NULL){if(tmp->num>=num){newnode->next=tmp;tmp1->next=newnode;break;}tmp1=tmp1->next;tmp=tmp->next;}if(tmp==NULL){tmp1->next=newnode;}}
voidfindStudentFromNum(intnum){structstudent*tmp=head->next;intflag1;while(tmp!=NULL){if(tmp->num==num){flag1=1;system("cls");puts("恭喜您!找到了该学生,信息如下:\n学号\t姓名\t出生日期\t性别\t家庭地址\t联系方式");printf("%d\t%s\t%s\t%s\t%s\t\t%s\n\n",tmp->num,tmp->name,tmp->birthday,tmp->sex,tmp->adress,tmp->phone);break;}tmp=tmp->next;}if(flag1!=1){puts("系统中不存在该学生的信息!");}}
voidfindStudentFromName(charname[arrSize]){structstudent*tmp=head->next;intflag2;while(tmp!=NULL){if(strcmp(tmp->name,name)==0){flag2=1;system("cls");puts("恭喜您!找到了该学生,信息如下:\n学号\t姓名\t出生日期\t性别\t家庭地址\t联系方式");printf("%d\t%s\t%s\t%s\t%s\t\t%s\n\n",tmp->num,tmp->name,tmp->birthday,tmp->sex,tmp->adress,tmp->phone);break;}tmp=tmp->next;}if(flag2!=1){puts("系统中不存在该学生的信息!");}}
voidmodifyStudentFromNum(intnum,charname[arrSize],charbirthday[arrSize],charsex[arrSize],charadress[arrSize],charphone[arrSize]){structstudent*tmp=head->next;while(tmp!=NULL){if(tmp->num==num){strcpy(tmp->name,name);strcpy(tmp->birthday,birthday);strcpy(tmp->sex,sex);strcpy(tmp->adress,adress);strcpy(tmp->phone,phone);break;}tmp=tmp->next;}}
voiddeleteStudentFromNum(intnum){structstudent*tmp=head->next;structstudent*tmp1=head;while(tmp!=NULL){if(tmp->num==num){tmp1->next=tmp->next;free(tmp);break;}tmp=tmp->next;tmp1=tmp1->next;}}
voiddeleteStudentFromName(charname[arrSize]){structstudent*tmp=head->next;structstudent*tmp1=head;while(tmp!=NULL){if(strcmp(tmp->name,name)==0){tmp1->next=tmp->next;free(tmp);break;}tmp=tmp->next;tmp1=tmp1->next;}}
voidprintList(){structstudent*tmp;tmp=head->next;
puts("学号\t姓名\t出生日期\t性别\t家庭地址\t联系方式");while(tmp){printf("%d\t%s\t%s\t%s\t%s\t\t%s\n",tmp->num,tmp->name,tmp->birthday,tmp->sex,tmp->adress,tmp->phone);tmp=tmp->next;}}
voidfreeList(){structstudent*tmp=head;structstudent*tmp1;while(tmp){tmp1=tmp;tmp=tmp->next;free(tmp1);}}
voidexitPrograms(){system("cls");printf("请输入0退出程序:");exit(getch());}
intx;
intcheckNumNoSame(){structstudent*tmp=head->next;
while(1){if(tmp==NULL){returnx;}if(tmp->num==x){printf("已存在该学号,请重新输入!\n\n");checkNumStrlen();break;}tmp=tmp->next;}}
intmain(void){fullScreen();//调用全屏函数
system("color0C");//背景为黑色,前景为淡红色
checkUsernamePassword();//验证用户名和密码
printf("系统正在初始化,请稍候");wait();//稍候效果......system("cls");system("color0A");for(inti=50000;i>=0;i--){printf("%d",rand());Sleep(0.000001);}system("cls");
hello();//动态显示欢迎信息
system("color0A");//背景为黑色,前景为淡绿色
menu();//打印菜单栏structstudent*stu1;structstudent*stu2;structstudent*stu3;structstudent*stu4;structstudent*tmp;
stu1=createStudent(201601,"Alan","1997-09-15","女","墨西哥","13871745572",NULL);stu2=createStudent(201602,"Bobo","1994-08-25","男","亚马逊","0710-1452637",NULL);stu3=createStudent(201603,"John","1996-02-23","男","莫斯科","13476320757",NULL);stu4=createStudent(201604,"Cici","1995-11-12","女","太平洋","0710-4567894",NULL);head=(structstudent*)malloc(sizeof(structstudent));head->num=-1;head->next=NULL;
head->next=stu1;stu1->next=stu2;stu2->next=stu3;stu3->next=stu4;stu4->next=NULL;FILE*fp;structstudenttmps;structstudent*tmp_head;fp=fopen("student.txt","rt");if(fp==NULL){perror("fopen");return-1;}tmp_head=head;memset(&tmps,0,sizeof(structstudent));while(fread(&tmps,sizeof(structstudent),1,fp)>0){tmp_head->next=createStudent(tmps.num,tmps.name,tmps.birthday,tmps.sex,tmps.adress,tmps.phone,NULL);tmp_head=tmp_head->next;memset(&tmps,0,sizeof(structstudent));}fclose(fp);intnum;chartemp[arrSize]={0};//用于以字符串形式接收的学号成员转换为int类型的中间变量charname[arrSize]={0},birthday[arrSize]={0},sex[arrSize]={0},adress[arrSize]={0},phone[arrSize]={0};
intchoice=0;while(1){ret:printf("\n请选择1-7:");fflush(stdin);scanf("%d",&choice);fflush(stdin);switch(choice){case1:puts("请分别输入要添加的学生的信息");num=checkNumStrlen();printf("请输入要添加的学生姓名:");fflush(stdin);scanf("%s",name);
ret1://用于跳转语句1printf("请输入要添加的学生出生日期:");scanf("%s",birthday);if((birthday[4]!='-')||(birthday[7]!='-')){puts("您输入的出生日期格式有误,请按照:1990-09-20的格式输入!\n");gotoret1;}
ret2://用于跳转语句2while(1){printf("请输入要添加的学生性别:");scanf("%s",sex);if((strcmp(sex,"男")==0)||(strcmp(sex,"女")==0)){break;}else{puts("您输入的性别格式有误,请输入男或女!\n");gotoret2;}}printf("请输入要添加的学生家庭地址:");scanf("%s",adress);
ret3://用于跳转语句3while(1){printf("请输入要添加的学生联系方式:");scanf("%s",phone);if((strlen(phone)==11)||((strlen(phone)==12)&&(phone[4]=='-'))){break;}else{puts("您输入的联系方式格式有误,请按照:11位数字或者0710-9999999的格式输入!\n");gotoret3;}}system("cls");printf("系统正在添加学生信息,请稍候");wait();addStudent(num,name,birthday,sex,adress,phone);Sleep(100);puts("\n恭喜您!信息添加成功!\n");printList();puts("\n");menu();break;case2:printf("请输入要查找的学生学号:");scanf("%d",&num);system("cls");printf("系统正在查找学生信息,请稍候");wait();findStudentFromNum(num);printf("\n");printList();puts("\n");menu();break;
case3:printf("请输入要查找的学生姓名:");scanf("%s",name);system("cls");printf("系统正在查找学生信息,请稍候");wait();findStudentFromName(name);printf("\n");printList();puts("\n");menu();break;
case4:printf("请输入要修改的学生学号:");scanf("%d",&num);printf("请输入要修改的学生姓名:");scanf("%s",name);printf("请输入要修改的学生出生日期:");scanf("%s",birthday);printf("请输入要修改的学生性别:");scanf("%s",sex);printf("请输入要修改的学生家庭地址:");scanf("%s",adress);printf("请输入要修改的学生联系方式:");scanf("%s",phone);system("cls");printf("系统正在修改学生信息,请稍候");wait();modifyStudentFromNum(num,name,birthday,sex,adress,phone);Sleep(100);puts("\n恭喜您!信息修改成功!\n");printList();puts("\n");menu();break;
case5:printf("请输入要删除的学生学号:");scanf("%d",&num);puts("\n");system("cls");printf("系统正在删除学生信息,请稍候");wait();deleteStudentFromNum(num);Sleep(100);puts("\n恭喜您!信息删除成功!\n");printList();puts("\n");menu();break;case6:printf("请输入要删除的学生姓名:");scanf("%s",name);system("cls");printf("系统正在删除学生信息,请稍候");wait();deleteStudentFromName(name);Sleep(100);puts("\n恭喜您!信息删除成功!\n");printList();puts("\n");menu();break;case7:fp=fopen("student.txt","wt");if(fp==NULL){perror("fopen");return-1;}tmp_head=head->next;while(tmp_head){fwrite(tmp_head,sizeof(structstudent),1,fp);tmp_head=tmp_head->next;}fclose(fp);
exitPrograms();break;
default:puts("您输入的操作编号不在本系统服务区范围,请输入数字1-7!");gotoret;break;}}