教你30元自制考勤打卡系統(tǒng)!

2021年4月,為了簡化班級早自習(xí)考勤簽到流程,我利用校園卡,獨立制作了一個簡易考勤打卡系統(tǒng)。整個打卡系統(tǒng)一共花了我32元人民幣。

首先我在網(wǎng)購軟件上購買了一個能讀取IC卡卡號的讀卡器(現(xiàn)在網(wǎng)購軟件上隨手一找最便宜的那種就行了,現(xiàn)在好像20元左右就可以了,我的主要是不確定我們校園卡的ID號長度所以買的讀取長度長),將所有同學(xué)的校園卡卡號存儲到CSV文件中并與學(xué)號和姓名一一對應(yīng)。


image.png

然后是程序的編寫——通過C++文件流對CSV文件讀取得到學(xué)生信息并存儲到結(jié)構(gòu)體中,運用標志數(shù)組判斷每個同學(xué)是否已考勤……反正實現(xiàn)其實很簡單,主要是知道讀卡器上刷卡相當(dāng)于在電腦在編輯的文件or程序框里面輸入卡號并換行。
之后的早自習(xí)考勤,我只需要將讀卡器連上電腦并運行程序,班級同學(xué)在讀卡器刷一下校園卡或輸入學(xué)號就可以進行考勤。


image.png

在考勤過程中,我還可以通過自己的查詢命令,實時查詢當(dāng)次還沒打卡的同學(xué)名單。同時,考勤程序?qū)崟r將考勤信息輸出到CSV文件,考勤結(jié)束后我可以通過輸出的文件得知各位同學(xué)考勤的具體時間。


image.png

以下給出具體代碼

