C++学生信息管理系统
本文实例为大家分享了C++学生信息管理系统源码,供大家参考,具体内容如下 1. tea_list.c #include<stdio.h> #include<stdlib.h> #include<string.h> #include"teacher.h" int sq_tea ; PTEA head = NULL ; FILE *fp ; int tea_llopen(const char* path)//打开文件 { fp=fopen(path,"r"); if(fp==NULL){ perror("open fail"); return -1;} #ifdef DEBUG printf ("debug--001") ; #endif PTEA p; int ret; while(p) { p=malloc(sizeof(TEA)); if(p==NULL){ perror("申请空间不够"); return -1;} ret=fscanf(fp,"%d%d%d%s%s",&p->id,&p->age,&p->wages,p->name,p->passwd); if(ret<=0) break; if(head==NULL){ p->next=NULL; p->pre=NULL; head=p;} else{ p->next=head; p->pre=NULL; head->pre=p; head=p;} } return 0; } #if 1 int tea_llshow( )//显示 { if(head==NULL) return -1; PTEA p=head; printf("工号t年龄t工资t姓名n"); while(p) { printf("%dt%dt%dt%sn",p->id,p->age,p->wages,p->name); p=p->next; } return 0; } PTEA tea_llcheck(PTEA a)//查找 { printf("输入查找教师工号n"); int id; scanf("%d",&id); while(getchar()!='n'); PTEA p; p=head; while(p) { if(p->id==id){ printf ("工号t年龄t薪水t姓名n " ); printf ("%dt%dt%dt%sn",p->name); break ; } p=p->next; } if (p==NULL) { printf ("未找到该教师n"); printf ("是否继续查找y/nn") ; char ch ; getchar(); ch=getchar(); if((ch=='y')||(ch=='Y')) tea_llcheck (p ) ; else return NULL ; } return 0; } #endif #if 1 int tea_lladd(PTEA b )//增加老师信息 { #ifdef _DEBUG_ printf ("debug-001n") ; #endif PTEA p ; char ch ; p=malloc(sizeof(TEA)); if(p==NULL){ perror("申请空间不够n"); return -1;} printf ("请输入添加老师的信息n工号t年龄t薪水t姓名t密码n") ; scanf("%d%d%d%s",p->passwd) ; while(getchar()!='n'); if ( p == NULL ) return -1 ; if ( head == NULL ) //说明链表为空,加入成第一个 { p->next = NULL ; p->pre = NULL ; head->pre = p ; head = p ; } else { p->next=head ; p->pre=NULL ; head->pre = p ; head=p ; } /* fprintf ( fp,"%dt%dt%dt%sn",p->name ) ; fclose ( fp ) ; fopen ("teacher.txt","a+"); */ return 0 ; } #endif #if 1 int tea_lldelete( PTEA a ) //删除老师 { int key ; printf ("请输入要删除的老师的工号n") ; scanf ("%d",&key); while(getchar()!='n'); PTEA p ; PTEA q ; p = head ; while (p) { if (p->id == key ) { if( (p == head)&&(head->next!=NULL) ) { head = head->next ; head->pre = NULL ; #ifdef _DEBUG_ printf ("case 1n") ; #endif } else if ((p==head) && ( head->next==NULL)) { head = NULL ; #ifdef _DEBUG_ printf ("case 2n") ; #endif } else if( (p!=head )&&(p->next!=NULL) ) {p->pre->next=p->next ; p->next->pre = p->pre ; #ifdef _DEBUG_ printf ("case 3n ") ; I #endif } else { p->pre->next = NULL ; #ifdef _DEBUG_ printf ("case 4n") ; #endif } break ; } p = p->next ; } free (p) ; if (p==NULL) printf ("未找到该教师") ; /* fp = fopen("teacher.txt","r+"); while(p){ fprintf (fp," %dt%dt%dt%sn",p->name ); p=p->next ; } fclose (fp) ; tea_llopen ; */ } #endif #if 1 int tea_llchange()//修改老师信息 { PTEA p; printf("n输入工号"); int key; scanf("%d",&key); while(getchar()!='n'); p=head; while(p) { if(p->id==key){ printf("工号t年龄t薪水t姓名n"); scanf("%d%d%d%s%s",p->passwd); while(getchar()!='n'); break ; } p=p->next;} p = head ; printf ("修改之后为n"); printf("学号t年龄t数学t英语t语文t班级t姓名t密码n"); while(p) { printf("%dt%dt%dt%st%sn",p->passwd); p=p->next; } return 0; } #endif #if 1 PTEA tea_check_id() //校验老师用户名 { PTEA p; p = head; int id; char ch; printf("请输入您的工号:"); scanf("%d",&id); while(getchar()!='n'); while(p) { if(p->id==id){ return p; } p = p->next; } if(p==NULL){ printf("找不到该用户n"); printf("是否重试?[y/n]n"); // scanf("%c",&ch) ; // getchar () ; ch = getchar () ; if ((ch=='y')||(ch=='Y')) tea_check_id(); else menu(); } } #endif #if 1 PTEA tea_check_passwd() //校验老师密码 { PTEA p; p =tea_check_id(); char passwd[20]; char ch; printf("请输入密码:"); scanf("%s",passwd); while(getchar()!='n'); if(strcmp (p->passwd,passwd)==0) { sq_tea = p->id ; #ifdef _DEBUG_ printf("================%dn",p->id) ; printf("================%dn",sq_tea) ; getchar(); getchar(); #endif return p; }else{ printf("密码不正确n"); printf("是否重新输入[y/n]n"); // getchar() ; ch = getchar () ; while(getchar()!='n'); if((ch=='y')||(ch=='Y')) tea_check_passwd(); else menu(); } return NULL; } #endif #if 1 int tea_change_passwd() { PTEA p; p=tea_check_passwd(); char new_passwd[20]; char new[20]; char ch; printf("请输入新密码:"); scanf("%s",new_passwd); while(getchar() != 'n'); printf("请再次输入新密码:"); scanf("%s",new); while(getchar() != 'n'); if(strcmp(new_passwd,new)==0) { strcpy(p->passwd,new_passwd) ; printf("密码修改成功!n"); // tea_write() ; } else { printf("密码输入错误n"); printf("是否重试[y/n]n"); // getchar(); ch=getchar() ; while(getchar()!='n'); if((ch=='y')||(ch=='Y')) tea_change_passwd(); else exit(1); } return 0; } #endif #if 1 int tea_lookme() { PTEA p; p = head ; while (p) { if( p->id == sq_tea ) { printf("工号t年龄t薪水t姓名t密码n"); printf("%dt%dt%dt%sn%sn",p->passwd); } p = p->next ; } return 0 ; } #endif #if 1 int tea_write() { PTEA p; // PTEA head ; FILE *fp; p=head; fp=fopen("teacher.txt","w+"); while(p) { fprintf( fp,"%dt%dt%dt%st%sn",p->passwd); p=p->next; } return 0; } #endif #if 0 int main(int argc,char * argv[]) { if(argc<2){ printf("execult error"); return -1;} int ret; PTEA p; ret=tea_llopen(argv[1]); if(ret<0){ printf("list is endn"); return -1;} // tea_llshow(head); // int id; /* p=tea_llcheck(); printf("%dt%dt%dt%sn",p->name); */ //tea_llshow(); // tea_lladd(head) ; // tea_llshow(head) ; // tea_lldelete( head ) ; // tea_llshow(head) ; tea_llcheck(head) ; return 0; } #endif 2. stu_list.c #include<stdio.h> #include<stdlib.h> #include<string.h> #include"student.h" PSTU head1 = NULL ; int sq_stu ; #if 1 FILE*fp; int stu_llopen(char* path)//打开文件 { fp=fopen(path,"r"); if(fp==NULL){ perror("open fail"); return -1;} #ifdef _DEBUG_ printf ("open susessn") ; #endif PSTU p; int ret; while(p) { #ifdef _DEBUG_ perror("while -timen"); #endif p=malloc(sizeof(STU)); if(p==NULL){ printf("申请空间不够"); return -1;} ret=fscanf(fp,"%d%d%d%d%d%d%s%s",&p->math,&p->english,&p->chinese,&p->class,p->passwd); #ifdef _DEBUG_ printf("ret is okn") ; #endif if(ret<=0) { #ifdef _DEBUG_ printf ("list is end n ") ; #endif break; } if(head1==NULL){ p->next=NULL; p->pre=NULL; head1=p;} else{ p->next=head1; p->pre=NULL; head1->pre=p; head1=p;} } return 0; } #endif int stu_llshow()//显示 { // FILE *fp; if(head1==NULL) return -1; PSTU p=head1; printf("学号t年龄t数学t英语t语文t班级t姓名n"); while(p) { printf("%dt%dt%dt%dt%dt%dt%sn",p->math,p->english,p->chinese,p->class,p->name); p=p->next; } // fflush(stdout) ; return 0; } int stu_llcheck()//查找 { printf("n输入查找学号n"); int key; scanf("%d",&key); while(getchar()!='n'); PSTU p; p=head1; if(head1==NULL) { printf ("打开链表失败") ; return -1; } while(p) { if(p->id==key) { #ifdef _DEBUG_ printf ("while p ") ; #endif printf("%dt%dt%dt%dt%dt%dt%sn",p->name); break ; } p=p->next; } if (p==NULL) { printf ("未找到该学生"); printf ("是否继续查找y/n") ; char ch ; ch=getchar(); while(getchar()!='n'); if((ch='y')||(ch=='Y')) stu_llcheck() ; else exit(1) ; } return 0; } int __stu_lladd(PSTU p)//被调用添加 { if(p==NULL) return -1; if(head1==NULL){ p->next=NULL; p->pre=NULL; head1->pre=p; head1=p;} else{ p->next=head1; p->pre=NULL; head1->pre=p; head1=p;} return 0; } int stu_lladd()//添加 { PSTU p; p=malloc(sizeof(STU)); if(p==NULL) return -1; printf("n输入添加学生信息nn"); printf("学号t年龄t数学t英语t语文t班级t姓名t密码n"); scanf("%d%d%d%d%d%d%s",p->passwd); __stu_lladd(p); /* fprintf( fp,"%dt%dt%dt%dt%dt%dt%sn",p->name ); fclose (fp) ; fp = fopen ("student.txt","r" ) ; */ return 0; } #if 1 int __stu_lldelete(int id)//被调用的删除 { PSTU p; PSTU q=NULL; p=head1; while(p) { if(p->id==id){ if(p==head1){ if(head1->next){ head1=head1->next; head1->pre=NULL;} else{ head1=NULL;} } else{ if(p->next){ p->pre->next=p->next; p->next->pre=p->pre;} else{ p->pre->next=NULL;} } break; } p=p->next; } if (p==NULL) { printf ("未找到该学生n"); } free(p); /* fclose (fp) ; p=head1 ; fp = fopen("student.txt","w+"); while(p){ fprintf (fp,p->name); p=p->next ; } fclose (fp) ; fp = fopen ("student.txt","r" ) ; p=head1 ; stu_llopen("") ; */} int stu_lldelete()//删除 { int id; PSTU p; printf("n输入删除学号n"); scanf("%d",&id); while(getchar()!='n') ; return __stu_lldelete(id); } #endif #if 1 int stu_llchange()//修改 { PSTU p; printf("n输入修改学号"); int key; scanf("%d",&key); while(getchar() != 'n'); p=head1; while(p) { if(p->id==key){ printf("学号t年龄t数学t英语t语文t班级t姓名t密码n"); scanf("%d%d%d%d%d%d%s%s",p->passwd); break ; } p=p->next;} /* fprintf( fp,"%dt%dt%dt%dt%dt%st%dn",p->class ); printf("学号t年龄t数学t英语t语文t姓名t班级"); */ p = head1 ; printf ("修改之后为n"); printf("学号t年龄t数学t英语t语文t班级t姓名n"); while(p) { printf("%dt%dt%dt%dt%dt%dt%sn",p->name); p=p->next; } return 0; } #endif #if 1 //排序 int stu_sort() { PSTU p ; // p->sum == (p->math + p->english + p->chinese) ; PSTU new_head1=NULL; PSTU q=NULL,max=head1,prev; printf ("按照总成绩排序n"); while(head1) { //1,找到最大分数的节点地址 max = head1; prev=q=NULL; p=head1; while(p) { if( (p->math+p->english+p->chinese) > (max->math+max->english+max->chinese) ) { max = p; prev= q; } q = p; p=p->next; } if(prev){ prev->next = max->next; }else{ head1= head1->next; } //3,把该节点头插到新链表头指针 max->next = new_head1; new_head1 = max; } head1 = max; stu_llshow() ; return 0 ; } #endif #if 1 PSTU stu_check_id() //校验学生用户名 { PSTU p; p = head1; int id; char ch; printf("请输入您的学号:"); scanf("%d",&id); while(getchar() != 'n'); while(p) { if(p->id==id){ return p; } p = p->next; } printf ("找到该用户n") ; if(p==NULL){ printf("找不到该用户n"); printf("是否重试?[y/n]n"); ch = getchar () ; while(getchar()!=' '); if ((ch=='y')||(ch=='Y')) stu_check_id(); else menu(); } } #endif #if 1 PSTU stu_check_passwd() //校验学生密码 { PSTU p; p =stu_check_id(); char passwd[20]; char ch; printf("请输入密码:"); scanf("%s",passwd); while(getchar()!='n') ; if(strcmp (p->passwd,passwd)==0) { sq_stu = p->id ; return p; }else{ printf("密码不正确n"); printf("是否重新输入[y/n]n"); ch = getchar () ; while(getchar()!='n'); if((ch=='y')||(ch=='Y')) stu_check_passwd(); else menu(); } return NULL; } #endif #if 1 int stu_change_passwd() { PSTU p; p=stu_check_passwd(); // p->passwd=1234; char new_passwd[20]; char new[20]; char ch; printf("请输入新密码:"); scanf("%s",new_passwd); while(getchar() != 'n'); printf("请再次输入新密码:"); scanf("%s",new); while(getchar()!='n') ; if(strcmp(new_passwd,new_passwd) ; printf("密码修改成功!n"); } else { printf("密码输入错误n"); printf("是否重试[y/n]n"); ch=getchar(); while (getchar()!='n') ; if((ch=='y')||(ch=='Y')) stu_change_passwd(); else student_menu(); } return 0; } #endif #if 1 int stu_lookme() { PSTU p; p = head1 ; #ifdef _DEBUG_ printf ("%dn",sq_stu) ; #endif while (p) { if (p->id==sq_stu){ printf("学号t年龄t数学t英语t语文t班级t姓名t密码n"); printf("%dt%dt%dt%dt%dt%dt%st%sn",p->passwd); } p = p->next ; } return 0 ; } #endif #if 1 int stu_write() { PSTU p; FILE *fp; // PSTU head1 ; p=head1; fp=fopen("student.txt","w"); while(p) { fprintf( fp,"%dt%dt%dt%dt%dt%dt%st%sn",p->passwd); p=p->next; } return 0; } #endif #if 1 void stu_check_class() { int class ; PSTU p ; int i=0 ; p = head1 ; printf ("请输入您要查找的班级:n"); scanf ("%d",&class); while(getchar()!='n') ; while (p){ if (p->class==class ) { printf("%dt%dt%dt%dt%dt%dt%sn",p->name); i++ ; } p=p->next; } if((p==NULL)&&(i==0)) printf("未找到该班级n"); } #endif #if 0 int main(int argc,char * argv[]) { /* if(argc<2){ printf("execult error"); return -1;} */ int ret; PSTU p; ret=stu_llopen("student.txt"); if(ret<0){ printf("创建失败n"); return -1;} printf ("debug-000n") ; // int id; stu_llshow(); // stu_lldelete(); // stu_llcheck() ; // stu_llshow(); stu_check_class() ; // stu_llchange(); // sleep (1) ; // stu_llshow(); // stu_sort(); // stu_llshow(); return 0; } #endif 3. student.txt 4. teacher.txt 5. menu.c #include"student.h" #include"teacher.h" #if 1 void admin_menu_1() { char u[20]=""; char u1[20]="admin"; char p[20]=""; char p1[20]="admin"; while (1) { printf("管理员用户名n"); scanf("%s",u); while(getchar()!= 'n'); printf("管理员密码n"); scanf("%s",p); while(getchar()!= 'n'); if (strcmp(u,u1)==0&&strcmp(p,p1)==0) admin_menu_2() ; else printf ("输入用户名或密码不正确,是否重试y/nn"); char ch ; ch=getchar() ; while(getchar()!= 'n'); if ((ch=='y')||(ch=='Y')) admin_menu_1() ; else menu() ; } } #endif #if 1 void admin_menu_2() { while(1) { system ("clear"); printf("nnn"); printf("tttt******************************n"); printf("tttt* 1.管理老师 *n"); printf("tttt* 2.管理学生 *n"); printf("tttt* 0.返回 *n"); printf("tttt******************************n"); printf("tttt请输入数字选择n"); char ch ; ch=getchar(); while(getchar()!= 'n'); switch(ch) { case '1': admin_menu_2_1() ; break ; case '2': admin_menu_2_2() ; break ; case '0': menu(); default: admin_menu_2() ; break; } } } #endif #if 1 void teacher_menu() { tea_check_passwd(); char ch; while(1) { printf("nnn"); printf("tttt******************************n"); printf("tttt* 1.查找学生信息 *n"); printf("tttt* 2.按总成绩排名 *n"); printf("tttt* 3.修改老师密码 *n"); printf("tttt* 4.查看我的信息 *n"); printf("tttt* 5.按照班级查找学生 *n"); printf("tttt* 0.返回 *n"); printf("tttt******************************n"); printf("tttt请输入数字选择n"); ch=getchar(); while(getchar()!='n'); switch(ch) { case '1': //admin_tea_delete();break; stu_llshow(); stu_llcheck(); break; case '2': stu_sort() ; break ; case '3': printf ("修改老师密码n") ; tea_change_passwd() ; break ; case '4': printf("我的信息n"); tea_lookme() ; break; case '5': printf("按照班级查找n"); stu_check_class(); break ; case '0': menu(); default : printf("字符不符n"); break; } } } #endif #if 1 void student_menu() { stu_check_passwd(); while(1) { printf("nnn"); printf("tttt******************************n"); printf("tttt* 1.查询我的信息 *n"); printf("tttt* 2.修改学生密码 *n"); printf("tttt* 0.返回 *n"); printf("tttt******************************n"); printf("tttt请输入数字选择n"); char ch; ch=getchar(); while(getchar()!='n'); switch(ch) { case '1': printf("查询我的信息n"); stu_lookme(); break; case '2': printf("修改密码n"); stu_change_passwd(); break; case '0': menu() ;// break;//exit(0); default : printf("请输入n"); break; } } } #endif #if 1 void menu() { char ch; while(1) { system ("clear"); printf("nnn"); printf("tttt******************************n"); printf("tttt* 欢迎进入学生管理系统 *n"); printf("tttt******************************n"); printf("tttt* 1.管理员登录 *n"); printf("tttt* 2.老师登录 *n"); printf("tttt* 3.学生登录 *n"); printf("tttt* 0.保存并退出 *n"); printf("tttt******************************n"); printf("tttt请输入数字选择n"); ch=getchar(); while(getchar()!= 'n'); switch(ch) { case '1': admin_menu_1();break; case '2': teacher_menu(); break; case '3': student_menu();break; case '0': tea_write() ; stu_write() ; exit(0) ; //break;//exit(0); default : printf("输入不存在的字符n"); break; } } } #endif #if 1 void admin_menu_2_1() { while(1) { printf("nnn"); printf("tttt******************************n"); printf("tttt* 1.删除老师 *n"); printf("tttt* 2.添加老师 *n"); printf("tttt* 3.查找老师 *n"); printf("tttt* 4.修改老师 *n"); printf("tttt* 5.查看全部老师 *n"); printf("tttt* 0.返回 *n"); printf("tttt******************************n"); printf("tttt请输入数字选择n"); char ch ; ch=getchar(); while(getchar()!='n'); switch(ch) { case '1': //admin_tea_delete();break; printf("删除教师n"); tea_llshow( ) ; tea_lldelete() ; break; case '2': printf("添加教师n"); tea_lladd( ) ; tea_llshow() ; break; //admin_tea_add();break; case '3': printf("查找教师n"); tea_llcheck( ) ; break; //admin_tea_cheak();break; case '4': printf("修改老师n"); tea_llchange() ; break; case '5': printf("查看全部老师n"); tea_llshow() ; break; // case '0': admin_menu_2() ;// break;//exit(0); default : printf("字符不符n"); break; } } } #endif #if 1 void admin_menu_2_2() { while(1) { printf("nnn"); printf("tttt******************************n"); printf("tttt* 1.删除学生 *n"); printf("tttt* 2.添加学生 *n"); printf("tttt* 3.查找学生 *n"); printf("tttt* 4.修改学生 *n"); printf("tttt* 5.查看全部学生 *n"); printf("tttt* 0.返回 *n"); printf("tttt******************************n"); printf("tttt请输入数字选择n"); char ch ; ch=getchar(); while(getchar()!='n'); switch(ch) { case '1': printf ("删除学生"); stu_llshow(); stu_lldelete(); stu_llshow(); break ; case '2': printf("添加学生n"); stu_lladd(); stu_llshow(); break ; case '3': printf("查找学生n"); stu_llcheck(); break; case '4': printf("修改学生n"); stu_llchange(); break; case '5': printf("查看全部学生n"); stu_llshow() ; break; case '0': admin_menu_2() ; default : printf("请选择n"); break; } } } #endif #if 1 int main() { stu_llopen(FILENAME1); tea_llopen(FILENAME); #ifdef _DEBUG_ stu_llshow(); tea_llshow(); #endif sleep(1); system ("clear"); menu(); } #endif 以上就是本文的全部内容,希望对大家学习C++管理系统有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |