C语言实现教务管理系统
本文实例为大家分享了C语言实现教务管理系统的具体代码,供大家参考,具体内容如下
目前已完成教师管理系统部分,学生管理系统待完成:
实现效果如图:
主界面:
教师端——注册账号
进入教师管理系统
文件的保存
代码如下:
#include<stdio.h> #include<stdlib.h> #include<string.h> /*教师应用结构体*/ typedef struct Teacher { char name[10];//学生姓名 char iD[10];//学生学号 float score;//学生成绩 }teacher; /*教师链表结点*/ typedef struct { teacher data; struct Teacher* next; }Tutor; /*教师系统账号*/ typedef struct manager { char manAcc[10]; //账号 char manPassw[10]; //密码 struct manager* next; }Manager; Manager* managerHead; /*函数声明*/ void mainMenu();//主菜单 void studentPort();//学生端 /*---------------------------------------------------------*/ /* 教师管理系统函数 */ /*---------------------------------------------------------*/ void showTeacherPort();//教师端 void teacherRegister();//教师端账号注册 void teacherLogin();//教师端登录 int Password_Text_Find();//密码验证 Manager* Manager_check();//账号核对 void teacherPort();//教师端 void tutorMenu();//教师管理菜单 void teacherFunction();//教师端功能应用 void insertStudentData();//学生信息录入 void showStudentData();//学生信息展示 void searchStudentData();//学生信息查询 void changeStudentData();//学生信息修改 Tutor* deleteStudentData();//学生信息删除 /*---------------------------------------------------------*/ /* 教师链表的初始化 */ /*---------------------------------------------------------*/ Tutor* initTeacherList();//链表初始化 Tutor* createNode();//创建结点 /*---------------------------------------------------------*/ /* 文件的读写操作 */ /*---------------------------------------------------------*/ void readInfoFromFile(); void writeInfoToFile(); int main(void) { int choice = 0; while (1) { mainMenu();//主菜单 printf("\t请输入选择:"); scanf("%d", &choice); switch (choice) { case 1: teacherPort(); break; case 2: studentPort(); break; case 3: printf("您已退出系统!\n"); system("pause"); exit(0); default: printf("您的输入有误,请重新输入!\n"); break; } system("pause"); system("cls"); } } /*主菜单*/ void mainMenu() { system("color f0"); printf("-------------------------------------------------\n"); printf("*欢迎使用教务管理系统*\n"); printf("\t1.教师端\n"); printf("\t2.学生端\n"); printf("\t3.退出系统\n"); printf("-------------------------------------------------\n"); } /*学生端*/ void studentPort() { system("cls"); system("color b0"); printf("\n\n\n\n\n\n\n\t\t\t\t学生端暂时未写,有兴趣可以接着写!!!\n\n\n\n\n\n\n\n"); } /*教师端*/ void showTeacherPort() { system("CLS"); printf("\n\n\n\t\t\t\t 教师端"); printf("\n\t\t\t---------------------------------\n\n"); printf("\t\t\t\t1)注册\n"); printf("\t\t\t\t2)登录\n"); printf("\t\t\t\t0)返回\n"); printf("\n\t\t\t---------------------------------\n\n"); } /*教师管理菜单*/ void tutorMenu() { system("cls"); system("color 70"); printf("-------------------------------------------------\n"); printf("*欢迎进入教师端*\n"); printf("\t1.学生信息录入\n"); printf("\t2.学生信息展示\n"); printf("\t3.学生信息查询\n"); printf("\t4.学生信息修改\n"); printf("\t5.学生信息删除\n"); printf("\t6.学生数据保存\n"); printf("\t0.返回主菜单\n"); printf("-------------------------------------------------\n"); } /*教师端账号注册*/ void teacherRegister() { Manager* p = (Manager*)malloc(sizeof(Manager)); p->next = NULL; printf("请输入注册账号:"); scanf("%s", p->manAcc); printf("请输入账号密码:"); scanf("%s", p->manPassw); if (managerHead == NULL) { managerHead = p; } else { p->next = managerHead; managerHead = p; } printf("注册成功!\n"); } /*核对账号*/ Manager* Manager_check(char* Manager_num) { Manager* t = managerHead; while (t) { if (strcmp(Manager_num, t->manAcc) != 0) { t = t->next; continue; } return t; } return t; } /*密码验证*/ int Password_Text_Find(char* Password) { char password_tem[20]=""; int tem = 0; int n = 0; //检测输入次数 while (n != 3) { scanf("%s", password_tem); if (strcmp(password_tem, Password) == 0) { tem = 1; break; } else { n++; printf("\n\t\t输入错误,请重新输入,你还有%d次机会:", 3 - n); } } return tem; } /*教师端登录*/ void teacherLogin() { char ID[10]; Manager* t; printf("请输入账号:"); scanf("%s",ID); t = Manager_check(ID); if (!t) { printf("\t\t抱歉,账号不存在\n"); system("pause"); return; } printf("请输入密码:"); if (Password_Text_Find(t->manPassw) == 0) { printf("\n\t\t已经错误输入密码三次,将退出登录系统···\n"); system("pause"); return; } printf("\t\t登录成功···\n"); system("pause"); teacherFunction(); } /*教师端*/ void teacherPort() { while (1) { showTeacherPort(); char ch = getch(); switch(ch) { case '1': teacherRegister(); break; case '2': teacherLogin(); break; case '0': return; default: printf("\t\t输入错误,请重新输入\n"); break; } system("pause"); system("cls"); } } /*教师端应用功能*/ void teacherFunction() { Tutor* T = initTeacherList(); teacher data; int choice = 0; readInfoFromFile(T); while (1) { tutorMenu();//教师菜单 printf("\t请输入选择:"); scanf("%d", &choice); switch (choice) { case 1: printf("\t1.学生信息录入\n"); printf("学生姓名:"); scanf("%s", data.name); printf("学生学号:"); scanf("%s", data.iD); printf("学生成绩:"); scanf("%f", &data.score); insertStudentData(T, data);//录入学生信息 break; case 2: showStudentData(T); break; case 3: searchStudentData(T); break; case 4: changeStudentData(T); break; case 5: T=deleteStudentData(T); break; case 6: writeInfoToFile(T); break; case 0: return; default: printf("您的输入有误,请重新输入!\n"); break; } system("pause"); system("cls"); } } /*教师链表初始化*/ Tutor* initTeacherList() { Tutor* headNode = (Tutor*)malloc(sizeof(Tutor)); headNode->next = NULL; return headNode; } /*创建结点*/ Tutor* createNode(teacher data) { Tutor* newNode = (Tutor*)malloc(sizeof(Tutor)); newNode->data = data; newNode->next = NULL; return newNode; } /*学生信息录入*/ void insertStudentData(Tutor* headNode,teacher data) { Tutor* newNode = createNode(data); /*头接法*/ newNode->next = headNode->next; headNode->next = newNode; printf("\t录入成功!\n"); } /*学生信息展示*/ void showStudentData(Tutor* headNode) { Tutor* P = headNode->next; printf("姓名\t学号\t成绩\t\n"); while (P) { printf("%s\t%s\t%f\n", P->data.name, P->data.iD, P->data.score); P = P->next; } } /*学生信息查询-按学号*/ void searchStudentData(Tutor* headNode) { Tutor* P = headNode->next; char ID[10] = " "; printf("请输入查找的学生学号:"); scanf("%s", ID); while (P) { if (strcmp(P->data.iD, ID) != 0) { P = P->next; continue; } else { printf("姓名\t学号\t成绩\n"); printf("%s\t%s\t%f\n", P->data.name, P->data.iD, P->data.score); return; } } printf("\t目前不存在该学生信息!\n"); return; } /*学生信息修改*/ void changeStudentData(Tutor* headNode) { Tutor* P = headNode->next; char ID[10] = " "; printf("请输入修改的学生学号:"); scanf("%s", ID); while (P) { if (strcmp(P->data.iD, ID) != 0) { P = P->next; continue; } else { printf("\t请进行修改\n"); printf("学生姓名:"); scanf("%s", P->data.name); printf("学生学号:"); scanf("%s", P->data.iD); printf("学生成绩:"); scanf("%f", &P->data.score); printf("已完成修改!\n"); return; } } printf("\t目前不存在该学生信息!\n"); return; } /*学生信息删除*/ Tutor* deleteStudentData(Tutor* headNode) { Tutor* head= headNode; Tutor* node= head->next; char ID[10] = " "; if (headNode->next == NULL) { printf("\t当前数据为空!\n"); return headNode; } printf("请输入要删除的学生学号:"); scanf("%s", ID); while (node!=NULL) { if (strcmp(node->data.iD, ID) != 0) { head = node; node = node->next; continue; } else { head->next = node->next; free(node); printf("\t删除成功!\n"); return headNode; } } printf("\t未找到该学生的相关信息!\n"); return headNode; } //文件读操作 void readInfoFromFile(Tutor* headNode) { FILE* fp; struct Teacher data; fp = fopen("1.txt", "r"); if (fp == NULL) { fp = fopen("1.txt", "w+"); } //2.读文件 fscanf(fp, "姓名\t学号\t成绩\n");//fscanf--格式化读取数据 while (fscanf(fp, "%s\t%s\t%f\n", data.name, data.iD, &data.score) != EOF) { insertStudentData(headNode, data); } fclose(fp); } //文件写操作 void writeInfoToFile(Tutor* headNode) { FILE* fp; fp = fopen("1.txt", "w"); Tutor* pMove = headNode->next; fprintf(fp, "姓名\t学号\t成绩\n"); //fprintf--写入格式化数据 while (pMove) { fprintf(fp, "%s\t%s\t%f\n", pMove->data.name,pMove->data.iD, pMove->data.score); pMove = pMove->next; } fclose(fp); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
赞 (0)