日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

C++ 简易打卡机

發(fā)布時(shí)間:2023/12/29 c/c++ 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++ 简易打卡机 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

(1) 上班打卡,員工具有編號(hào)(首位為 1 的六位編號(hào)),輸入編號(hào)后,再
輸入校驗(yàn)碼,校驗(yàn)碼生成規(guī)則:員工編號(hào)除首位反序,再與員工編號(hào)
求和,如:員工編號(hào),110086,校驗(yàn)碼為 178087。校驗(yàn)碼錯(cuò)誤即打
卡失敗。記錄打卡時(shí)間
(2) 下班打卡,只需輸入員工編號(hào)即可。記錄打卡時(shí)間,顯示該人員今天
上班時(shí)長(zhǎng),如果上班時(shí)長(zhǎng)不夠,顯示早退 xx 分鐘??梢愿孪掳啻?br /> 卡時(shí)間。無(wú)下班打卡顯示缺卡。
(3) 可以設(shè)置規(guī)定上班時(shí)長(zhǎng),如 9 小時(shí)
(4) 測(cè)試需要可以規(guī)定 6 秒=實(shí)際 1 小時(shí),每次測(cè)試,輸入指令后,開啟
打卡機(jī),打卡機(jī)開啟模擬時(shí)間為:周一早上七點(diǎn)。程序運(yùn)行結(jié)束為周
五晚 12 點(diǎn)。
(5) 實(shí)行彈性打卡制,如前一天上班時(shí)長(zhǎng)超過(guò)規(guī)定時(shí)長(zhǎng) 3 小時(shí)以上,第
二天遲到 2 小時(shí)以內(nèi)不算遲到。
(6) 打卡機(jī)運(yùn)行結(jié)束之前,每周該打卡機(jī)會(huì)生成每周考勤周報(bào),顯示周平
均上班時(shí)長(zhǎng),周遲到,早退,缺卡次數(shù)等。


一、變量設(shè)置

struct tm *info; //當(dāng)前時(shí)間(time.h內(nèi)置結(jié)構(gòu)體)typedef struct WORKER{int number; //員工編號(hào)int work_time; //當(dāng)天工作時(shí)間//上午上班時(shí)間string AM_ontime; int AM_on_hour;int AM_on_mins;//上午下班時(shí)間string AM_outtime; int AM_out_hour;int AM_out_mins;//下午上班時(shí)間string PM_ontime; int PM_on_hour;int PM_on_mins;//下午下班時(shí)間string PM_outtime; int PM_out_hour;int PM_out_mins;//晚上上班時(shí)間string Night_ontime;int Night_on_hour; int Night_on_mins;//晚上下班時(shí)間 string Night_outtime; int Night_out_hour; int Night_out_mins; }P; P worker[5] = {0}; //員工結(jié)構(gòu)體//周報(bào) struct REPORT {int late_num; //遲到次數(shù)int early_num; //早退次數(shù)int absence_num; //缺勤次數(shù)double avetime; //周平均工作時(shí)間 }report[20] = {0};

二、主界面
先將所要完成的功能的整體框架寫出來(lái),然后一個(gè)一個(gè)去寫具體的功能實(shí)現(xiàn)。

