签到C语言实现.docx
- 文档编号:30231786
- 上传时间:2023-08-07
- 格式:DOCX
- 页数:32
- 大小:21.56KB
签到C语言实现.docx
《签到C语言实现.docx》由会员分享,可在线阅读,更多相关《签到C语言实现.docx(32页珍藏版)》请在冰豆网上搜索。
签到C语言实现
#include
#include
#include
#include
#include
#include
#defineINPUT_LEN6
/*统计某十五天内64位员工的上班迟到早退的次数,星期天和星期六系统自动关闭;
假设员工上下班都在标准点±1小时,不存在迟到或早退超过一小时的,其余时间系统自动关闭!
迟到早退的次数记录在a.dat日志分别记录在log_check_in和log_check_out里*/
structstaffinfo
{
charname[15];
intlatetimes;
intearlyleavetimes;
};//定义员工信息结构体
externstructstaffinfostaffs[66]={"mali",0,0,"mahongtao",0,0,"malei",0,0,"bianxianfeng",0,0,"kongxue",0,0,"yinlixin",0,0,"yinchao",0,0,"fangxiaomin",0,0,"wangxiaozheng",0,0,"wangfengqin",0,0,"",0,0,"wangshengqiang",0,0,"wangyangyang",0,0,"wangyang",0,0,"wangtailai",0,0,"wangli",0,0,"wangruiqi",0,0,"luxianjun",0,0,"aizhongwen",0,0,"lvshengnan",0,0,"zhudongdong",0,0,"zhuxiaoyu",0,0,"zhulei",0,0,"jiangmoumei",0,0,"yanhan",0,0,"hefei",0,0,"hejiwei",0,0,"yushuanglin",0,0,"zhangzhipeng",0,0,"zhangxian",0,0,"zhangqiong",0,0,"liyan",0,0,"lixin",0,0,"yanghuan",0,0,"yanghonghao",0,0,"wangxun",0,0,"shaoguojun",0,0,"chenwenhao",0,0,"chenzhangping",0,0,"chenkaidi",0,0,"chencui",0,0,"fangshuo",0,0,"wuqingyuan",0,0,"luoshuai",0,0,"luohao",0,0,"zhengshenlei",0,0,"hongchao",0,0,"zhongbingchuan",0,0,"tangjian",0,0,"xuyanan",0,0,"xuwei",0,0,"jialihong",0,0,"qianhongzhou",0,0,"meikaihuang",0,0,"meijun",0,0,"huangwanying",0,0,"youxuecheng",0,0,"chengqihuai",0,0,"tongxingxing",0,0,"gechunyu",0,0,"dongchengyun",0,0,"leiyanwen",0,0,"baoguoqing",0,0,"yanmeilin",0,0,"weizheng",0,0
};//定义并初始化公司员工数组
charpassword[7]="123456";//密码
voidprompt_message1()//提示
{
system("cls");
printf("╔══════════════════════════╗\n");
printf("║系统已经关闭!
║\n");
printf("║※签到时间为早7点到9点,午13点15点!
※║\n");
printf("║※签出时间为午11点到13点,晚17到19点!
※║\n");
printf("╚══════════════════════════╝\n");
}
voidprompt_message2()//提示
{
printf("╔══════════════════════════╗\n");
printf("║系统已经关闭!
║\n");
printf("║※[1]查询总体的迟到早退次数※║\n");
printf("║※[2]按员工姓名查询迟到早退次数※║\n");
printf("║※[3]查询签到日志※║\n");
printf("║※[4]查询签出日志※║\n");
printf("║※[I]初始化※║\n");
printf("║※[C]清除日志※║\n");
printf("║※[Q]退出※║\n");
printf("╚══════════════════════════╝\n");
printf("选择:
");
}
voidtitle()
{
system("title公司签到系统");//调用系统标题函数,定义窗口标题
system("color0b");
system("modeconcols=80lines=25");//调用系统窗口函数,定义窗口大小
printf("公司员工签到系统\n");
printf("\n");
}
voidprompt_message()//清屏,依层输出信息
{
system("pause");
system("cls");
prompt_message1();
prompt_message2();
}
intwithdraw_or_quit_cmd()//退出取消函数
{
system("color0a");
putchar('\7');
puts("提示:
此操作威胁数据安全!
确定继续?
[y|n]");
{
charaa;
while
(1)
{
aa=getch();
if(aa=='y'||aa=='Y')
{
printf("正在收集相关信息...\n");
return
(1);
}
elseif(aa=='n'||aa=='N')
{
printf("取消动作...\n取消成功!
\n");
break;
}
else
{
putchar('\7');
printf("\n提示:
请按要求输入!
\n");
printf("选择:
\n");
continue;
}
}
prompt_message();
}
return0;
}
char*getpasswd()
{
charchValue;
char*szPassword=(char*)malloc(sizeof(char)*(INPUT_LEN));
intiCounter=0;//定义计数器
while
(1)
{
if((chValue=getch())!
='\r')//如果输入的不是回车
{
if(chValue!
='\b')//如果输入的不是退格
{
if(iCounter { szPassword[iCounter]=chValue; putchar('*');//在屏幕上显示星号 iCounter++; } else { putchar('\7');//如果密码已经超过最大长度,则响铃报警 } } else { if(iCounter! =0)//如果按了退格,并且当前不是第一个字符 { iCounter--; printf("\b\b");//注意两个\b之间是有个空格的,含义是先退格, //然后打印空白字符将之前的字符覆盖掉,然后再退格使光标退回 } } } else { szPassword[iCounter]=0;//密码输入结束时将末尾以\0结尾! printf("\n"); break; } } returnszPassword; } char*int_to_char(inti)//把整型转化为字符串型 { intj,a,b,c; char*ch=(char*)malloc(sizeof(char)*4); j=i+67; if(j>=100) { c=j%10; b=j/10%10; a=j/10/10; ch[0]=a+'0'; ch[1]=b+'0'; ch[2]=c+'0'; ch[3]='\0'; } else { c=j%10; b=j/10; ch[0]='0'; ch[1]=b+'0'; ch[2]=c+'0'; ch[3]='\0'; } returnch; } intinitialize()//功能: 初始化员工的出勤情况 { FILE*fp; inti; if((fp=fopen("D: \\a.dat","w+"))==NULL) { printf("提示: 不能打开指定的文件: D: \\a.dat! \n"); printf("严重错误,错误原因未知! \n"); system("pause"); exit(0); } printf("正在初始化...\n"); for(i=1;i<=9;i++) fprintf(fp,"|0%d0000",i); for(i=10;i<=65;i++) fprintf(fp,"|%d0000",i); fprintf(fp,"|"); fprintf(fp,"\n"); fclose(fp); printf("初始化成功! \n"); return0; } intyes_or_not_initialize()//询问是否初始化库 { intnum=0; charo,*p; o=getch();//options if(o=='n') return(0); elseif(o=='y') { printf("请输入管理员密码: "); while (1) { p=getpasswd(); if(strcmp(p,password)==0&&num<=3) { puts("密码正确! ");return1; } elseif(num<2) { num++; printf("提示: 密码输错%d次,还有%d次机会! \n",num,3-num); system("pause"); printf(": "); continue; } else { printf("提示: 已超出输入次数限制! 系统冻结3分钟! \n"); system("pause"); exit(0);//待写冻结代码,暂以退出替之 } } } else { putchar('\7'); puts("提示: 是[y]否[n]输入管理员密码重新建立库: "); intyes_or_not_initialize(); } return0; } voidconsult_by_total()//功能: 输出员工总体的出勤情况 { FILE*fp; intstate; charch; if((fp=fopen("D: \\a.dat","rb+"))==NULL) { printf("不能打开指定的文件: D: \\a.dat! \n是[y]否[n]输入管理员密码重新建立库: \n"); state=yes_or_not_initialize(); while (1) { if(state==0) { printf("正在退出...\n"); system("pause"); exit(0); } if(state==1) { printf("开始初始化...\n"); initialize(); printf("请重新运行程序! \n"); exit(0); } } } printf("说明: \n\t\t|员工序号员工迟到次数员工早退次数|\n\n查询结果: \n"); while((ch=fgetc(fp))! =EOF) { fseek(fp,-1L,1); printf("%c",fgetc(fp)); } fclose(fp); } intconsult_by_name(charname[15])//按照员工姓名查询员工出勤情况 { FILE*fp1; inti,i1,i2,i3,k,state; chara[460],*fp; charpassword[7]="123456"; fp=a; externstructstaffinfostaffs[66]; intinitialize(); if(strcmp(name,"end")==0)return0; for(i=0;i<=64;i++) { k=0; if(strcmp(staffs[i].name,name)==0) { i1=i+1; k=1; break; } } while((fp1=fopen("D: \\a.dat","rb+"))==NULL) { printf("不能打开指定的文件: D: \\a.dat! \n是[y]否[n]输入管理员密码重新建立库: \n"); while (1) { state=yes_or_not_initialize(); if(state==0) { printf("正在退出...\n"); system("pause"); exit(0); } if(state==1) { printf("开始初始化...\n"); initialize(); printf("请重新运行程序! \n"); exit(0); } } } fgets(a,460,fp1);//460≈65*7! 把文件放到数组中以便指针操作 fclose(fp1); while(*fp! ='\0') { if(*fp=='|'&&((*(fp+1)-'0')*10+(*(fp+2)-'0'))==i1) { i2=(*(fp+3)-'0')*10+(*(fp+4)-'0'); i3=(*(fp+5)-'0')*10+(*(fp+6)-'0'); break; } elsefp+=7; } if(k==0)printf("没有该员工! 请核实您的输入! \n"); else { printf("评价: \t"); if((i2+i3)>=5)printf("此半个月表现不佳,迟到早退总次数已过五次! \n"); elseif(i1! =0) printf("表现不错! \n"); printf("%s\t迟到次数: %d\t早退次数: %d\n\n",staffs[i1-1].name,i2,i3); } return (1); } voidlog_consult1()//签到日志查询 { FILE*fp; charch; if((fp=fopen("D: \\log_check_in.txt","r"))==NULL) { printf("提示: 无法读取日志! 请管理员处理! \n"); return; } while((ch=fgetc(fp))! =EOF) putchar(ch); } voidlog_consult2()//签出日志查询 { FILE*fp; charch; if((fp=fopen("D: \\log_check_out.txt","r"))==NULL) { printf("提示: 无法读取日志! 请管理员处理! \n"); return; } while((ch=fgetc(fp))! =EOF) putchar(ch); } voidconsult()//非签到时间的信息管理维护 { intn=1,m=1,num=0; charname[15],g,*p; charpassword[7]="123456"; printf("选择对员工出勤情况的操作: \n查询[1~4]\t初始化[I]\t退出[Q]\t\t清除日志[C]\n请先输入管理员密码: "); while (1) { p=getpasswd(); if(strcmp(p,password)==0&&num<=3) { system("color0a");//可操作时变色 prompt_message2(); while (1) { g=getche(); putchar('\n'); if(g=='1') { system("cls"); consult_by_total(); prompt_message(); continue; } elseif(g=='2') { while (1) { system("cls"); printf("按照姓名查询: \n"); printf("请输入要查询的员工姓名(输入end退出! ): \n"); scanf("%s",name); getchar(); if(consult_by_name(name)==0) break; elsesystem("pause"); } prompt_message(); continue; } elseif(g=='3') { log_consult1(); prompt_message(); continue; } elseif(g=='4') { log_consult2(); prompt_message(); continue; } elseif(g=='I'||g=='i') { if(withdraw_or_quit_cmd()==1) initialize(); prompt_message(); continue; } elseif(g=='Q'||g=='q') { if(withdraw_or_quit_cmd()==1) { printf("退出成功! \n"); exit(0); } } elseif(g=='C'||g=='c') { putchar('\7'); printf("提示: 考虑安全因素,请管理员手工清理! \n"); prompt_message(); continue; } else { system("color0a"); putchar('\7');//响铃报警 printf("\n提示: 请按要求输入! \n"); prompt_message(); continue; } } num++;break; } elseif(num<2) { num++; printf("提示: 密码输错%d次,还有%d次机会! \n",num,3-num); system("pause"); printf(": "); continue; } else { printf("提示: 已超出输入次数限制! 系统冻结3分钟! \n"); system("pause"); exit(0);//待写冻结代码,暂以退出替之 } } } voidlog_check_in(charname[15])//记录签到日志 { FILE*fp; time_tsystime; structtm*LM; time(&systime); LM=localtime(&systime);//获取当前系统时间 if((fp=fopen("D: \\log_check_in.txt","a"))==NULL) { printf("日志暂时无法记录! "); } fprintf(fp,"%s\t\tcheckedin\t%d月%d日%d时%d分\n",name,(LM->tm_mon)+1,LM->tm_mday,LM->tm_hour,LM->tm_min); fclose(fp); } voidlog_check_out(charname[15])//记录签出日志 { FILE*fp; time_tsystime; structtm*LM; time(&systime); LM=localtime(&systime);//获取当前系统时间 if((fp=fopen("D: \\log_check_out.txt","a"))==NULL) { printf("日志暂时无法记录! "); } fprintf(fp,"%s\t\tcheckedout\t%d月%d日%d时%d分\n",name,(LM->tm_mon)+1,LM->tm_mday,LM->tm_hour,LM->tm_min); fclose(fp); } voidlog_clear()//清除所有日志 { FILE*fp; if((fp=fopen("D: \\log_check_in.txt","w"))==NULL) { printf("无法删除日志! 请管理员处理! "); exit(0); } fclose(fp); }//待写 intcounter_Later_times(inti)//功能: 记录员工迟到(Later_times)次数 { intm,n,state; intLtms=0; chara[460],*fp; charpassword[7]="123456"; FILE*fp1; fp=a; i+=1; while((fp1=fopen("D: \\a.dat","rb+"))==NULL) { prin
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 签到 语言 实现