最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言簡單實現(xiàn)門禁系統(tǒng)

 更新時間:2019年01月21日 14:10:45   作者:我是四海  
這篇文章主要為大家詳細介紹了C語言簡單實現(xiàn)門禁系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下

問題提出

用C語言實現(xiàn)門禁系統(tǒng)功能。

功能簡析

1、系統(tǒng)登錄分為管理員登錄和學生登錄,輸入相應字符即可選擇登錄;

這里寫圖片描述 

2、學生登錄,學生使用自己的賬號密碼登錄系統(tǒng),選擇開啟的門,即可開啟門禁;此外系統(tǒng)還會記錄下學生登錄的信息,如登錄賬號、登錄時間、開啟哪間門;

這里寫圖片描述 

3、管理員登錄,管理員登錄也是要輸入特定的賬號密碼才能登錄;登錄之后才能進入管理員操作界面進行相應操作,如添加學生賬號、刪除學生賬號、查看學生基本信息、查看學生登錄情況……輸入相應字符即可選擇執(zhí)行相應的功能。

這里寫圖片描述 

4、管理員權限一:添加學生賬號。輸入學生姓名(即為賬號)、密碼、專業(yè)班級等基本信息,可用于后續(xù)查詢,回車完成添加。查看系統(tǒng)中學生信息,該賬號已存在

這里寫圖片描述 

5、管理員權限二:刪除學生賬號。輸入需要刪除的賬號,回車完成刪除操作,查看系統(tǒng)數(shù)據(jù)庫中已無該學生信息。

這里寫圖片描述 

6、管理員權限三:查看所以學生基本信息。輸入相應字符,即可查詢所以信息

這里寫圖片描述 

7、管理員權限四:查看學生登錄門禁系統(tǒng)情況。輸入相應相應字符,可按學生使用門禁系統(tǒng)時間先后順序一次顯示學生賬號、登錄時間,選擇開啟的門。

這里寫圖片描述 

8、管理員權限五:修改存在于系統(tǒng)的學生信息。輸入需要修改的學生賬號,并輸入修改后的賬號、密碼、專業(yè)班級等基本信息。

這里寫圖片描述

實現(xiàn)關鍵

首先考慮到要對學生賬號等基本數(shù)據(jù)要重復使用,且易更改,下次使用時上次修改的信息還會存在而不是對代碼進行修改,所以考慮使用對文本進行操作。將學生賬號密碼等數(shù)據(jù)信息全部儲存在一個txt或dat文本中,調(diào)用函數(shù)對文本進行相應操作,對數(shù)據(jù)的操作即是對文件的操作。

