本文实例为大家分享了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("%d\t%d\t%d\t%s\n",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 ("%d\t%d\t%d\t%s\n",p->name); break ; } p=p->next; } if (p==NULL) { printf ("未找到该教师\n"); printf ("是否继续查找y/n\n") ; 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-001\n") ; #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,"%d\t%d\t%d\t%s\n",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 1\n") ; #endif } else if ((p==head) && ( head->next==NULL)) { head = NULL ; #ifdef _DEBUG_ printf ("case 2\n") ; #endif } else if( (p!=head )&&(p->next!=NULL) ) {p->pre->next=p->next ; p->next->pre = p->pre ; #ifdef _DEBUG_ printf ("case 3\n ") ; I #endif } else { p->pre->next = NULL ; #ifdef _DEBUG_ printf ("case 4\n") ; #endif } break ; } p = p->next ; } free (p) ; if (p==NULL) printf ("未找到该教师") ; /* fp = fopen("teacher.txt","r+"); while(p){ fprintf (fp," %d\t%d\t%d\t%s\n",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("%d\t%d\t%d\t%s\t%s\n",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("================%d\n",p->id) ; printf("================%d\n",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("%d\t%d\t%d\t%s\n%s\n",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,"%d\t%d\t%d\t%s\t%s\n",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 end\n"); return -1;} // tea_llshow(head); // int id; /* p=tea_llcheck(); printf("%d\t%d\t%d\t%s\n",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 susess\n") ; #endif PSTU p; int ret; while(p) { #ifdef _DEBUG_ perror("while -time\n"); #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 ok\n") ; #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("%d\t%d\t%d\t%d\t%d\t%d\t%s\n",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("%d\t%d\t%d\t%d\t%d\t%d\t%s\n",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输入添加学生信息\n\n"); printf("学号\t年龄\t数学\t英语\t语文\t班级\t姓名\t密码\n"); scanf("%d%d%d%d%d%d%s",p->passwd); __stu_lladd(p); /* fprintf( fp,"%d\t%d\t%d\t%d\t%d\t%d\t%s\n",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,"%d\t%d\t%d\t%d\t%d\t%s\t%d\n",p->class ); printf("学号\t年龄\t数学\t英语\t语文\t姓名\t班级"); */ p = head1 ; printf ("修改之后为\n"); printf("学号\t年龄\t数学\t英语\t语文\t班级\t姓名\n"); while(p) { printf("%d\t%d\t%d\t%d\t%d\t%d\t%s\n",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()!='\0'); 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 ("%d\n",sq_stu) ; #endif while (p) { if (p->id==sq_stu){ printf("学号\t年龄\t数学\t英语\t语文\t班级\t姓名\t密码\n"); printf("%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\n",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,"%d\t%d\t%d\t%d\t%d\t%d\t%s\t%s\n",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("%d\t%d\t%d\t%d\t%d\t%d\t%s\n",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-000\n") ; // 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
1002 25 100 90 85 1 s1 000
1003 25 107 90 84 1 s1 000
1004 25 100 90 80 1 s1 000
1005 25 107 90 80 1 s1 000
1006 25 100 90 80 1 s1 000
1007 25 108 90 80 1 s1 000
1008 25 100 78 80 1 s1 000
1009 25 100 90 80 1 s1 000
1010 25 100 45 80 1 s1 000
1012 25 90 90 80 1 s1 000
4. teacher.txt
10002 75 4500 wang2 000
10003 75 4500 wang3 000
10004 75 4500 wang4 000
10005 75 4500 wang5 000
10006 75 4500 wang6 000
10007 75 4500 wang7 000
10008 75 4500 wang8 000
10009 75 4500 wang9 000
10010 75 4500 wang10 000
10011 75 4500 wang11 000
10012 75 4500 wang12 000
10013 75 4500 wang13 000
10014 75 4500 wang14 000
10015 75 4500 wang15 000
10016 75 4500 wang16 000
10017 75 4500 wang17 000
10018 75 4500 wang18 000
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/n\n"); 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("\n\n\n"); 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* 0.返回 *\n"); printf("\t\t\t\t******************************\n"); printf("\t\t\t\t请输入数字选择\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("\n\n\n"); 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* 0.返回 *\n"); printf("\t\t\t\t******************************\n"); printf("\t\t\t\t请输入数字选择\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("\n\n\n"); 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* 0.返回 *\n"); printf("\t\t\t\t******************************\n"); printf("\t\t\t\t请输入数字选择\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("\n\n\n"); printf("\t\t\t\t******************************\n"); printf("\t\t\t\t* 欢迎进入学生管理系统 *\n"); 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* 0.保存并退出 *\n"); printf("\t\t\t\t******************************\n"); printf("\t\t\t\t请输入数字选择\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("\n\n\n"); 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* 0.返回 *\n"); printf("\t\t\t\t******************************\n"); printf("\t\t\t\t请输入数字选择\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("\n\n\n"); 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* 0.返回 *\n"); printf("\t\t\t\t******************************\n"); printf("\t\t\t\t请输入数字选择\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++管理系统有所帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。