打卡系统练习

打卡系统

main.c

#include "clock_in.h"

int main()
{
     
    clockin_machine_start();
    return 0;
}

clock_in.h

#ifndef __CLOCK_IN_H__
#define __CLOCK_IN_H__

#include 
#include 
#include 
#include 


#define ONEDAY 144                 //一天144秒
#define ONEHOUR 6                  //一小时6秒
#define WORKTIME 9                 //工作时间

typedef struct st
{
     
    int age;
    int number;
    int phone;
    char name[20];
    char sex[10];
    char email[20];
    struct work_inf{
     
        time_t clock_in_time;              //上班打卡时间
        time_t clock_out_time;             //下班打卡时间        
        //int clock_frequency;            //打卡次数
        int clock_in_frequency;           //班打卡次数
        int clock_out_frequency;           //下班打卡次数
        int be_late_number;                //迟到次数
        int leave_early_number;            //早退次数
     }work;
}st;

st s1,s2,s3,s4,s5;


int number_out;                    //下班打卡工号
time_t clock_in_time;              //上班打卡时间
time_t start_time;              //上班打卡时间
time_t clock_out_time;             //下班打卡时间
time_t clock_time;                  //判断打卡时间
time_t judge_time;                   //判断关机时间 
long int time_start;               //理论开机时间周一7am
int number_in;                        //上班打卡工号 

int clock_in_frequency[5];           //上班打卡次数
int clock_out_frequency[5];           //下班打卡次数
int be_late_number[5];                //迟到次数
int leave_early_number[5];            //早退次数    


void clockin_machine_start();           //打卡机
void creat_staff();                     //创建员工信息
int judge_staff(int num);               //判断工号
int clock_in();                         //上班打卡
int clock_out();                        //下班打卡
int clock_suc();                        //判断出勤
int Week_Report();                      //周报
void InsertSort1(int a[], int n);       //排序


#endif

clock_in.c

#include "clock_in.h"

void clockin_machine_start()          //打卡机
{
        
    int a,b;
    printf("开机\n");
    printf("=====================\n");
    start_time = time(NULL);                    //设定开机时间(s)
    //printf("%ld\n",start_time); 
    time_start=start_time+(ONEHOUR*7);   
    creat_staff();                              //创建员工信息
    //printf("%ld\n",time_start);

    while(1)
    {
     
        clock_time=time(NULL);                  //判断打卡时间
        if(((clock_time-start_time)%ONEDAY)/ONEHOUR<=12)  //上班打卡
        {
     
            a=clock_in();
            if(a==0)
            {
        
                if(number_in==s1.number)
                {
        
                    s1.work.clock_in_time=time(NULL);
                }
                else if(number_in==s2.number)
                {
        
                    s2.work.clock_in_time=time(NULL);
                    //printf("s2work=%ld\n",s2.work.clock_in_time);
                }
                else if(number_in==s3.number)
                {
        
                    s3.work.clock_in_time=time(NULL);
                    //printf("s2work=%ld\n",s3.work.clock_in_time);
                }   
                else if(number_in==s4.number)
                {
        
                    s4.work.clock_in_time=time(NULL);
                    //printf("s2work=%ld\n",s4.work.clock_in_time);
                }   
                else if(number_in==s5.number)
                {
       
                    s5.work.clock_in_time=time(NULL);
                    //printf("s2work=%ld\n",s5.work.clock_in_time);
                } 

                else
                {
     
                    printf("=============================\n");
                    printf("||       上班打卡失败      ||\n");
                    printf("||       请重新打卡!       ||\n");
                    printf("=============================\n");
                }
            }
        }
        else                                           //下班打卡
        {
     
            b=clock_out();
            if(b==0)
            {
     
                if(number_out==s1.number)
                {
     
                    s1.work.clock_out_time=time(NULL);
                }
                else if(number_out==s2.number)
                {
     
                    s2.work.clock_out_time=time(NULL);
                }
                else if(number_out==s3.number)
                {
     
                    s3.work.clock_out_time=time(NULL);
                }
                else if(number_out==s4.number)
                {
     
                    s4.work.clock_out_time=time(NULL);
                }
                else if(number_out==s5.number)
                {
     
                    s5.work.clock_out_time=time(NULL);
                }
                else
                {
     
                    printf("=============================\n");
                    printf("||       下班打卡失败      ||\n");
                    printf("||       请重新打卡!       ||\n");
                    printf("=============================\n");
                }
            }
        }
        //通过开机时间、打卡时间判断打卡是否成功
        clock_suc();
        
        judge_time=time(NULL);                          //判断关机时间
        if((judge_time-start_time)/ONEDAY>=5)
        {
     
            int week_report();                          //输出周报 
            printf("打卡机关机!\n");
            break;
        }
    }
}

