员工考勤程序是一种帮助企业管理员工出勤状况的程序,可以记录员工的考勤时间、迟到、早退、请假等情况,方便企业进行工资计算、考核评估等工作。以下是一个简单的员工考勤程序的代码示例:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define MAX_EMPLOYEES 100
#define MAX_NAME_LENGTH 20

typedef struct {
    char name[MAX_NAME_LENGTH];
    int id;
    int attendance[31];
} Employee;

void add_employee(Employee employees[], int* count);
void mark_attendance(Employee employees[], int count);
void view_attendance(Employee employees[], int count);

int main() {
    Employee employees[MAX_EMPLOYEES];
    int count = 0;
    int choice;

    do {
        printf("\nEmployee Attendance System\
");
        printf("1. Add Employee\
");
        printf("2. Mark Attendance\
");
        printf("3. View Attendance\
");
        printf("4. Exit\
");
        printf("Enter your choice: ");
        scanf("%d", &choice);

        switch (choice) {
            case 1:
                add_employee(employees, &count);
                break;
            case 2:
                mark_attendance(employees, count);
                break;
            case 3:
                view_attendance(employees, count);
                break;
            case 4:
                printf("Exiting program...\
");
                break;
            default:
                printf("Invalid choice. Please try again.\
");
                break;
        }
    } while (choice != 4);

    return 0;
}

void add_employee(Employee employees[], int* count) {
    if (*count >= MAX_EMPLOYEES) {
        printf("Maximum number of employees reached.\
");
        return;
    }

    Employee new_employee;

    printf("Enter employee name: ");
    scanf("%s", new_employee.name);

    printf("Enter employee ID: ");
    scanf("%d", &new_employee.id);

    memset(new_employee.attendance, 0, sizeof(new_employee.attendance));

    employees[*count] = new_employee;
    (*count)++;

    printf("Employee added successfully.\
");
}

void mark_attendance(Employee employees[], int count) {
    int id, day;
    time_t now;
    struct tm* tm_info;

    printf("Enter employee ID: ");
    scanf("%d", &id);

    for (int i = 0; i < count; i++) {
        if (employees[i].id == id) {
            now = time(NULL);
            tm_info = localtime(&now);

            day = tm_info->tm_mday;

            if (employees[i].attendance[day - 1] == 1) {
                printf("Attendance already marked for today.\
");
                return;
            }

            employees[i].attendance[day - 1] = 1;

            printf("Attendance marked successfully.\
");
            return;
        }
    }

    printf("Employee not found.\
");
}

void view_attendance(Employee employees[], int count) {
    int id, total_days = 0, present_days = 0;

    printf("Enter employee ID: ");
    scanf("%d", &id);

    for (int i = 0; i < count; i++) {
        if (employees[i].id == id) {
            printf("Attendance for %s (ID: %d):\
", employees[i].name, employees[i].id);

            for (int j = 0; j < 31; j++) {
                printf("%d: %s\
", j + 1, employees[i].attendance[j] == 1 ? "Present" : "Absent");

                if (employees[i].attendance[j] == 1) {
                    present_days++;
                }

                total_days++;
            }

            printf("Total days: %d\
", total_days);
            printf("Present days: %d\
", present_days);
            printf("Absent days: %d\
", total_days - present_days);
            return;
        }
    }

    printf("Employee not found.\
");
}

该程序使用了结构体来存储每个员工的信息,包括姓名、ID和考勤记录。程序提供了三个功能:添加员工、标记考勤和查看考勤。在标记考勤功能中,程序使用了time.h库来获取当前日期,并记录在员工的考勤记录中。在查看考勤功能中,程序会统计员工的总出勤天数、出勤天数和缺勤天数,并显示在屏幕上。

C语言员工考勤程序代码示例 - 轻松管理员工出勤情况

原文地址: https://www.cveoy.top/t/topic/f1gB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录