void clockin_machine_start() {char select;string time = getTime();//當(dāng)前時(shí)間//判斷是否是休息日if(info->tm_wday >= 1 && info->tm_wday <= 5 ){printf("\n");printf("\n");printf("-----------------------------------\n");cout << "當(dāng)前時(shí)間是:" ;cout << time << endl;cout << "打卡機(jī)已打開,請(qǐng)選擇:" << endl;cout << "1.上班打卡" << endl;cout << "2.下班打卡" << endl;cout << "3.控制時(shí)間" << endl;cout << "4.生成周報(bào)" << endl;cout << "5.退出" << endl;cin >> select;if(select == '1'){create_checkNum();}else if(select == '2'){punch_card_out();}else if(select == '3'){control_time();}else if(select == '4'){create_report();}else if(select == '5'){exit(0);}else{printf("輸入錯(cuò)誤,請(qǐng)重新選擇\n");clockin_machine_start();}}else{printf("今天是休息時(shí)間\n");}}

三、獲取和控制時(shí)間
要實(shí)現(xiàn)打卡,首先要獲取當(dāng)前的時(shí)間,該函數(shù)返回當(dāng)前初始化的時(shí)間

int flag = 1; string getTime() {if(flag == 1){time_t curtime;time( &curtime );info = localtime( &curtime );//初始化時(shí)間為星期一早上7點(diǎn)(沒有初始化具體日期)info->tm_wday = 1;info->tm_hour = 7;info->tm_min = 0;info->tm_sec = 0;flag = 2;//僅初始化一次就行}char tmp[64];strftime(tmp, sizeof(tmp), "%A %Y-%m-%d %H:%M:%S",info);return tmp; }

然后對(duì)時(shí)間進(jìn)行控制:

void control_time() {//顯示時(shí)間string time = getTime();printf("\n");printf("\n");printf("*****************************************\n");cout << "當(dāng)前時(shí)間是:";cout << time << endl;char select;cout << "請(qǐng)選擇:" << endl;cout << "1.時(shí)間增加一天(從另一天的早上七點(diǎn)開始)" << endl;cout << "2.時(shí)間增加幾小時(shí)" << endl;cout << "3.返回" << endl;cin >> select;if(select == '1'){info->tm_wday = info->tm_wday + 1;info->tm_hour = 7;info->tm_min = 0;info->tm_sec = 0;control_time();}if(select == '2'){int hour;cout << "請(qǐng)輸入增加的時(shí)間(小時(shí)):";cin >> hour;info->tm_hour = info->tm_hour + hour;control_time();}if(select == '3'){clockin_machine_start();} }

要進(jìn)行更具體的時(shí)間控制可根據(jù)tm結(jié)構(gòu)體內(nèi)部的參數(shù)進(jìn)行修改

四、實(shí)現(xiàn)打卡
對(duì)時(shí)間進(jìn)行控制后就要實(shí)現(xiàn)打卡。
先進(jìn)行上班打卡:
上班打卡要輸入員工編碼,生成并檢查效驗(yàn)碼:

void create_checkNum() {int N;//員工編號(hào)int ReNum = 0;//逆序int checkNum;//效驗(yàn)碼//生成效驗(yàn)碼printf("請(qǐng)輸入員工編號(hào)(6位):\n");cin >> N;for(int i = 1; i <= 5; i++){worker[info->tm_wday].number = N; }//轉(zhuǎn)化為逆序string Number = to_string(N);string ReNumber[5];for(int i = Number.size() - 1; i > 0; i--){ReNumber[5-i] = Number[i];}for(int i = 0; i < 5; i++){int a = stoi(ReNumber[i]);int b = 1;for(int j = 0; j < 4-i; j++){b *= 10;}ReNum += a * b;}checkNum = ReNum + N;//檢查效驗(yàn)碼int CN;printf("請(qǐng)輸入效驗(yàn)碼:\n");cin >> CN;if(CN != checkNum){printf("效驗(yàn)碼錯(cuò)誤,請(qǐng)重新輸入.\n");create_checkNum();}else{printf("輸入正確\n");punch_card_on();} }

檢查完后就進(jìn)行上班打卡:
設(shè)置的上班時(shí)間分別為9:00 , 14:00 , 20:00

void punch_card_on() {//上午if(info->tm_hour <= 12){//9點(diǎn)上班if(info->tm_hour <= 9){printf("上班打卡成功\n");worker[info->tm_wday].AM_ontime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].AM_ontime << endl; worker[info->tm_wday].AM_on_hour = info->tm_hour; //將小時(shí)(幾點(diǎn))存放到結(jié)構(gòu)體worker[info->tm_wday].AM_on_mins = info->tm_min; //將分鐘(幾分)存放到結(jié)構(gòu)體clockin_machine_start();}//遲到else if(info->tm_hour < 11){ printf("您已遲到\n");worker[info->tm_wday].AM_ontime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].AM_ontime << endl; worker[info->tm_wday].AM_on_hour = info->tm_hour; //將小時(shí)(幾點(diǎn))存放到結(jié)構(gòu)體worker[info->tm_wday].AM_on_mins = info->tm_min; //將分鐘(幾分)存放到結(jié)構(gòu)體report[0].late_num ++;//遲到次數(shù)+1clockin_machine_start();}//超過(guò)規(guī)定時(shí)間(11點(diǎn)),認(rèn)定缺勤else{printf("您被認(rèn)為缺勤\n"); clockin_machine_start();} }//下午else if(info->tm_hour <= 19){//2點(diǎn)上班if(info->tm_hour <= 14){printf("上班打卡成功\n");worker[info->tm_wday].PM_ontime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].PM_ontime << endl; //將時(shí)間存放到結(jié)構(gòu)體worker[info->tm_wday].PM_on_hour = info->tm_hour;worker[info->tm_wday].PM_on_mins = info->tm_min;clockin_machine_start();}else if(info->tm_hour < 17){ printf("您已遲到\n");worker[info->tm_wday].PM_ontime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].PM_ontime << endl; //將時(shí)間存放到結(jié)構(gòu)體worker[info->tm_wday].PM_on_hour = info->tm_hour;worker[info->tm_wday].PM_on_mins = info->tm_min;report[0].late_num ++;//遲到次數(shù)+1clockin_machine_start();}//超過(guò)下午五點(diǎn),認(rèn)為缺勤else {printf("您被認(rèn)為缺勤\n"); clockin_machine_start();} }//晚上else{//8點(diǎn)上班if(info->tm_hour <= 20 ){printf("上班打卡成功\n");worker[info->tm_wday].Night_ontime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].Night_ontime << endl; //將時(shí)間存放到結(jié)構(gòu)體worker[info->tm_wday].Night_on_hour = info->tm_hour;worker[info->tm_wday].Night_on_mins = info->tm_min;clockin_machine_start();}else if(info->tm_hour <= 21){ printf("您已遲到\n");worker[info->tm_wday].Night_ontime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].Night_ontime << endl; //將時(shí)間存放到結(jié)構(gòu)體worker[info->tm_wday].Night_on_hour = info->tm_hour;worker[info->tm_wday].Night_on_mins = info->tm_min;report[0].late_num ++;//遲到次數(shù)+1clockin_machine_start();}//超過(guò)晚上9點(diǎn),認(rèn)為缺勤else{printf("您被認(rèn)為缺勤\n"); clockin_machine_start();} } }

上班打卡后就是下班打卡:
下班打卡就沒有具體時(shí)間要求,最后工作時(shí)間足夠就行。(但沒打卡會(huì)被認(rèn)為缺勤)

void punch_card_out() {int N;printf("請(qǐng)輸入您的編號(hào):");cin >> N;//上午if(info->tm_hour < 13){printf("下班打卡成功\n");worker[info->tm_wday].AM_outtime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].AM_outtime << endl;//將時(shí)間存放到結(jié)構(gòu)體worker[info->tm_wday].AM_out_hour = info->tm_hour;worker[info->tm_wday].AM_out_mins = info->tm_min;//計(jì)算當(dāng)天工作時(shí)間calculate_Worktime();}//下午else if(info->tm_hour < 19){printf("下班打卡成功\n");worker[info->tm_wday].PM_outtime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].PM_outtime << endl;//將時(shí)間存放到結(jié)構(gòu)體worker[info->tm_wday].PM_out_hour = info->tm_hour;worker[info->tm_wday].PM_out_mins = info->tm_min;//計(jì)算當(dāng)天工作時(shí)間calculate_Worktime();}//晚上else {printf("下班打卡成功\n");worker[info->tm_wday].Night_outtime = getTime();cout << "打卡時(shí)間:" << worker[info->tm_wday].Night_outtime << endl;//將時(shí)間存放到結(jié)構(gòu)體worker[info->tm_wday].Night_out_hour = info->tm_hour;worker[info->tm_wday].Night_out_mins = info->tm_min;//計(jì)算當(dāng)天工作時(shí)間calculate_Worktime();} }

打卡完后進(jìn)行計(jì)算工作時(shí)間的函數(shù):

void calculate_Worktime() {int am = 0;int pm = 0;int ni = 0;//上午工作時(shí)間//判斷是否缺勤或沒打卡if(worker[info->tm_wday].AM_on_hour != 0 && worker[info->tm_wday].AM_out_hour != 0) {//計(jì)算時(shí)間am = (worker[info->tm_wday].AM_out_hour - worker[info->tm_wday].AM_on_hour) * 60+ (worker[info->tm_wday].AM_out_mins - worker[info->tm_wday].AM_on_mins); }//下午工作時(shí)間//判斷是否缺勤或沒打卡if(worker[info->tm_wday].PM_on_hour != 0 && worker[info->tm_wday].PM_out_hour != 0){//計(jì)算時(shí)間pm = (worker[info->tm_wday].PM_out_hour - worker[info->tm_wday].PM_on_hour) * 60+ (worker[info->tm_wday].PM_out_mins - worker[info->tm_wday].PM_on_mins); }//晚上工作時(shí)間//判斷是否缺勤或沒打卡if(worker[info->tm_wday].Night_on_hour != 0 && worker[info->tm_wday].Night_out_hour != 0){//計(jì)算時(shí)間ni = (worker[info->tm_wday].Night_out_hour - worker[info->tm_wday].Night_on_hour) * 60+ (worker[info->tm_wday].Night_out_mins - worker[info->tm_wday].Night_on_mins); }//將工作時(shí)間放入結(jié)構(gòu)體int sum = am + pm + ni;worker[info->tm_wday].work_time = sum;//判斷前一天是否加班超過(guò)3三小時(shí)int a = 540;if(worker[info->tm_wday - 1].work_time >= 720){a = 420;}//如果小于規(guī)定工作時(shí)間if(sum < a){int b = 540 - sum;printf("今天工作時(shí)間不足,早退%d分鐘.\n", b);report[0].early_num ++; //早退次數(shù)+1}//如果滿足工作時(shí)間else if(sum >= a && sum < 720){printf("\n");printf("今天工作時(shí)間:%d分鐘.\n", sum);}//返回主界面clockin_machine_start(); }

五、生成周報(bào)
只要一個(gè)時(shí)間段里僅打卡一次(僅上班打卡或僅下班打卡)都被認(rèn)為缺勤

void create_report() {double ave_time = 0;//周平均工作時(shí)間int sum = 0;for(int i = 1 ; i <= 5 ; i++){sum += worker[i].work_time;}ave_time = sum / 5.0;report[0].avetime = ave_time;//統(tǒng)計(jì)缺勤次數(shù)for(int i = 1 ; i <= 5 ; i++){//上午缺勤if(worker[i].AM_on_hour == 0 || worker[i].AM_out_hour == 0){report[0].absence_num ++;}//下午缺勤if(worker[i].PM_on_hour == 0 || worker[i].PM_out_hour == 0){report[0].absence_num ++;}//晚上缺勤if(worker[i].Night_on_hour == 0 || worker[i].Night_out_hour == 0){report[0].absence_num ++;}}printf("\n");printf("**************周報(bào)*****************\n");printf("周平均工作時(shí)間: %lf分鐘.\n", ave_time);printf("早退次數(shù): %d\n", report[0].early_num);printf("遲到次數(shù): %d\n", report[0].late_num);printf("缺勤次數(shù): %d\n", report[0].absence_num);}

六、主函數(shù)

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

總結(jié)

以上是生活随笔為你收集整理的C++ 简易打卡机的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。