//上班打卡判定
int clock_in()
{
     
    int n1,n2,n3,n4,n5;
    int verification,verification_inside;
    printf("---------\n");
    printf("请上班打卡\n");
    printf("---------\n");
    printf("请输入工号:\n");
    scanf("%d",&number_in);
    if(number_in/100000==0)
    {
     
        printf("===============================\n");
        printf(" ||       请输入正确工号     ||\n");                         
        printf(" ||       上班打卡失败!     ||\n");
        printf("===============================\n");
    }
    n1=(number_in/10000)-10;
    n2=(number_in/1000)-(100+(n1*10));
    n3=(number_in/100)-(1000+(n1*100)+(n2*10));
    n4=(number_in/10)-(10000+(n1*1000)+(n2*100)+(n3*10));
    n5=(number_in-((100000)+(n1*10000)+(n2*1000)+(n3*100)+(n4*10)));
    
    //判断验证码是否正确
    verification_inside=100000+((n1+n5)*10000)+((n2+n4)*1000)+(n3*2*100)+((n2+n4)*10)+(n1+n5);
    printf("请输入验证码:\n");
    scanf("%d",&verification);

    if(verification_inside==verification||judge_staff(number_in)!=0)
    {
     
        printf("===============================\n");
        printf(" ||       上班打卡成功!     ||\n");
        printf("===============================\n");
    }
    else if(judge_staff(number_in)==0)
    {
     
        printf("===============================\n");
        printf(" ||         工号错误!       ||\n");
        printf("===============================\n");

    }
    else
    {
     
        printf("验证码错误\n");
        return -1;
    }

    return 0;
}

//下班打卡
int clock_out()
{
     
    int number_out;
    printf("---------\n");
    printf("请下班打卡\n");
    printf("---------\n");
    printf("请输入工号:\n");
    scanf("%d",&number_out);
    printf("--%d,--%d\n",number_in,number_out);
    if(number_out/100000==0&&judge_staff(number_out)==0)
    {
                  
        printf("===============================\n");
        printf(" ||       请输入正确工号     ||\n");
        printf(" ||       下班打卡失败!     ||\n");
        printf("===============================\n");
        return -1;
    }
    if((number_in)=(number_out)||judge_staff(number_out)!=0)
    {
     
        printf("您的工号为:%d\n",number_out);
        printf("===============================\n");
        printf(" ||       下班打卡成功!     ||\n");
        printf("===============================\n");
        return 0;
    }
    else
    {
     
        printf("工号不符\n");
    }
    return 0;
}

