#include #include #include #include #include #include //#include void menus(); void input(); void display(); void save(); int my_delete(); void end(); int password(); int login(); int cpassword(); int alter(); void demand(); void _menus(); void out(); void _menus2(); /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int num=0;//当前数组中存储的数据量 struct node{ char stnum[20]; char stname[20]; char sex[8]; int age; char detail[100]; }student[1000]; int main(int argc, char *argv[]) { //if(!login())return 0; menus(); char choice; while(1){ printf("请输入正确选项!\n"); choice=getch(); system("cls"); switch(choice){ case '1': input(); end(); break; case '2': display(); break; case '3': printf("\a保存后将退出系统\n是否继续?\n继续则输入'Y'\n按其他任意键取消\n"); char ch; ch=getch(); if(ch=='Y'||ch=='y'){ save(); out(); return 0; } break; case '4': if(my_delete()!=1){ out(); return 0; } break; case '5': if(alter()!=1){ out(); return 0; } break; case '6': demand(); break; case '7': if(cpassword()!=1){ out(); return 0; } break; case '8': out(); return 0; default: system("cls"); end(); break; } system("cls"); menus(); } return 0; } void out() { system("cls"); printf("本次使用到此结束!\n即将退出程序!\n"); for(int i=3;i>0;i--){ printf("%d秒后退出程序!\n",i); Sleep(1000); } } void menus() { printf("\t\t\t\t**********请选择系统功能选项**************\n"); printf("\t\t\t\t*--------1 学生基本信息录入--------------*\n"); printf("\t\t\t\t*--------2 学生基本信息显示--------------*\n"); printf("\t\t\t\t*--------3 学生基本信息保存--------------*\n"); printf("\t\t\t\t*---4 学生基本信息删除(此选项须输入密码)-*\n"); printf("\t\t\t\t*---5 学生基本信息修改(此选项须输入密码)-*\n"); printf("\t\t\t\t*--------6 学生基本信息查询--------------*\n"); printf("\t\t\t\t*------------7 密码修改------------------*\n"); printf("\t\t\t\t*------------8 退出系统------------------*\n"); printf("\t\t\t\t******************************************\n\n"); } void input() { int n=0; char c='0'; int falg=1; printf("请输入你要录入的学生信息数:\n"); do{ c=getch(); if(c>'9'||c<'0'){ system("cls"); printf("数值非法!!!\n请重新输入!\n"); } }while(c>'9'||c<'0'); n=c-'0'; printf("你选择录入%d名学生!\n",n); if(num+n+1>=1000){ printf("本次录入只能录入%d名学生!\n",1000-num-1); falg=0; } for(int i=num;i'0')break; else printf("数值非法请重新输入!\n"); } printf("您选择的是%d选项\n",cho-'0'); printf("\n请输入数据:"); switch (cho){ case '1': scanf("%s",t); while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){ if(strcmp(s,tem[i].stnum)==0) { fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",t,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail); printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",t,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail); } else fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail); i++; } break; case '2': scanf("%s",t); while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){ if(strcmp(s,tem[i].stnum)==0) { fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,t,tem[i].sex,tem[i].age,tem[i].detail); printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",tem[i].stnum,t,tem[i].sex,tem[i].age,tem[i].detail); } else fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail); i++; } break; case '3': scanf("%s",t); while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){ if(strcmp(s,tem[i].stnum)==0) { fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,t,tem[i].age,tem[i].detail); printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",tem[i].stnum,tem[i].stname,t,tem[i].age,tem[i].detail); } else fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail); i++; } break; case '4': scanf("%d",&d); while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){ if(strcmp(s,tem[i].stnum)==0) { fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,d,tem[i].detail); printf("学号:%-12s姓名:%-8s\t性别:%-4s\t年龄:%-4d\t备注:%-4s\n",tem[i].stnum,tem[i].stname,tem[i].sex,d,tem[i].detail); } else fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail); i++; } break; default: out(); return 1; } while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){ if(strcmp(s,tem[i].stnum)!=0)fprintf(ou,"%s\t%s\t%s\t%d\t%s\n",tem[i].stnum,tem[i].stname,tem[i].sex,tem[i].age,tem[i].detail); i++; } fclose(fp); fclose(ou); unlink("data.txt"); rename("data2.txt","data.txt"); printf("文件修改完成!\a"); Sleep(2500); system("cls"); return 1; } void demand() { char choice; while(1){ while(1){ system("cls"); _menus(); printf("请输入正确选项!\n"); choice=getch(); if(choice<'6'&&choice>'0'){ printf("您选择的是%d选项\n",choice-'0'); break; } } struct node tem[1000]; FILE *fp; fp=fopen("data.txt","r"); if(fp==NULL){ printf("文件打开失败!\n"); end(); return ; } int i=0; while(fscanf(fp,"%s%s%s%d%s",tem[i].stnum,tem[i].stname,tem[i].sex,&tem[i].age,tem[i].detail)!=EOF){ i++; } fclose(fp); int sum=i; char d[20]; int c; int fa=1; switch(choice){ case '1': printf("请输入学号:"); scanf("%s",d); for(int i=0;i3){ char si; printf("密码错误超过三次!\n"); printf("是否继续输入"); printf("按Y则继续输入!\n否则退出!\n"); si=getch(); if(si=='Y'||si=='y'){}else return 0; } printf("请输入密码!\n"); scanf("%s",mi); if(strcmp(mi,mi2)==0){ printf("密码正确!\n"); Sleep(1000); return 1; }else { printf("密码错误!\n"); Sleep(1000); } fa++; } return 0; } int login() { char mi[100]; char zhang[100]; char mi2[100]; char zhang2[100]; mi2[100]='\0'; mi[100]='\0'; FILE *fp; fp=fopen("user.txt","r"); if(fp==NULL){ printf("打开文件失败!\n"); Sleep(1000); return 0; } fscanf(fp,"%s",zhang2); fscanf(fp,"%s",mi2); fclose(fp); for(int i=0;i<3;i++){ printf("请输入您的账号:"); scanf("%s",zhang); printf("\n"); printf("请输入您的密码:"); scanf("%s",mi); printf("\n"); if(strcmp(mi,mi2)!=0||strcmp(zhang,zhang2)!=0){ system("cls"); printf("账号或密码输入错误!\n请重新输入!\n你还有%d次机会\n",3-i-1); if(3-i-1==0){ printf("本次使用到此结束!\n"); printf("按任意键退出!\n"); getchar(); getchar(); return 0; } }else{ printf("欢迎使用本系统!\n"); end(); system("cls"); return 1; } } end(); return 0; } int cpassword() { char mi[100]; char zhang[100]; char mi2[100]; mi2[100]='\0'; mi[100]='\0'; char zhang2[100]; if(password()!=1){ return 0; } FILE *out; out=fopen("user.txt","r"); fscanf(out,"%s",zhang2); fclose(out); while(1){ printf("请修改您的密码!\n"); scanf("%s",mi2); printf("请确认您的密码!\n"); scanf("%s",mi); if(strcmp(mi,mi2)==0){ FILE *fp; fp=fopen("user.txt","w+"); fprintf(fp,"%s %s",zhang2,mi2); fclose(fp); break; }else { printf("两次密码不匹配\n请重新输入!\n"); Sleep(1000); system("cls"); } } printf("密码修改成功!\n"); printf("请重新登陆!\n"); Sleep(1000); system("cls"); return login(); }