您好,登錄后才能下訂單哦!
這篇文章主要介紹“C語言如何實現教務管理系統”,在日常操作中,相信很多人在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); }
到此,關于“C語言如何實現教務管理系統”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。