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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

C++ 简易打卡机

發布時間:2023/12/29 c/c++ 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C++ 简易打卡机 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

(1) 上班打卡,員工具有編號(首位為 1 的六位編號),輸入編號后,再
輸入校驗碼,校驗碼生成規則:員工編號除首位反序,再與員工編號
求和,如:員工編號,110086,校驗碼為 178087。校驗碼錯誤即打
卡失敗。記錄打卡時間
(2) 下班打卡,只需輸入員工編號即可。記錄打卡時間,顯示該人員今天
上班時長,如果上班時長不夠,顯示早退 xx 分鐘。可以更新下班打
卡時間。無下班打卡顯示缺卡。
(3) 可以設置規定上班時長,如 9 小時
(4) 測試需要可以規定 6 秒=實際 1 小時,每次測試,輸入指令后,開啟
打卡機,打卡機開啟模擬時間為:周一早上七點。程序運行結束為周
五晚 12 點。
(5) 實行彈性打卡制,如前一天上班時長超過規定時長 3 小時以上,第
二天遲到 2 小時以內不算遲到。
(6) 打卡機運行結束之前,每周該打卡機會生成每周考勤周報,顯示周平
均上班時長,周遲到,早退,缺卡次數等。


一、變量設置

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

二、主界面
先將所要完成的功能的整體框架寫出來,然后一個一個去寫具體的功能實現。

void clockin_machine_start() {char select;string time = getTime();//當前時間//判斷是否是休息日if(info->tm_wday >= 1 && info->tm_wday <= 5 ){printf("\n");printf("\n");printf("-----------------------------------\n");cout << "當前時間是:" ;cout << time << endl;cout << "打卡機已打開,請選擇:" << endl;cout << "1.上班打卡" << endl;cout << "2.下班打卡" << endl;cout << "3.控制時間" << endl;cout << "4.生成周報" << 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("輸入錯誤,請重新選擇\n");clockin_machine_start();}}else{printf("今天是休息時間\n");}}

三、獲取和控制時間
要實現打卡,首先要獲取當前的時間,該函數返回當前初始化的時間

int flag = 1; string getTime() {if(flag == 1){time_t curtime;time( &curtime );info = localtime( &curtime );//初始化時間為星期一早上7點(沒有初始化具體日期)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; }

然后對時間進行控制:

void control_time() {//顯示時間string time = getTime();printf("\n");printf("\n");printf("*****************************************\n");cout << "當前時間是:";cout << time << endl;char select;cout << "請選擇:" << endl;cout << "1.時間增加一天(從另一天的早上七點開始)" << endl;cout << "2.時間增加幾小時" << 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 << "請輸入增加的時間(小時):";cin >> hour;info->tm_hour = info->tm_hour + hour;control_time();}if(select == '3'){clockin_machine_start();} }

要進行更具體的時間控制可根據tm結構體內部的參數進行修改

四、實現打卡
對時間進行控制后就要實現打卡。
先進行上班打卡:
上班打卡要輸入員工編碼,生成并檢查效驗碼:

void create_checkNum() {int N;//員工編號int ReNum = 0;//逆序int checkNum;//效驗碼//生成效驗碼printf("請輸入員工編號(6位):\n");cin >> N;for(int i = 1; i <= 5; i++){worker[info->tm_wday].number = 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;//檢查效驗碼int CN;printf("請輸入效驗碼:\n");cin >> CN;if(CN != checkNum){printf("效驗碼錯誤,請重新輸入.\n");create_checkNum();}else{printf("輸入正確\n");punch_card_on();} }

檢查完后就進行上班打卡:
設置的上班時間分別為9:00 , 14:00 , 20:00

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

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

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

打卡完后進行計算工作時間的函數:

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

五、生成周報
只要一個時間段里僅打卡一次(僅上班打卡或僅下班打卡)都被認為缺勤

void create_report() {double ave_time = 0;//周平均工作時間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;//統計缺勤次數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("**************周報*****************\n");printf("周平均工作時間: %lf分鐘.\n", ave_time);printf("早退次數: %d\n", report[0].early_num);printf("遲到次數: %d\n", report[0].late_num);printf("缺勤次數: %d\n", report[0].absence_num);}

六、主函數

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。