//判断出勤参数
int clock_suc()
{
            
    //判断上班打卡次数
    if(number_in==s1.number&&(((s1.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>0&&(((s1.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)<=8)
    {
     
        printf("打卡成功\n");
        s1.work.clock_in_frequency++;
        printf("王一上班打卡次数:%d\n",s1.work.clock_in_frequency);
    }
    else if(number_in==s2.number&&(((s2.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>0&&(((s2.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)<=8)
    {
     
        printf("打卡成功\n");
        s2.work.clock_in_frequency++;
        printf("王二上班打卡次数:%d\n",s2.work.clock_in_frequency);
    }
    else if(number_in==s3.number&&(((s3.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>0&&(((s3.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)<=8)
    {
     
        printf("打卡成功\n");
        s3.work.clock_in_frequency++;
        printf("王三上班打卡次数:%d\n",s3.work.clock_in_frequency);                 
    }
    else if(number_in==s4.number&&(((s4.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>0&&(((s4.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)<=8)
    {
     
        printf("打卡成功\n");
        s4.work.clock_in_frequency++;
        printf("王四上班打卡次数:%d\n",s4.work.clock_in_frequency);                 
    }
    else if(number_in==s5.number&&(((s5.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>0&&(((s5.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)<=8)
    {
     
        printf("打卡成功\n");
        s5.work.clock_in_frequency++;
        printf("王五上班打卡次数:%d\n",s5.work.clock_in_frequency);                 
    }
   
//判断迟到次数
    if(number_in==s1.number&&(((s1.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>8)
    {
     
        printf("迟到了\n");
        s1.work.be_late_number++;
        printf("迟到次数:%d\n",s1.work.be_late_number);
    }
    else if(number_in==s2.number&&(((s2.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>8)
    {
     
        printf("迟到了\n");
        s2.work.be_late_number++;
        printf("迟到次数:%d\n",s2.work.be_late_number);
    }
    else if(number_in==s3.number&&(((s3.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>8)
    {
     
        printf("迟到了\n");                                                          
        s3.work.be_late_number++;
        printf("迟到次数:%d\n",s3.work.be_late_number);
    }
    else if(number_in==s4.number&&(((s4.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>8)
    {
     
        printf("迟到了\n");
        s4.work.be_late_number++;
        printf("迟到次数:%d\n",s4.work.be_late_number);
    }
    else if(number_in==s5.number&&(((s5.work.clock_in_time - start_time)%ONEDAY)/ONEHOUR)>8)
    {
     
        printf("迟到了\n");                                                          
        s5.work.be_late_number++;
        printf("迟到次数:%d\n",s5.work.be_late_number);
    }
  
//判断早退次数
    if(number_out==s1.number&&(((s1.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)<17||(((s1.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)>12)
    {
     
        printf("早退了\n");
        s1.work.leave_early_number++;
        printf("早退次数:%d\n",s1.work.leave_early_number);
    }
    else if((number_out==s2.number)&&(((s2.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)<17||(((s2.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)>12)
    {
     
        printf("早退了\n");
        s2.work.leave_early_number++;
        printf("早退次数:%d\n",s2.work.leave_early_number);
    }
    else if((number_out==s3.number)&&(((s3.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)<17||(((s3.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)>12)
    {
     
        printf("早退了\n");
        s3.work.leave_early_number++;
        printf("早退次数:%d\n",s3.work.leave_early_number);
    }
    else if((number_out==s4.number)&&(((s4.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)<17||(((s4.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)>12)
    {
     
        printf("早退了\n");
        s4.work.leave_early_number++;
        printf("早退次数:%d\n",s4.work.leave_early_number);
    }
    else if((number_out==s5.number)&&(((s5.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)<17||(((s5.work.clock_out_time - start_time)%ONEDAY)/ONEHOUR)>12)
    {
     
        printf("早退了\n");
        s5.work.leave_early_number++;
        printf("早退次数:%d\n",s5.work.leave_early_number);
    } 

   
    
//判断下班打卡次数
    if(number_out==s1.number&&(((clock_out_time - start_time)%ONEDAY)/ONEHOUR)>17)
    {
     
        printf("下班了\n");
        s1.work.clock_out_frequency++;
        printf("下班打卡次数:%d\n",s1.work.clock_out_frequency);
    }
    else if(number_out==s2.number&&(((clock_out_time - start_time)%ONEDAY)/ONEHOUR)>17)
    {
     
        printf("下班了\n");
        s2.work.clock_out_frequency++;
        printf("下班打卡次数:%d\n",s2.work.clock_out_frequency);
    }
    else if(number_out==s3.number&&(((clock_out_time - start_time)%ONEDAY)/ONEHOUR)>17)
    {
     
        printf("下班了\n");
        s3.work.clock_out_frequency++;
        printf("下班打卡次数:%d\n",s3.work.clock_out_frequency);
    }
    else if(number_out==s4.number&&(((clock_out_time - start_time)%ONEDAY)/ONEHOUR)>17)
    {
     
        printf("下班了\n");
        s4.work.clock_out_frequency++;
        printf("下班打卡次数:%d\n",s4.work.clock_out_frequency);
    }
    else if(number_out==s5.number&&(((clock_out_time - start_time)%ONEDAY)/ONEHOUR)>17)
    {
     
        printf("下班了\n");
        s5.work.clock_out_frequency++;
        printf("下班打卡次数:%d\n",s5.work.clock_out_frequency);
    }
   

    return 0;
}

//排序
void insertsort1(int a[], int n)
{
     
    int i, j;
    for(i=1; i<n; i++)
    {
     
        if(a[i] < a[i-1])   
        {
     
            int temp = a[i];                       //保存要比较的值
            for(j=i-1; j>=0 && a[j]>temp; j--)    //从后向前查找待插入位置
                a[j+1] = a[j];                    //挪位
            a[j+1] = temp;                       //复制到插入位置
        }
    }
}


//周报         
int week_report()
{
     
    printf("=================================\n");
    printf("             工作周报            \n");
    printf("=================================\n");
    
    int clock_in_frequency[5]={
     s1.work.clock_in_frequency,s2.work.clock_in_frequency,s3.work.clock_in_frequency,s4.work.clock_in_frequency,s5.work.clock_in_frequency};           //上班打卡次数
    int clock_out_frequency[5]={
     s1.work.clock_out_frequency,s2.work.clock_out_frequency,s3.work.clock_out_frequency,s4.work.clock_out_frequency,s5.work.clock_out_frequency};           //下班打卡次数
    int be_late_number[5]={
     s1.work.be_late_number,s2.work.be_late_number,s3.work.be_late_number,s4.work.be_late_number,s5.work.be_late_number};                //迟到次数
    int leave_early_number[5]={
     s1.work.leave_early_number,s2.work.leave_early_number,s3.work.leave_early_number,s4.work.leave_early_number,s5.work.leave_early_number};            //早退次数         

    insertsort1(clock_in_frequency,5);  
    insertsort1(clock_out_frequency,5);
    insertsort1(be_late_number,5);
    insertsort1(leave_early_number,5);

    if(clock_in_frequency[4]==s1.work.clock_in_frequency)
    {
     
        printf("上班打卡次数最多的是%s\n",s1.name);
    }
    else if(clock_in_frequency[4]==s2.work.clock_in_frequency)
    {
     
        printf("上班打卡次数最多的是%s\n",s2.name);
    }
    else if(clock_in_frequency[4]==s3.work.clock_in_frequency)
    {
     
        printf("上班打卡次数最多的是%s\n",s3.name);                              
    }
    else if(clock_in_frequency[4]==s4.work.clock_in_frequency)
    {
     
    printf("上班打卡次数最多的是%s\n",s4.name);
    }
    else if(clock_in_frequency[4]==s5.work.clock_in_frequency)
    {
     
    printf("上班打卡次数最多的是%s\n",s5.name);                              
    }
    else{
     
        printf("error\n");
    }

    if(clock_out_frequency[4]==s1.work.clock_out_frequency)
    {
     
    printf("下班打卡次数最多的是%s\n",s1.name);
    }
    else if(clock_out_frequency[4]==s2.work.clock_out_frequency)
    {
     
    printf("下班打卡次数最多的是%s\n",s2.name);                              
    }
    else if(clock_out_frequency[4]==s3.work.clock_out_frequency)
    {
     
    printf("下班打卡次数最多的是%s\n",s3.name);
    }
    else if(clock_out_frequency[4]==s4.work.clock_out_frequency)
    {
      
    printf("下班打卡次数最多的是%s\n",s4.name);
    }
    else if(clock_out_frequency[4]==s5.work.clock_out_frequency)
    {
     
    printf("下班打卡次数最多的是%s\n",s5.name);
    }
    else{
     
    printf("error\n");
    }

    if(be_late_number[4]==s1.work.be_late_number)
    {
     
    printf("迟到次数最多的是%s\n",s1.name);
    }
    else if(be_late_number[4]==s2.work.be_late_number)
    {
     
    printf("迟到次数最多的是%s\n",s2.name);
    }
    else if(be_late_number[4]==s3.work.be_late_number)
    {
     
    printf("迟到次数最多的是%s\n",s3.name);
    }
    else if(be_late_number[4]==s4.work.be_late_number)
    {
     
    printf("迟到次数最多的是%s\n",s4.name);
    }
    else if(be_late_number[4]==s5.work.be_late_number)
    {
     
    printf("迟到次数最多的是%s\n",s5.name);
    }
    else{
     
    printf("error\n");
    }

    if(leave_early_number[4]==s1.work.leave_early_number)
    {
     
    printf("早退次数最多的是%s\n",s1.name);
    }
    else if(leave_early_number[4]==s1.work.leave_early_number)
    {
     
    printf("早退次数最多的是%s\n",s2.name);
    }
    else if(leave_early_number[4]==s3.work.leave_early_number)
    {
     
    printf("早退次数最多的是%s\n",s3.name);
    }
    else if(leave_early_number[4]==s4.work.leave_early_number)
    {
     
    printf("早退次数最多的是%s\n",s4.name);
    }
    else if(leave_early_number[4]==s5.work.leave_early_number)
    {
     
    printf("早退次数最多的是%s\n",s5.name);
    }
    else{
     
    printf("error\n");
    }


    return 0;
}

//创建员工信息
void creat_staff()
{
     
    s1.number=123456;
    s1.age=20;
    s1.phone=1888888888;
    strcpy(s1.name,"王一");
    strcpy(s1.sex,"男");
    strcpy(s1.email,"[email protected]");
    

    s2.number=123455;
    s2.age=20;
    s2.phone=1888888888;
    strcpy(s2.name,"王二");
    strcpy(s2.sex,"男");
    strcpy(s2.email,"[email protected]");


    s3.number=123454;
    s3.age=20;
    s3.phone=1888888888;
    strcpy(s3.name,"王三");
    strcpy(s3.sex,"男");
    strcpy(s3.email,"[email protected]");


    s4.number=123453;
    s4.age=20;
    s4.phone=1888888888;
    strcpy(s4.name,"王四\0");
    strcpy(s4.sex,"男\0");
    strcpy(s4.email,"[email protected]\0");


    s5.number=123452;
    s5.age=20;
    s5.phone=1888888888;
    strcpy(s5.name,"王五");
    strcpy(s5.sex,"男");
    strcpy(s5.email,"123456'q.com");
                           
}

//判断工号
int judge_staff(int num)
{
     
    if(num==s1.number)
    {
     
        return 1;
    }
    else if(num==s1.number)
    {
     
        return 1;
    }
    else if(num==s1.number)
    {
     
        return 1;
    }
    else if(num==s1.number)
    {
     
        return 1;
    }
    else if(num==s1.number)
    {
     
        return 1;
    }
    else
    {
     
        return 0;
    }
}


你可能感兴趣的:(c,练习,linux)