1、C语言编写的班级信息管理系统有 班级信息录入,班级信息查询,班级信息修改,班级信息全部显示。录入的信息有:班级 级别 专业 班主任 总人数 男生人数 女生人数。 代码:#include #include #include #include #define NULL 0 #define LEN sizeof(struct student) #define FILE_DATA_PATH c:student.txt struct student long int num; char name20; int age; char sex4; char birthday10; char address30
2、; long int tele_num; char E_mail20; struct student *next; ; int TOTAL_NUM = 0; struct student *head = NULL; void welcome(); void mainmenu(); void record(); void insert(struct student *stu); void display(struct student *stu); void displayAll(); void query(); void query_by_num(); void query_by_name();
3、 void readData(); void writeData(); void freeAll(); void del(); void change(); void devise(struct student *p); int main() char userName9; char userPWD7; int i; welcome(); for(i = 0; i 3; i+) printf(n管理员初始用户名和密码均为adminn); printf(请输入您的用户名:); scanf(%s, userName); printf(n请输入您的密码:); scanf(%s, userPWD);
4、if (strcmp(userName,admin)=0) & (strcmp(userPWD,admin)=0) /用户名和密码正确,显示主菜单 mainmenu(); break; else if (i num); printf(请输入学生的姓名:); scanf(%s,p0-name); printf(请输入学生的年龄:); scanf(%d,&p0-age); printf(请输入学生的性别:); scanf(%s,p0-sex); printf(请输入学生的出生年月:); scanf(%s,p0-birthday); printf(请输入学生的地址:); scanf(%s,p0-ad
5、dress); printf(请输入学生的电话:); scanf(%ld,&p0-tele_num); printf(请输入学生的E-mail:); scanf(%s,p0-E_mail); insert(p0); printf(该学生的信息为:n); printf(-); printf(学号t姓名t年龄t性别t出生年月tt地址t电话tE-mailn); display(p0); void insert(struct student *stu) struct student *p0, *p1, *p2; p1 = head; p0 = stu; if(head = NULL) head = p
6、0; p0-next = NULL; else while(p0-num p1-num)&(p1-next != NULL) p2 = p1; p1 = p1-next; if(p0-num num) if(head = p1) head = p0; else p2-next = p0; p0-next = p1; else p1-next = p0; p0-next = NULL; TOTAL_NUM+; void display(struct student *p) printf(%ldt%st%dt%st%st%st%ldt%sn, p-num, p-name, p-age, p-sex
7、, p-birthday, p-address, p-tele_num, p-E_mail); /浏览学生信息 void displayAll() struct student *p; printf(学生总数:%dn, TOTAL_NUM); p = head; if(head != NULL) printf(n学号t姓名t年龄t性别t出生年月t地址t电话tE-mailn); printf(-); do display(p); p = p-next; while(p != NULL); printf(n); /查询学生信息 void query() int choice; choice = -
8、1; do printf(n); printf(+-+n); printf(| 按学号查询 请按 1 |n); printf(| 按姓名查询 请按 2 |n); printf(| 取消 请按 0 |n); printf(+-+n); printf(请输入您的选择:); scanf(%d, &choice); switch(choice) case 0: return; case 1: query_by_num(); break; case 2: query_by_name(); break; default: printf(n无效选项!); break; while(choice != 0);
9、 /按学号查询学生信息 void query_by_num() int num; struct student *p1; printf(请输入学生的学号:); scanf(%ld, &num); if(head=NULL) printf(无学生记录!n); return; p1=head; while(num!=p1-num & p1-next!=NULL) p1=p1-next; if(num = p1-num) printf(n学号t姓名t年龄t性别t出生年月t地址t电话tE-mailn); printf(-); display(p1); else printf(没有该学生记录,请核对!)
10、; /按姓名查询学生信息 void query_by_name() char name20; struct student *p1; printf(请输入学生的姓名:); scanf(%s, name); if(head=NULL) printf(无学生记录!n); return; p1=head; while(strcmp(name, p1-name) & p1-next!=NULL) p1=p1-next; if(!strcmp(name, p1-name) printf(n学号t姓名t年龄t性别t出生年月t地址t电话tE-mailn); printf(-); display(p1); e
11、lse printf(没有该学生记录,请核对!); /写入文件 void writeData() FILE* fp;/文件指针 struct student *p; fp = fopen(FILE_DATA_PATH, w); if (!fp) printf(文件打开错误!); return; fprintf(fp,%dn, TOTAL_NUM); for(p = head; p!= NULL; p= p-next) fprintf(fp,%ldt%st%dt%st%st%st%ldt%sn, p-num, p-name, p-age, p-sex, p-birthday, p-address
12、, p-tele_num, p-E_mail); fclose(fp); void freeAll() struct student *p1, *p2; p1=p2=head; while(p1) p2=p1-next; free(p1); p1=p2; /读取文件 void readData() FILE* fp;/文件指针 struct student *p1, *p2; fp = fopen(FILE_DATA_PATH, r); if (!fp) printf(文件打开错误!); return 0; fscanf(fp,%dn, &TOTAL_NUM); head = p1 = p2
13、= (struct student *)malloc(LEN); fscanf(fp,%ldt%st%dt%st%st%st%ldt%sn, &p1-num, p1-name, &p1-age, p1-sex, p1-birthday, p1-address, &p1-tele_num, p1-E_mail); while(!feof(fp) p1 = (struct student *)malloc(LEN); fscanf(fp,%ldt%st%dt%st%st%st%ldt%sn, &p1-num, p1-name, &p1-age, p1-sex, p1-birthday, p1-ad
14、dress, &p1-tele_num, p1-E_mail); p2-next = p1; p2 = p1; p2-next = NULL; fclose(fp); /删除学生信息 void del() struct student *p1, *p2; long int num; if(head = NULL) printf(无学生记录!n); return; printf(请输入您要删除的学生的学号:); scanf(%ld, &num); p1 = head; while(num != p1-num & p1-next != NULL) p2 = p1; p1 = p1-next; if
15、(num = p1-num) if(p1 = head) head = p1-next; else p2-next = p1-next; free(p1); TOTAL_NUM-; else printf(没有该学生记录,请核对!n); /修改学生信息 void change() struct student *p1, *p2; long int num; if(head = NULL) printf(无学生记录!n); return; printf(请输入您要修改的学生的学号:); scanf(%ld, &num); p1 = head; while(num != p1-num & p1-n
16、ext != NULL) p2 = p1; p1 = p1-next; if(num = p1-num) devise(p1); else printf(没有该学生记录,请核对!n); void devise(struct student *p) int choice; choice = -1; do printf(请选择您要修改的学生的信息内容:n); printf(+-+n); printf(| 姓名 请按 1 |n); printf(| 年龄 请按 2 |n); printf(| 性别 请按 3 |n); printf(| 出生年月 请按 4 |n); printf(| 地址 请按 5
17、|n); printf(| 电话 请按 6 |n); printf(| E-mail 请按 7 |n); printf(| 取消 请按 0 |n); printf(+-+n); printf(请输入您的选择:); scanf(%d, &choice); switch(choice) case 0: return; case 1: printf(请输入新姓名:); scanf(%s, p-name); break; case 2: printf(请输入新年龄:); scanf(%d, &p-age); break; case 3: printf(请输入新性别:); scanf(%s, p-sex); break; case 4: printf(请输入新出生年月:); scanf(%s, p-birthday); break; case 5: printf(请输入新地址:); scanf(%s, p-address); break; case 6: printf(请输入新电话:); scanf(%ld, &p-tele_num); break; case 7: printf(请输入新E-mail:); scanf(%s, p-E_mail); break; default: printf(n无效选项!); break; while(choice != 0);