打卡系统
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
#define ONEHOUR 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_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;
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);
time_start=start_time+(ONEHOUR*7);
creat_staff();
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);
}
else if(number_in==s3.number)
{
s3.work.clock_in_time=time(NULL);
}
else if(number_in==s4.number)
{
s4.work.clock_in_time=time(NULL);
}
else if(number_in==s5.number)
{
s5.work.clock_in_time=time(NULL);
}
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;
}
}