#include<cstdio>
#include<iostream>
#include<cstring>
#include<windows.h>
#include<time.h>
using namespace std;
struct Student{
    string CardNum,StudentID,Name;
    int Class,Num;
    bool Sex;
}student[10000];
bool IsBeated[5050];
bool Checked[5050];
static string GetCurrentDateStr()
{
    time_t t = time(NULL);
    char ch[64] = {0};
    strftime(ch, sizeof(ch) - 1, "%Y%m%d%p", localtime(&t));
    return ch;
}
static string GetCurrentTimeStr()
{
    time_t t = time(NULL);
    char ch[64] = {0};
    strftime(ch, sizeof(ch) - 1, "%H:%M:%S", localtime(&t));
    return ch;
}
int main(){
    cout<<"----------------------------------------------------------"<<endl;
    cout<<"Welcome to AA Grade 2020,Class 1 of UESTC BeatCard System!"<<endl;
    cout<<"----------------------------------------------------------"<<endl<<endl;
    cout<<"--------------------------------------------"<<endl;
    cout<<"Loading data..."<<endl;
    freopen("data.csv","r",stdin);
    // freopen("datatry.csv","r",stdin);
    string temp;
    int num1=0;
    while(cin>>temp){
        student[num1].CardNum=temp.substr(1,18);
        student[num1].StudentID=temp.substr(21,13);
        student[num1].Name=temp.substr(37,temp.length());
        if(temp.substr(35,1).compare("b")==0)student[num1].Sex=1;
        else student[num1].Sex=0;
        char* ID=(char*)student[num1].StudentID.substr(8,5).c_str();
        student[num1].Class=(ID[0]-'0')*10+(ID[1]-'0');
        student[num1].Num=(ID[3]-'0')*10+(ID[4]-'0');
        num1++;
    }
    // for(int i=0;i<num1;i++)cout<<student[i].Name<<' '<<student[i].StudentID<<' '<<student[i].CardNum<<endl;
    cin.clear();
    for(int i=0;i<num1;i++){
        IsBeated[student[i].Class*100+student[i].Num]=0;
    }
    cout<<"Data loading sucessfully! Ready to BeatCard!"<<endl;
    cout<<"--------------------------------------------"<<endl<<endl;
    cout<<"---------------------------------------------"<<endl;
    cout<<"Just put your student ID card on the machine."<<endl;
    cout<<"Enter \"quit\" / \"exit\" to exit the system."<<endl;
    cout<<"---------------------------------------------"<<endl<<endl;
    cout<<"------------------"<<endl;
    freopen("CON","r",stdin);
    string Filename;
    string Time=GetCurrentDateStr();
    Filename="log//"+Time+".csv";
    freopen(Filename.c_str(),"a",stdout);
    cout<<"StudentID"<<','<<"Class"<<','<<"Num"<<','<<"Name"<<','<<"EnterTime"<<endl;
    flag:
    while(cin>>temp){
        Time=GetCurrentTimeStr();
        if(temp.compare("exit")==0||temp.compare("quit")==0)break;
        bool IsFound=0;
        // cout<<temp<<endl;
        for(int i=0;i<num1&&!IsFound;i++){
            if(temp.compare(student[i].CardNum)==0||temp.compare(student[i].StudentID)==0){
                IsFound=1;
                if(IsBeated[student[i].Class*100+student[i].Num]==1){
                    freopen("CON","w",stdout);
                    cout<<"You had beat the card!"<<endl<<endl;
                    freopen(Filename.c_str(),"a",stdout);
                    break;
                }
                IsBeated[student[i].Class*100+student[i].Num]=1;
                cout<<"#"+student[i].StudentID<<','<<student[i].Class<<','<<student[i].Num<<','<<student[i].Name<<','<<Time<<endl;
                freopen("CON","w",stdout);
                string Adj;
                if(student[i].Sex)Adj="handsome ";
                else Adj="beautiful ";
                cout<<"The time is "+Time<<endl;
                cout<<"Welcome "+Adj+student[i].Name<<" !"<<endl<<endl;
                freopen(Filename.c_str(),"a",stdout);
            }
        }
        if(IsFound==0){
            freopen("CON","w",stdout);
            cout<<"Error, please change another card!"<<endl<<endl;
            freopen(Filename.c_str(),"a",stdout);
        }
    }
    freopen("CON","w",stdout);
    cout<<"------------------"<<endl;
    cout<<endl<<"-------------------------------------"<<endl;
    memset(Checked,0,sizeof(Checked));
    int NoHereNum=0;
    for(int i=0;i<num1;i++){
        if(IsBeated[student[i].Class*100+student[i].Num]==0&&Checked[student[i].Class*100+student[i].Num]==0){
            NoHereNum++;
            cout<<"Class."<<student[i].Class<<" NO.";
            if(student[i].Num<10)cout<<'0';
            cout<<student[i].Num;
            if(student[i].Name.length()==4)cout<<" ";
            cout<<' '<<student[i].Name;
            if(student[i].Name.length()==4)cout<<" ";
            cout<<" is not here!"<<endl;
            Checked[student[i].Class*100+student[i].Num]=1;
            // IsBeated[student[i].Class][student[i].Num]=1;
        }
    }
    if(NoHereNum==0)cout<<"Congratulations! All people are here!"<<endl;
    cout<<"-------------------------------------"<<endl<<endl;
    cout<<"--------------------------------------------------------------"<<endl;
    cout<<"Enter \"quit\" / \"exit\" to quit or enter \"continue\" to continue."<<endl;
    cout<<"--------------------------------------------------------------"<<endl<<endl;
    cout<<"------------------"<<endl;
    while(cin>>temp){
        if(temp.compare("exit")==0||temp.compare("quit")==0)break;
        if(temp.compare("continue")==0){
            cout<<"------------------"<<endl<<endl;
            cout<<"------------------"<<endl;
            freopen(Filename.c_str(),"a",stdout);
            goto flag;
        }
    }
    cout<<"------------------"<<endl;
    return 0;
}

小彩蛋~看看當(dāng)時學(xué)期始末的考勤簽到情況表!綠色是請假,黃色是遲到,紅色是缺勤。有壞蛋一直不來?。?!


學(xué)期初考勤情況
學(xué)期末考勤情況
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容