C++ 职工打卡管理系统示例代码
以下是一个基于 C++ 的简单职工打卡管理系统的示例代码:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Employee {
public:
Employee(string name, int id) : name(name), id(id) {}
void clockIn() {
inTime.push_back(getCurrentTime());
cout << '员工 ' << name << ' 打卡上班' << endl;
}
void clockOut() {
outTime.push_back(getCurrentTime());
cout << '员工 ' << name << ' 打卡下班' << endl;
}
void printAttendance() {
cout << '员工 ' << name << ' 的出勤记录:' << endl;
for (int i = 0; i < inTime.size(); i++) {
cout << '上班时间:' << inTime[i] << ',下班时间:' << outTime[i] << endl;
}
}
private:
string name;
int id;
vector<string> inTime;
vector<string> outTime;
string getCurrentTime() {
// 获取当前时间的实现略
}
};
int main() {
Employee employee('张三', 1001);
employee.clockIn();
employee.clockOut();
employee.printAttendance();
return 0;
}
该示例代码实现了以下功能:
- 员工信息管理: 创建 Employee 类,包含员工姓名、ID、上班时间和下班时间的记录。
- 打卡记录: 提供
clockIn()和clockOut()方法,用于记录员工的上班和下班时间。 - 出勤信息打印: 提供
printAttendance()方法,用于打印员工的出勤记录。
在 main 函数中,创建了一个名为 '张三' 的员工,并进行了上班、下班和打印出勤记录的操作。
需要注意的是,示例代码中的 getCurrentTime() 方法需要根据具体的实现来获取当前时间。此外,该示例代码只实现了一个简单的功能,实际的职工打卡管理系统可能需要更多的功能和数据处理。
通过本示例代码,您可以学习到如何使用 C++ 开发一个简单的职工打卡管理系统,并为进一步的开发提供参考。
原文地址: https://www.cveoy.top/t/topic/o3iw 著作权归作者所有。请勿转载和采集!