C語(yǔ)言簡(jiǎn)單實(shí)現(xiàn)門(mén)禁系統(tǒng)
問(wèn)題提出
用C語(yǔ)言實(shí)現(xiàn)門(mén)禁系統(tǒng)功能。
功能簡(jiǎn)析
1、系統(tǒng)登錄分為管理員登錄和學(xué)生登錄,輸入相應(yīng)字符即可選擇登錄;
2、學(xué)生登錄,學(xué)生使用自己的賬號(hào)密碼登錄系統(tǒng),選擇開(kāi)啟的門(mén),即可開(kāi)啟門(mén)禁;此外系統(tǒng)還會(huì)記錄下學(xué)生登錄的信息,如登錄賬號(hào)、登錄時(shí)間、開(kāi)啟哪間門(mén);
3、管理員登錄,管理員登錄也是要輸入特定的賬號(hào)密碼才能登錄;登錄之后才能進(jìn)入管理員操作界面進(jìn)行相應(yīng)操作,如添加學(xué)生賬號(hào)、刪除學(xué)生賬號(hào)、查看學(xué)生基本信息、查看學(xué)生登錄情況……輸入相應(yīng)字符即可選擇執(zhí)行相應(yīng)的功能。
4、管理員權(quán)限一:添加學(xué)生賬號(hào)。輸入學(xué)生姓名(即為賬號(hào))、密碼、專業(yè)班級(jí)等基本信息,可用于后續(xù)查詢,回車完成添加。查看系統(tǒng)中學(xué)生信息,該賬號(hào)已存在
5、管理員權(quán)限二:刪除學(xué)生賬號(hào)。輸入需要?jiǎng)h除的賬號(hào),回車完成刪除操作,查看系統(tǒng)數(shù)據(jù)庫(kù)中已無(wú)該學(xué)生信息。
6、管理員權(quán)限三:查看所以學(xué)生基本信息。輸入相應(yīng)字符,即可查詢所以信息
7、管理員權(quán)限四:查看學(xué)生登錄門(mén)禁系統(tǒng)情況。輸入相應(yīng)相應(yīng)字符,可按學(xué)生使用門(mén)禁系統(tǒng)時(shí)間先后順序一次顯示學(xué)生賬號(hào)、登錄時(shí)間,選擇開(kāi)啟的門(mén)。
8、管理員權(quán)限五:修改存在于系統(tǒng)的學(xué)生信息。輸入需要修改的學(xué)生賬號(hào),并輸入修改后的賬號(hào)、密碼、專業(yè)班級(jí)等基本信息。
實(shí)現(xiàn)關(guān)鍵
首先考慮到要對(duì)學(xué)生賬號(hào)等基本數(shù)據(jù)要重復(fù)使用,且易更改,下次使用時(shí)上次修改的信息還會(huì)存在而不是對(duì)代碼進(jìn)行修改,所以考慮使用對(duì)文本進(jìn)行操作。將學(xué)生賬號(hào)密碼等數(shù)據(jù)信息全部?jī)?chǔ)存在一個(gè)txt或dat文本中,調(diào)用函數(shù)對(duì)文本進(jìn)行相應(yīng)操作,對(duì)數(shù)據(jù)的操作即是對(duì)文件的操作。
代碼實(shí)現(xiàn)
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> struct information { char name[10]; char password[10]; char profession[20]; }; struct Thelog { char name[10]; char times[24]; char num[1]; }; FILE *fp; //文件指針 information *head;//鏈表頭指針 void add_student(information a); //函數(shù)[1]管理員添加學(xué)生賬號(hào),使用門(mén)禁系統(tǒng) void delete_student(char names[10]);//函數(shù)[2]管理員員刪除學(xué)生賬號(hào),解除使用門(mén)禁系統(tǒng)權(quán)限 void administrator_login(); //函數(shù)[3]管理員登陸 void administrator_management(); //函數(shù)[4]管理員操作界面,添加學(xué)生賬號(hào),刪除學(xué)生賬號(hào),查看學(xué)生使用門(mén)禁情況 void student_login(); //函數(shù)[5]學(xué)生登陸,用于打開(kāi)門(mén)禁 void time (); //函數(shù)[6]時(shí)間函數(shù),用于顯示登陸時(shí)間 void All_output(); //函數(shù)[7]全部學(xué)生信息 void the_log(information a,char num[1]); //函數(shù)[8]錄入學(xué)生使用門(mén)禁情況 void log_output(); //函數(shù)[9]輸出學(xué)生使用門(mén)禁情況 void replace_massage(char names[10]); //函數(shù)[10]更改學(xué)生信息,只有管理員有權(quán)限 int main() { int n; printf(" *********************************************\n"); printf(" * 歡迎使用四海門(mén)禁系統(tǒng)!??! *\n"); printf(" *********************************************\n"); printf("\n"); printf(" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*\n"); printf(" *輸入0:退出系統(tǒng); 輸入1:管理員登陸; 輸入2:學(xué)生登陸*\n"); printf(" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*\n"); printf(" "); scanf("%d",&n); while(n!=0) { if(n==1) administrator_login(); else if(n==2) student_login(); else if(n>10||n<0) { printf(" *********************************************\n"); printf(" * 歡迎使用四海門(mén)禁系統(tǒng)?。。? *\n"); printf(" *********************************************\n");break; } printf(" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*\n"); printf(" *輸入0:退出系統(tǒng); 輸入1:管理員登陸; 輸入2:學(xué)生登陸*\n"); printf(" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*\n"); printf(" "); scanf("%d",&n); } printf(" *********************************************\n"); printf(" * 歡迎使用四海門(mén)禁系統(tǒng)?。?! *\n"); printf(" *********************************************\n"); return 0; } void administrator_login() //管理員登錄 { information a; printf(" 請(qǐng)輸入管理員賬號(hào):"); scanf("%s",a.name); printf(" 請(qǐng)輸入管理員密碼:"); scanf("%s",a.password); if(strcmp(a.name,"管理員")==0&&strcmp(a.password,"123456789")==0) { printf("\n"); printf(" *********管理員登陸成功!!!*********\n\n"); administrator_management(); } else { printf( " 管理員登陸失?。。?!請(qǐng)檢查仔細(xì)核對(duì)賬號(hào)、密碼\n"); } } void administrator_management() //管理員操作臺(tái) { int num; printf(" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*\n"); printf(" *輸入1:注冊(cè)學(xué)生賬號(hào) 輸入2:刪除賬號(hào) 輸入3:顯示所有學(xué)生信息*\n"); printf(" *輸入4;查看學(xué)生使用門(mén)禁情況 輸入5:修改學(xué)生信息 輸入6:刷新屏幕 *\n"); printf(" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*\n"); printf(" "); scanf("%d",&num); while(num!=-1) { if(num==0||num>10||num<0) { printf(" 管理員身份已注銷\n"); break; } if(num==1) { fp=fopen("student_Account.txt","a"); information a; printf(" 請(qǐng)輸入賬號(hào):"); scanf("%s",a.name); printf(" 請(qǐng)輸入密碼:"); scanf("%s",a.password); printf(" 請(qǐng)輸入專業(yè)班級(jí):"); scanf("%s",a.profession); add_student(a); fclose(fp); } if(num==2) { char names[10]; printf(" 請(qǐng)輸入要?jiǎng)h除的賬號(hào):"); scanf("%s",names); delete_student(names); } if(num==3) { fp=fopen("student_Account.txt","r"); All_output(); fclose(fp); } if(num==4) { fp=fopen("Thelog.txt","r"); log_output(); fclose(fp); } if(num==5) { char names[10]; fp=fopen("student_Account.txt","r+"); printf(" 請(qǐng)輸入需要修改的賬號(hào):"); scanf("%s",names); replace_massage(names); fclose(fp); } if(num==6) { system("cls"); } printf(" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*\n"); printf(" *輸入1:注冊(cè)學(xué)生賬號(hào) 輸入2:刪除賬號(hào) 輸入3:顯示所有學(xué)生信息*\n"); printf(" *輸入4;查看學(xué)生使用門(mén)禁情況 輸入5:修改學(xué)生信息 輸入6:刷新屏幕 *\n"); printf(" */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*\n"); printf(" "); scanf("%d",&num); } } void student_login() //學(xué)生登錄 { information a; information b; fp=fopen("student_Account.txt","r"); printf(" 請(qǐng)輸入賬號(hào):"); scanf("%s",a.name); printf(" 請(qǐng)輸入密碼:"); scanf("%s",a.password); fread(&b,sizeof(struct information),1,fp); int i=0; while(feof(fp)==0) { if(strcmp(a.name,b.name)==0&&strcmp(a.password,b.password)==0) { char num[1]; printf(" 請(qǐng)選擇要打開(kāi)幾號(hào)門(mén)\n"); printf(" "); scanf("%s",num); time(); printf(" 親愛(ài)的%s童鞋,你成功登陸本系統(tǒng),已開(kāi)啟%s號(hào)門(mén)\n",a.name,num); i++; the_log(a,num); } fread(&b,sizeof(struct information),1,fp); } if(i==0) printf(" 登陸賬號(hào)不存在或密碼錯(cuò)誤!??!若無(wú)賬號(hào)請(qǐng)聯(lián)系管理員分配賬號(hào)\n"); fclose(fp); } void delete_student(char names[10]) //管理員刪除學(xué)生賬號(hào),解除使用門(mén)禁權(quán)限 { FILE *p; information a; int i=0; fp=fopen("student_Account.txt","r"); p=fopen("student.txt","w"); fread(&a,sizeof(struct information),1,fp); while(feof(fp)==0) { if(strcmp(a.name,names)==0) {fread(&a,sizeof(struct information),1,fp);i=1;} else { fwrite(&a,sizeof(struct information),1,p); } fread(&a,sizeof(struct information),1,fp); } if(strcmp(a.name,names)!=0) fwrite(&a,sizeof(struct information),1,p); else i=1; if(i==0) printf(" 賬號(hào)%s不在系統(tǒng)中\(zhòng)n",names); else printf(" 賬號(hào)%s已成刪除\n",names); fclose(fp); fclose(p); remove("student_Account.txt"); rename("student.txt","student_Account.txt"); } void add_student(information a) //管理員添加學(xué)生信息,分配賬號(hào),授權(quán)使用門(mén)禁系統(tǒng) { fseek(fp,-sizeof(struct information),1); fwrite(&a,sizeof(struct information),1,fp); printf(" 添加學(xué)生%s成功!!!\n\n",a.name); } void time() //顯示本地時(shí)間 { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime (&rawtime ); printf(" %s",asctime (timeinfo)); } void All_output() //輸出所有學(xué)生信息 { int i=0; information a; fread(&a,sizeof(struct information),1,fp); while(feof(fp)==0) { printf(" * * * * * * * * * * * * * * * * * * * * * * *\n"); printf(" * 學(xué)生賬號(hào):%-20s*\n",a.name); printf(" * 學(xué)生密碼:%-20s*\n",a.password); printf(" * 專業(yè)班級(jí):%-20s*\n",a.profession); printf(" * * * * * * * * * * * * * * * * * * * * * * *\n"); printf("\n"); i++; fread(&a,sizeof(struct information),1,fp); } if(i==0) printf(" 系統(tǒng)中無(wú)學(xué)生賬號(hào)?。?!\n\n"); } void the_log(information a,char num[1]) //實(shí)時(shí)保存學(xué)生使用門(mén)禁系統(tǒng)情況 { FILE *p; Thelog c; strcpy(c.name,a.name); time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo =localtime ( &rawtime ); strcpy(c.times,asctime (timeinfo)); strcpy(c.num,num); p=fopen("Thelog.txt","a"); fwrite(&c,sizeof(struct Thelog),1,p); fclose(p); } void log_output() //輸出學(xué)生使用門(mén)禁系統(tǒng)情況 { Thelog a; fread(&a,sizeof(struct Thelog),1,fp); while(feof(fp)==0) { printf("%s",a.times); printf("學(xué)生%s登錄了門(mén)禁系統(tǒng),并開(kāi)啟了%s號(hào)門(mén)\n",a.name,a.num); fread(&a,sizeof(struct Thelog),1,fp); } } void replace_massage(char names[10]) //更改學(xué)生信息 { information a; information b; fread(&a,sizeof(struct information),1,fp); if(strcmp(names,a.name)==0) { printf(" 請(qǐng)輸入更改后的賬號(hào):"); scanf("%s",b.name); printf(" 請(qǐng)輸入修改后的密碼:"); scanf("%s",b.password); printf(" 請(qǐng)輸入修改后的專業(yè)班級(jí):"); scanf("%s",b.profession); fseek(fp,-sizeof(struct information),1);//文件指針退回原結(jié)構(gòu)體頭 fwrite(&b,sizeof(struct information),1,fp);//更新聯(lián)系人信息 printf(" 信息更改成功?。?!\n\n"); } else if(feof(fp)==0) replace_massage(names);//遞歸調(diào)用直到找到需要更改的姓名,并完成更改 else printf("%s不在系統(tǒng)中?。?!\n\n",names); }
后期分析
后期可利用單片機(jī)實(shí)現(xiàn)刷卡登錄的門(mén)禁系統(tǒng),利用qt 設(shè)計(jì)可視化程序,在學(xué)生登錄成功后觸發(fā)相應(yīng)的門(mén)開(kāi)啟或關(guān)閉。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C語(yǔ)言編寫(xiě)學(xué)生成績(jī)管理系統(tǒng)
- C語(yǔ)言通訊錄管理系統(tǒng)完整版
- C語(yǔ)言實(shí)現(xiàn)圖書(shū)管理系統(tǒng)
- C語(yǔ)言學(xué)生管理系統(tǒng)源碼分享
- 基于C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單的12306火車售票系統(tǒng)
- C語(yǔ)言職工信息管理系統(tǒng)源碼
- C語(yǔ)言職工管理系統(tǒng)設(shè)計(jì)
- c語(yǔ)言實(shí)現(xiàn)的貨物管理系統(tǒng)實(shí)例代碼(增加刪除 查找貨物信息等功能)
- C語(yǔ)言圖書(shū)管理系統(tǒng)簡(jiǎn)潔版
- C語(yǔ)言數(shù)據(jù)結(jié)構(gòu)之學(xué)生信息管理系統(tǒng)課程設(shè)計(jì)
相關(guān)文章
C++實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12C++內(nèi)存四區(qū)之代碼區(qū)、全局區(qū)、棧區(qū)和堆區(qū)
C++編譯器會(huì)把代碼直接分為四個(gè)小區(qū),弄懂這四小區(qū)對(duì)我們理解內(nèi)存有所幫助,所以下面這篇文章主要給大家介紹了關(guān)于C++內(nèi)存四區(qū)之代碼區(qū)、全局區(qū)、棧區(qū)和堆區(qū)的相關(guān)資料,需要的朋友可以參考下2021-07-07C語(yǔ)言必背的一些經(jīng)典程序代碼實(shí)例
C語(yǔ)言是一種高級(jí)編程語(yǔ)言,具有很多優(yōu)點(diǎn),下面這篇文章主要給大家介紹了關(guān)于C語(yǔ)言必背的一些經(jīng)典程序代碼,文中通過(guò)詳細(xì)的實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05C/C++ Qt TreeWidget 嵌套節(jié)點(diǎn)操作使用
本文主要介紹了TreeWidget的如何使用,實(shí)現(xiàn)對(duì)樹(shù)形框多節(jié)點(diǎn)的各種操作,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-11-11《戰(zhàn)狼》中兩軍作戰(zhàn)入侵代碼竟然是輸出星期幾的!
這篇文章主要介紹了《戰(zhàn)狼》中兩軍作戰(zhàn)入侵代碼竟然是輸出星期幾的,喜歡戰(zhàn)狼和編程的同學(xué)可以了解下。2017-11-11