代碼實現(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]管理員添加學生賬號,使用門禁系統(tǒng) 
void delete_student(char names[10]);//函數(shù)[2]管理員員刪除學生賬號,解除使用門禁系統(tǒng)權限 
void administrator_login();  //函數(shù)[3]管理員登陸 
void administrator_management(); //函數(shù)[4]管理員操作界面,添加學生賬號,刪除學生賬號,查看學生使用門禁情況 
void student_login();   //函數(shù)[5]學生登陸,用于打開門禁 
void time ();     //函數(shù)[6]時間函數(shù),用于顯示登陸時間 
void All_output();    //函數(shù)[7]全部學生信息 
void the_log(information a,char num[1]); //函數(shù)[8]錄入學生使用門禁情況 
void log_output();       //函數(shù)[9]輸出學生使用門禁情況 
void replace_massage(char names[10]);  //函數(shù)[10]更改學生信息,只有管理員有權限 
int main()
{
 int n;
 printf("   *********************************************\n");
 printf("   *   歡迎使用四海門禁系統(tǒng)?。。? *\n");
 printf("   *********************************************\n");
 printf("\n");
 printf("   */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*\n");
 printf("   *輸入0:退出系統(tǒng); 輸入1:管理員登陸; 輸入2:學生登陸*\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("   *   歡迎使用四海門禁系統(tǒng)?。?!  *\n");
  printf("   *********************************************\n");break;
 }
 printf("   */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*\n");
 printf("   *輸入0:退出系統(tǒng); 輸入1:管理員登陸; 輸入2:學生登陸*\n");
 printf("   */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*\n");
  printf(" ");
  scanf("%d",&n);
 }
  printf("   *********************************************\n");
  printf("   *   歡迎使用四海門禁系統(tǒng)?。。? *\n");
  printf("   *********************************************\n");
 return 0;
}
void administrator_login()   //管理員登錄 
{
 information a;

 printf(" 請輸入管理員賬號:");
 scanf("%s",a.name);
 printf(" 請輸入管理員密碼:");
 scanf("%s",a.password);
 if(strcmp(a.name,"管理員")==0&&strcmp(a.password,"123456789")==0)
  {
  printf("\n");
  printf(" *********管理員登陸成功!!!*********\n\n");
  administrator_management();
  }
  else
  {
  printf( "    管理員登陸失敗?。。≌垯z查仔細核對賬號、密碼\n"); 
  }

}
void administrator_management() //管理員操作臺 
{
 int num;
 printf("   */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*\n");
 printf("   *輸入1:注冊學生賬號   輸入2:刪除賬號  輸入3:顯示所有學生信息*\n"); 
 printf("   *輸入4;查看學生使用門禁情況 輸入5:修改學生信息 輸入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("   請輸入賬號:");
  scanf("%s",a.name);
  printf("   請輸入密碼:");
  scanf("%s",a.password);
  printf("  請輸入專業(yè)班級:");
  scanf("%s",a.profession);
   add_student(a);
  fclose(fp);
  }
   if(num==2)
  {
  char names[10];
  printf(" 請輸入要刪除的賬號:");
  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(" 請輸入需要修改的賬號:");
    scanf("%s",names);
    replace_massage(names);
    fclose(fp);
   }
   if(num==6)
   {
   system("cls");
   }
 printf("   */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*\n");
 printf("   *輸入1:注冊學生賬號   輸入2:刪除賬號  輸入3:顯示所有學生信息*\n"); 
 printf("   *輸入4;查看學生使用門禁情況 輸入5:修改學生信息 輸入6:刷新屏幕  *\n");
 printf("   */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*\n");
  printf(" ");
  scanf("%d",&num);
 }
}
void student_login()    //學生登錄 
{
 information a;
 information b;
 fp=fopen("student_Account.txt","r");
 printf(" 請輸入賬號:");
 scanf("%s",a.name);
 printf(" 請輸入密碼:");
 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(" 請選擇要打開幾號門\n");
  printf(" ");
  scanf("%s",num);

   time();
   printf(" 親愛的%s童鞋,你成功登陸本系統(tǒng),已開啟%s號門\n",a.name,num);
   i++;
  the_log(a,num);

  }
  fread(&b,sizeof(struct information),1,fp);
 }
 if(i==0)
  printf(" 登陸賬號不存在或密碼錯誤?。?!若無賬號請聯(lián)系管理員分配賬號\n");
 fclose(fp);
}
void delete_student(char names[10])  //管理員刪除學生賬號,解除使用門禁權限 
{ 
 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(" 賬號%s不在系統(tǒng)中\(zhòng)n",names);
  else
  printf(" 賬號%s已成刪除\n",names);
 fclose(fp);
 fclose(p);
 remove("student_Account.txt");
 rename("student.txt","student_Account.txt");
}
void add_student(information a)  //管理員添加學生信息,分配賬號,授權使用門禁系統(tǒng) 
{

   fseek(fp,-sizeof(struct information),1);
   fwrite(&a,sizeof(struct information),1,fp);
   printf("  添加學生%s成功!!!\n\n",a.name);


}
void time()       //顯示本地時間 
{
 time_t rawtime;
 struct tm * timeinfo;

time ( &rawtime );
timeinfo = localtime (&rawtime );
printf(" %s",asctime (timeinfo));
}
void All_output()     //輸出所有學生信息 
{
 int i=0;
 information a;

 fread(&a,sizeof(struct information),1,fp);
 while(feof(fp)==0)
 {
  printf("      * * * * * * * * * * * * * * * * * * * * * * *\n");
  printf("      *    學生賬號:%-20s*\n",a.name);
  printf("      *    學生密碼:%-20s*\n",a.password);
  printf("      *    專業(yè)班級:%-20s*\n",a.profession);
  printf("      * * * * * * * * * * * * * * * * * * * * * * *\n");
  printf("\n");
  i++;
 fread(&a,sizeof(struct information),1,fp);
 } 
 if(i==0)
 printf("    系統(tǒng)中無學生賬號?。。n\n");

}
void the_log(information a,char num[1])    //實時保存學生使用門禁系統(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()        //輸出學生使用門禁系統(tǒng)情況 
{ 
 Thelog a;

 fread(&a,sizeof(struct Thelog),1,fp);
 while(feof(fp)==0)
 {
  printf("%s",a.times);
  printf("學生%s登錄了門禁系統(tǒng),并開啟了%s號門\n",a.name,a.num);
 fread(&a,sizeof(struct Thelog),1,fp);
 }

}
void replace_massage(char names[10])   //更改學生信息 
{
 information a;
 information b;
 fread(&a,sizeof(struct information),1,fp);
 if(strcmp(names,a.name)==0)
 {
 printf("  請輸入更改后的賬號:");
 scanf("%s",b.name);
 printf("  請輸入修改后的密碼:");
 scanf("%s",b.password);
 printf(" 請輸入修改后的專業(yè)班級:");
 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);

}

后期分析

后期可利用單片機實現(xiàn)刷卡登錄的門禁系統(tǒng),利用qt 設計可視化程序,在學生登錄成功后觸發(fā)相應的門開啟或關閉。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

望都县| 玉龙| 饶河县| 治县。| 墨玉县| 麻江县| 崇明县| 莫力| 阳信县| 施甸县| 将乐县| 同德县| 偃师市| 南安市| 民权县| 稻城县| 吉安县| 朝阳区| 陆丰市| 时尚| 崇仁县| 福泉市| 蒙阴县| 巴楚县| 乐陵市| 舟山市| 拉萨市| 万盛区| 稷山县| 泸水县| 汉沽区| 雷山县| 浙江省| 拉孜县| 武平县| 铁岭县| 托克托县| 合川市| 阳泉市| 安远县| 石台县|