網(wǎng)站首頁 編程語言 正文
本文實例為大家分享了C語言實現(xiàn)教務(wù)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
目前已完成教師管理系統(tǒng)部分,學(xué)生管理系統(tǒng)待完成:
實現(xiàn)效果如圖:
主界面:
教師端——注冊賬號
進入教師管理系統(tǒng)
文件的保存
代碼如下:
#include#include #include /*教師應(yīng)用結(jié)構(gòu)體*/ typedef struct Teacher { ?? ?char name[10];//學(xué)生姓名 ?? ?char iD[10];//學(xué)生學(xué)號 ?? ?float score;//學(xué)生成績 }teacher; /*教師鏈表結(jié)點*/ typedef struct { ?? ?teacher data; ?? ?struct Teacher* next; }Tutor; /*教師系統(tǒng)賬號*/ typedef struct manager { ?? ?char manAcc[10];?? ?//賬號 ?? ?char manPassw[10];?? ?//密碼 ?? ?struct manager* next; }Manager; Manager* managerHead; /*函數(shù)聲明*/ void mainMenu();//主菜單 void studentPort();//學(xué)生端 /*---------------------------------------------------------*/ /* ? ? ? ? ? ? ? ? 教師管理系統(tǒng)函數(shù) ? ? ? ? ? ? ? ? ? ? ? */ /*---------------------------------------------------------*/ void showTeacherPort();//教師端 void teacherRegister();//教師端賬號注冊 void teacherLogin();//教師端登錄 int Password_Text_Find();//密碼驗證 Manager* Manager_check();//賬號核對 void teacherPort();//教師端 void tutorMenu();//教師管理菜單 void teacherFunction();//教師端功能應(yīng)用 void insertStudentData();//學(xué)生信息錄入 void showStudentData();//學(xué)生信息展示 void searchStudentData();//學(xué)生信息查詢 void changeStudentData();//學(xué)生信息修改 Tutor* deleteStudentData();//學(xué)生信息刪除 /*---------------------------------------------------------*/ /* ? ? ? ? ? ? ? ? 教師鏈表的初始化 ? ? ? ? ? ? ? ? ? ? ? ?*/ /*---------------------------------------------------------*/ Tutor* initTeacherList();//鏈表初始化 Tutor* createNode();//創(chuàng)建結(jié)點 /*---------------------------------------------------------*/ /* ? ? ? ? ? ? ? ? 文件的讀寫操作 ? ? ? ? ? ? ? ? ? ? ? ? ?*/ /*---------------------------------------------------------*/ 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("您已退出系統(tǒng)!\n"); ?? ??? ??? ?system("pause"); ?? ??? ??? ?exit(0); ?? ??? ?default: ?? ??? ??? ?printf("您的輸入有誤,請重新輸入!\n"); ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?system("pause"); ?? ??? ?system("cls"); ?? ?} } /*主菜單*/ void mainMenu() { ?? ?system("color f0"); ?? ?printf("-------------------------------------------------\n"); ?? ?printf("*歡迎使用教務(wù)管理系統(tǒng)*\n"); ?? ?printf("\t1.教師端\n"); ?? ?printf("\t2.學(xué)生端\n"); ?? ?printf("\t3.退出系統(tǒng)\n"); ?? ?printf("-------------------------------------------------\n"); } /*學(xué)生端*/ void studentPort() { ?? ?system("cls"); ?? ?system("color b0"); ?? ?printf("\n\n\n\n\n\n\n\t\t\t\t學(xué)生端暫時未寫,有興趣可以接著寫!!!\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.學(xué)生信息錄入\n"); ?? ?printf("\t2.學(xué)生信息展示\n"); ?? ?printf("\t3.學(xué)生信息查詢\n"); ?? ?printf("\t4.學(xué)生信息修改\n"); ?? ?printf("\t5.學(xué)生信息刪除\n"); ?? ?printf("\t6.學(xué)生數(shù)據(jù)保存\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; ? ?//檢測輸入次數(shù) ?? ?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已經(jīng)錯誤輸入密碼三次,將退出登錄系統(tǒng)···\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"); ?? ?} } /*教師端應(yīng)用功能*/ 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.學(xué)生信息錄入\n"); ?? ??? ??? ?printf("學(xué)生姓名:"); ?? ??? ??? ?scanf("%s", data.name); ?? ??? ??? ?printf("學(xué)生學(xué)號:"); ?? ??? ??? ?scanf("%s", data.iD); ?? ??? ??? ?printf("學(xué)生成績:"); ?? ??? ??? ?scanf("%f", &data.score); ?? ??? ??? ?insertStudentData(T, data);//錄入學(xué)生信息?? ??? ??? ? ?? ??? ??? ?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; } /*創(chuàng)建結(jié)點*/ Tutor* createNode(teacher data) { ?? ?Tutor* newNode = (Tutor*)malloc(sizeof(Tutor)); ?? ?newNode->data = data; ?? ?newNode->next = NULL; ?? ?return newNode; } /*學(xué)生信息錄入*/ void insertStudentData(Tutor* headNode,teacher data) { ?? ?Tutor* newNode = createNode(data); ?? ?/*頭接法*/ ?? ?newNode->next = headNode->next; ?? ?headNode->next = newNode; ?? ?printf("\t錄入成功!\n"); } /*學(xué)生信息展示*/ void showStudentData(Tutor* headNode) { ?? ?Tutor* P = headNode->next; ?? ?printf("姓名\t學(xué)號\t成績\t\n"); ?? ?while (P) ?? ?{ ?? ??? ?printf("%s\t%s\t%f\n", P->data.name, P->data.iD, P->data.score); ?? ??? ?P = P->next; ?? ?} } /*學(xué)生信息查詢-按學(xué)號*/ void searchStudentData(Tutor* headNode) { ?? ?Tutor* P = headNode->next; ?? ?char ID[10] = " "; ?? ?printf("請輸入查找的學(xué)生學(xué)號:"); ?? ?scanf("%s", ID); ?? ?while (P) ?? ?{ ?? ??? ?if (strcmp(P->data.iD, ID) != 0) ?? ??? ?{ ?? ??? ??? ?P = P->next; ?? ??? ??? ?continue; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?printf("姓名\t學(xué)號\t成績\n"); ?? ??? ??? ?printf("%s\t%s\t%f\n", P->data.name, P->data.iD, P->data.score); ?? ??? ??? ?return; ?? ??? ?} ?? ?} ?? ?printf("\t目前不存在該學(xué)生信息!\n"); ?? ?return; } /*學(xué)生信息修改*/ void changeStudentData(Tutor* headNode) { ?? ?Tutor* P = headNode->next; ?? ?char ID[10] = " "; ?? ?printf("請輸入修改的學(xué)生學(xué)號:"); ?? ?scanf("%s", ID); ?? ?while (P) ?? ?{ ?? ??? ?if (strcmp(P->data.iD, ID) != 0) ?? ??? ?{ ?? ??? ??? ?P = P->next; ?? ??? ??? ?continue; ?? ??? ?} ?? ??? ?else ?? ??? ?{?? ??? ? ?? ??? ??? ?printf("\t請進行修改\n"); ?? ??? ??? ?printf("學(xué)生姓名:"); ?? ??? ??? ?scanf("%s", P->data.name); ?? ??? ??? ?printf("學(xué)生學(xué)號:"); ?? ??? ??? ?scanf("%s", P->data.iD); ?? ??? ??? ?printf("學(xué)生成績:"); ?? ??? ??? ?scanf("%f", &P->data.score); ?? ??? ??? ?printf("已完成修改!\n"); ?? ??? ??? ?return; ?? ??? ?} ?? ?} ?? ?printf("\t目前不存在該學(xué)生信息!\n"); ?? ?return; } /*學(xué)生信息刪除*/ Tutor* deleteStudentData(Tutor* headNode) { ?? ?Tutor* head= headNode; ?? ?Tutor* node= head->next; ?? ?char ID[10] = " "; ?? ? ?? ?if (headNode->next == NULL) ?? ?{ ?? ??? ?printf("\t當(dāng)前數(shù)據(jù)為空!\n"); ?? ??? ?return headNode; ?? ?}?? ? ?? ?printf("請輸入要刪除的學(xué)生學(xué)號:"); ?? ?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未找到該學(xué)生的相關(guān)信息!\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學(xué)號\t成績\n");//fscanf--格式化讀取數(shù)據(jù) ?? ?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學(xué)號\t成績\n"); //fprintf--寫入格式化數(shù)據(jù) ?? ?while (pMove) ?? ?{ ?? ??? ?fprintf(fp, "%s\t%s\t%f\n", ?pMove->data.name,pMove->data.iD, pMove->data.score); ?? ??? ?pMove = pMove->next; ?? ?} ?? ?fclose(fp); }
原文鏈接:https://blog.csdn.net/weixin_53391957/article/details/118886015
相關(guān)推薦
- 2022-05-18 Qt?關(guān)于容器的遍歷迭代器的使用問題小結(jié)_C 語言
- 2022-11-01 使用Python處理KNN分類算法的實現(xiàn)代碼_python
- 2022-07-02 基于np.arange與np.linspace細(xì)微區(qū)別(數(shù)據(jù)溢出問題)_python
- 2023-01-10 golang實現(xiàn)簡單的tcp數(shù)據(jù)傳輸_Golang
- 2022-10-02 React函數(shù)組件和類組件的區(qū)別及說明_React
- 2022-11-04 C/C++中extern函數(shù)使用詳解_C 語言
- 2022-04-30 詳解Matlab如何繪制小提琴圖_C 語言
- 2022-10-11 C++函數(shù)模板與類模板相同與不同介紹_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支