2301_76827951 2023-09-23 20:12 采纳率: 0%
浏览 22
已结题

用c语言写一个团队考勤系统

  1. 程序开始时通过⽂件输⼊初始信息,在程序运⾏时能够新增、删除队员信息,并能根据学号
    查询队员信
    息(学号、姓名、打卡次数、打卡记录、总⼯作时间),打卡记录按照⽇期顺序打印,或者
    按照学号顺
    序打印所有队员信息(学号、姓名、打卡次数),能将队员信息导出成⽂件。
  2. 队员信息输⼊格式
    学号、姓名、打卡次数、打卡记录(打卡⽇期/打卡时间)2001 yzl 1 2022.1.1 8:00—21:30
    2005 zh 3 2021.11.1 12:00—22:00 2021.11.2 11:30—21:00 2021.11.4
    10:30—21:00
    学号为4位数⽆符号整型[1000, 9999]
    姓名为不定⻓度的字符串(tips: 使⽤指针)
    打卡次数范围 [0, 65536]
    打卡记录格式 year.month.day come:time~leave:time,⽇期时间简化处理为每⽉均为30天3. 输⼊某⾏信息记录格式有误时(包括未按格式输⼊、学号冲突、打卡次数与打卡记录不匹
    配、打卡时间
    超出范围如:25:61等)应当打印报错,并且跳过错误记录,同时接受其余正确信息。
  3. 单个队员信息以及打卡记录要求使⽤结构体的⽅式保存,并且使⽤链表(⽽⾮数组)的⽅式
    将所有信息
  • 写回答

16条回答 默认 最新

  • 专家-赤兔[在线] 2023-09-23 20:19
    关注
    获得0.60元问题酬金

    引用 皆我百晓生 小程序回复内容作答:

    整理和管理。要求程序在退出时能将队员信息保存到⽂件中,下次启动程序时能将
    之前保存的信息导⼊到程序中。

    以下是一个可能的实现:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    // 定义打卡记录节点
    typedef struct {
        char date[11];  // 打卡日期
        char come[6];   // 上班时间
        char leave[6];  // 下班时间
    } Record;
    
    // 定义队员节点
    typedef struct Member {
        unsigned int id;        // 学号
        char *name;             // 姓名
        unsigned int attendance;    // 打卡次数
        Record *records;        // 打卡记录
        unsigned int workHours; // 工作时间
        struct Member *next;    // 下一个队员节点的指针
    } Member;
    
    // 全局队员链表头指针和尾指针
    Member *head = NULL;
    Member *tail = NULL;
    
    // 函数声明
    void loadFromFile();
    void saveToFile();
    Member *createMember(unsigned int id, char *name, unsigned int attendance);
    void addMember();
    void deleteMember();
    void searchMemberById();
    void printAllMembers();
    void addRecord(Member *member);
    void calculateWorkHours(Member *member);
    
    int main() {
        // 加载之前保存的队员信息
        loadFromFile();
    
        int choice;
        do {
            // 显示菜单选项
            printf("\n--- 考勤系统 ---\n");
            printf("1. 新增队员\n");
            printf("2. 删除队员\n");
            printf("3. 根据学号查询队员信息\n");
            printf("4. 打印所有队员信息\n");
            printf("5. 导出队员信息到文件\n");
            printf("0. 退出\n");
            printf("请选择功能:");
            scanf("%d", &choice);
    
            switch (choice) {
                case 1:
                    addMember();
                    break;
                case 2:
                    deleteMember();
                    break;
                case 3:
                    searchMemberById();
                    break;
                case 4:
                    printAllMembers();
                    break;
                case 5:
                    saveToFile();
                    break;
                case 0:
                    printf("感谢使用,再见!\n");
                    break;
                default:
                    printf("无效的选项,请重新输入。\n");
            }
        } while (choice != 0);
    
        // 保存队员信息到文件
        saveToFile();
    
        return 0;
    }
    
    // 从文件加载队员信息
    void loadFromFile() {
        FILE *file = fopen("members.dat", "rb");
        if (file != NULL) {
            // 读取队员数量
            int count;
            fread(&count, sizeof(int), 1, file);
    
            for (int i = 0; i < count; i++) {
                // 读取队员数据
                Member *member = (Member*)malloc(sizeof(Member));
                fread(member, sizeof(Member), 1, file);
    
                // 读取姓名
                member->name = (char*)malloc(strlen(member->name) + 1);
                fread(member->name, strlen(member->name) + 1, 1, file);
    
                // 读取打卡记录
                member->records = (Record*)malloc(sizeof(Record) * member->attendance);
                fread(member->records, sizeof(Record), member->attendance, file);
    
                // 计算工作时间
                calculateWorkHours(member);
    
                // 添加队员到链表
                if (head == NULL) {
                    head = member;
                } else {
                    tail->next = member;
                }
                member->next = NULL;
                tail = member;
            }
    
            fclose(file);
        }
    }
    
    // 保存队员信息到文件
    void saveToFile() {
        FILE *file = fopen("members.dat", "wb");
        if (file != NULL) {
            // 计算队员数量
            int count = 0;
            Member *current = head;
            while (current != NULL) {
                count++;
                current = current->next;
            }
    
            // 写入队员数量
            fwrite(&count, sizeof(int), 1, file);
    
            // 依次写入队员数据
            current = head;
            while (current != NULL) {
                // 写入队员信息
                fwrite(current, sizeof(Member), 1, file);
    
                // 写入姓名
                fwrite(current->name, strlen(current->name) + 1, 1, file);
    
                // 写入打卡记录
                fwrite(current->records, sizeof(Record), current->attendance, file);
    
                current = current->next;
            }
    
            fclose(file);
        }
    }
    
    // 创建队员节点
    Member *createMember(unsigned int id, char *name, unsigned int attendance) {
        Member *member = (Member*)malloc(sizeof(Member));
        member->id = id;
        member->name = (char*)malloc(strlen(name) + 1);
        strcpy(member->name, name);
        member->attendance = attendance;
        member->records = (Record*)malloc(sizeof(Record) * attendance);
        member->workHours = 0;
        member->next = NULL;
        return member;
    }
    
    // 新增队员
    void addMember() {
        unsigned int id;
        printf("请输入学号:");
        scanf("%u", &id);
    
        // 检查学号是否已存在
        Member *current = head;
        while (current != NULL) {
            if (current->id == id) {
                printf("学号已存在,请重新输入。\n");
                return;
            }
            current = current->next;
        }
    
        char name[50];
        printf("请输入姓名:");
        scanf("%s", name);
    
        unsigned int attendance;
        printf("请输入打卡次数:");
        scanf("%u", &attendance);
    
        // 创建队员节点
        Member *member = createMember(id, name, attendance);
    
        // 添加打卡记录
        for (int i = 0; i < attendance; i++) {
            addRecord(member);
        }
    
        // 计算工作时间
        calculateWorkHours(member);
    
        // 添加队员到链表
        if (head == NULL) {
            head = member;
        } else {
            tail->next = member;
        }
        member->next = NULL;
        tail = member;
    
        printf("队员添加成功!\n");
    }
    
    // 删除队员
    void deleteMember() {
        unsigned int id;
        printf("请输入要删除的队员学号:");
        scanf("%u", &id);
    
        if (head == NULL) {
            printf("队员不存在!\n");
            return;
        }
    
        Member *current = head;
        Member *prev = NULL;
        while (current != NULL) {
            if (current->id == id) {
                // 找到要删除的队员节点
    
                if (prev != NULL) {
                    // 如果不是头节点,则更新前一个节点的next指针
                    prev->next = current->next;
                } else {
                    // 如果是头节点,则更新head指针
                    head = current->next;
                }
    
                // 释放节点占用的内存
                free(current->name);
                free(current->records);
                free(current);
    
                printf("队员删除成功!\n");
                return;
            }
    
            prev = current;
            current = current->next;
        }
    
        printf("队员不存在!\n");
    }
    
    // 根据学号查询队员信息
    void searchMemberById() {
        unsigned int id;
        printf("请输入要查询的队员学号:");
        scanf("%u", &id);
    
        Member *current = head;
        while (current != NULL) {
            if (current->id == id) {
                // 找到要查询的队员节点
    
                printf("学号:%u\n", current->id);
                printf("姓名:%s\n", current->name);
                printf("打卡次数:%u\n", current->attendance);
                printf("打卡记录:\n");
                for (int i = 0; i < current->attendance; i++) {
                    printf("%s:上班%s 下班%s\n", current->records[i].date, current->records[i].come, current->records[i].leave);
                }
                printf("总工作时间:%u小时\n", current->workHours);
    
                return;
            }
    
            current = current->next;
        }
    
        printf("队员不存在!\n");
    }
    
    // 打印所有队员信息
    void printAllMembers() {
        if (head == NULL) {
            printf("队员信息为空!\n");
            return;
        }
    
        Member *current = head;
        printf("所有队员信息:\n");
        while (current != NULL) {
            printf("学号:%u\n", current->id);
            printf("姓名:%s\n", current->name);
            printf("打卡次数:%u\n", current->attendance);
            printf("===============================\n");
            current = current->next;
        }
    }
    
    // 新增打卡记录
    void addRecord(Member *member) {
        char input[100];
        printf("请输入打卡记录(日期 上班时间 下班时间):");
        scanf("%s", input);
    
        char *token = strtok(input, " ");
        int i = 0;
        while (token != NULL) {
            if (i == 0) {
                strcpy(member->records[member->attendance].date, token);
            } else if (i == 1) {
                strcpy(member->records[member->attendance].come, token);
            } else if (i == 2) {
                strcpy(member->records[member->attendance].leave, token);
            }
    
            token = strtok(NULL, " ");
            i++;
        }
    
        member->attendance++;
    }
    
    // 计算工作时间
    void calculateWorkHours(Member *member) {
        unsigned int totalWorkHours = 0;
        for (int i = 0; i < member->attendance; i++) {
            char *comeHour = strtok(member->records[i].come, ":");
            char *comeMinute = strtok(NULL, ":");
            char *leaveHour = strtok(member->records[i].leave, ":");
            char *leaveMinute = strtok(NULL, ":");
    
            int comeH = atoi(comeHour);
            int comeM = atoi(comeMinute);
            int leaveH = atoi(leaveHour);
            int leaveM = atoi(leaveMinute);
    
            int workHours = (leaveH - comeH) * 60 + (leaveM - comeM);
    
            totalWorkHours += workHours;
        }
    
        member->workHours = totalWorkHours / 60;
    }
    

    请注意,此代码仅作为参考实现,并且没有进行输入校验和错误处理。根据实际需求,可能需要在适当的位置添加输入校验和错误处理。另外,在代码中,队员信息保存在链表中,并在退出程序时保存到文件中,并在下次启动程序时加载。队员信息保存在二进制文件"members.dat"中,可以根据需要更改文件名或路径。

    评论
  • threenewbee 2023-09-23 21:27
    关注
    获得1.00元问题酬金
    评论
  • 小明说Java 2023-09-23 20:29
    关注
    获得0.40元问题酬金

    可以去开源社区找一找,有现成的curd代码,改一改就行了

    评论
  • CSDN-Ada助手 CSDN-AI 官方账号 2023-09-23 22:21
    关注
    获得0.80元问题酬金

    【以下回答由 GPT 生成】

    我可以解决该问题。

    首先,我们需要定义一个队员的结构体,包含学号、姓名、打卡次数和打卡记录等信息。

    typedef struct {
        unsigned int studentNumber;
        char *name;
        unsigned int checkInCount;
        struct CheckInRecord *checkInRecords;
    } TeamMember;
    
    typedef struct CheckInRecord {
        char *date;
        char *checkInTime;
        char *checkOutTime;
        struct CheckInRecord *next;
    } CheckInRecord;
    

    然后,我们可以创建一个链表来保存队员信息,每个节点保存一个队员的信息。

    typedef struct Node {
        TeamMember data;
        struct Node *next;
    } Node;
    
    Node *head = NULL; // 头节点
    

    接下来,我们可以编写函数来实现各种功能。

    1. 程序开始时通过文件输入初始信息,在程序运行时能够新增、删除队员信息,并能根据学号查询队员信息(学号、姓名、打卡次数、打卡记录、总工作时间),打卡记录按照日期顺序打印,或者按照学号顺序打印所有队员信息(学号、姓名、打卡次数),能将队员信息导出成文件。
    // 从文件中加载初始信息
    void loadInitialInfoFromFile(char *filename);
    
    // 新增队员信息
    void addTeamMemberInfo(unsigned int studentNumber, char *name);
    
    // 删除队员信息
    void deleteTeamMemberInfo(unsigned int studentNumber);
    
    // 根据学号查询队员信息
    TeamMember *getTeamMemberInfoByStudentNumber(unsigned int studentNumber);
    
    // 打印打卡记录按照日期顺序
    void printCheckInRecordsByDate(unsigned int studentNumber);
    
    // 打印所有队员信息按照学号顺序
    void printAllTeamMembersByStudentNumber();
    
    // 导出队员信息到文件
    void exportTeamMemberInfoToFile(char *filename);
    
    1. 队员信息输入格式验证
    // 检查输入的打卡记录格式是否正确
    int checkCheckInRecordFormat(char *record);
    
    // 检查学号是否冲突
    int checkStudentNumberConflict(unsigned int studentNumber);
    
    // 检查打卡次数和打卡记录是否匹配
    int checkCheckInCountAndRecords(unsigned int checkInCount, char *records);
    
    // 检查打卡时间是否在范围内
    int checkCheckInTime(char *time);
    
    1. 链表操作函数
    // 创建新的队员节点
    Node *createNewNode(unsigned int studentNumber, char *name);
    
    // 将队员信息插入链表
    void insertTeamMemberInfo(Node *node);
    
    // 从链表中删除队员信息
    void deleteNode(unsigned int studentNumber);
    
    // 释放链表的内存
    void freeLinkedList();
    

    完成以上函数的编写后,我们就可以根据具体需求调用这些函数来实现团队考勤系统。

    以下是完整的 C 代码示例:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdbool.h>
    
    typedef struct {
        unsigned int studentNumber;
        char *name;
        unsigned int checkInCount;
        struct CheckInRecord *checkInRecords;
    } TeamMember;
    
    typedef struct CheckInRecord {
        char *date;
        char *checkInTime;
        char *checkOutTime;
        struct CheckInRecord *next;
    } CheckInRecord;
    
    typedef struct Node {
        TeamMember data;
        struct Node *next;
    } Node;
    
    Node *head = NULL;
    
    // 创建新的队员节点
    Node *createNewNode(unsigned int studentNumber, char *name) {
        Node *newNode = (Node *) malloc(sizeof(Node));
        newNode->data.studentNumber = studentNumber;
        newNode->data.name = strdup(name);
        newNode->data.checkInCount = 0;
        newNode->data.checkInRecords = NULL;
        newNode->next = NULL;
        return newNode;
    }
    
    // 将队员信息插入链表
    void insertTeamMemberInfo(Node *node) {
        if (head == NULL) {
            head = node;
        } else {
            Node *temp = head;
            while (temp->next != NULL) {
                temp = temp->next;
            }
            temp->next = node;
        }
    }
    
    // 从链表中删除队员信息
    void deleteNode(unsigned int studentNumber) {
        Node *temp = head;
        Node *prev = NULL;
        while (temp != NULL && temp->data.studentNumber != studentNumber) {
            prev = temp;
            temp = temp->next;
        }
        if (temp == NULL) {
            printf("队员信息不存在!\n");
            return;
        }
        if (prev == NULL) {
            head = temp->next;
        } else {
            prev->next = temp->next;
        }
        free(temp->data.name);
        free(temp);
    }
    
    // 释放链表的内存
    void freeLinkedList() {
        Node *temp = head;
        while (temp != NULL) {
            Node *prev = temp;
            temp = temp->next;
            free(prev->data.name);
            free(prev);
        }
    }
    
    // 检查输入的打卡记录格式是否正确
    int checkCheckInRecordFormat(char *record) {
        // 检查格式,省略具体实现
        return 1;
    }
    
    // 检查学号是否冲突
    int checkStudentNumberConflict(unsigned int studentNumber) {
        Node *temp = head;
        while (temp != NULL) {
            if (temp->data.studentNumber == studentNumber) {
                return 1;
            }
            temp = temp->next;
        }
        return 0;
    }
    
    // 检查打卡次数和打卡记录是否匹配
    int checkCheckInCountAndRecords(unsigned int checkInCount, char *records) {
        // 检查匹配,省略具体实现
        return 1;;
    }
    
    // 检查打卡时间是否在范围内
    int checkCheckInTime(char *time) {
        // 检查时间,省略具体实现
        return 1;
    }
    
    // 从文件中加载初始信息
    void loadInitialInfoFromFile(char *filename) {
        // 读取文件并解析初始化信息,省略具体实现
    }
    
    // 新增队员信息
    void addTeamMemberInfo(unsigned int studentNumber, char *name) {
        if (checkStudentNumberConflict(studentNumber)) {
            printf("学号冲突!\n");
            return;
        }
        Node *newNode = createNewNode(studentNumber, name);
        insertTeamMemberInfo(newNode);
    }
    
    // 删除队员信息
    void deleteTeamMemberInfo(unsigned int studentNumber) {
        deleteNode(studentNumber);
    }
    
    // 根据学号查询队员信息
    TeamMember *getTeamMemberInfoByStudentNumber(unsigned int studentNumber) {
        Node *temp = head;
        while (temp != NULL) {
            if (temp->data.studentNumber == studentNumber) {
                return &(temp->data);
            }
            temp = temp->next;
        }
        return NULL;
    }
    
    // 打印打卡记录按照日期顺序
    void printCheckInRecordsByDate(unsigned int studentNumber) {
        TeamMember *teamMember = getTeamMemberInfoByStudentNumber(studentNumber);
        if (teamMember == NULL) {
            printf("队员信息不存在!\n");
            return;
        }
        // 按日期打印打卡记录,省略具体实现
    }
    
    // 打印所有队员信息按照学号顺序
    void printAllTeamMembersByStudentNumber() {
        Node *temp = head;
        while (temp != NULL) {
            printf("学号:%u,姓名:%s,打卡次数:%u\n", temp->data.studentNumber, temp->data.name, temp->data.checkInCount);
            temp = temp->next;
        }
    }
    
    // 导出队员信息到文件
    void exportTeamMemberInfoToFile(char *filename) {
        // 导出队员信息到文件,省略具体实现
    }
    
    int main() {
        loadInitialInfoFromFile("initial_info.txt");
    
        addTeamMemberInfo(2001, "yzl");
        addTeamMemberInfo(2005, "zh");
        addTeamMemberInfo(2022, "wk");
    
        printAllTeamMembersByStudentNumber();
    
        deleteTeamMemberInfo(2005);
    
        printAllTeamMembersByStudentNumber();
    
        exportTeamMemberInfoToFile("exported_info.txt");
    
        freeLinkedList();
    
        return 0;
    }
    

    以上就是用 C 语言编写一个团队考勤系统的解决方案。在实际使用时,需要根据具体需求进行适当的调整和完善。



    【相关推荐】



    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论
  • 数据大魔王 2023-09-23 23:31
    关注
    获得0.60元问题酬金

    大致思路:

    1. 创建一个结构体来保存队员信息,包括学号、姓名、打卡次数和打卡记录等字段。可以使用链表(linked list)来保存所有队员信息。

    2. 程序开始时,通过文件输入读取初始队员信息并建立链表。

    3. 提供新增、删除队员信息的功能,根据用户的操作修改链表。

    4. 提供根据学号查询队员信息的功能,遍历链表寻找匹配的学号,并输出详细信息。

    5. 提供打卡记录的保存功能。你可以为每个队员的打卡记录使用一个单独的链表来保存。当用户新增打卡记录时,将新的打卡记录节点插入到对应队员的链表中,并按照日期顺序进行排序。

    6. 提供打印函数,可以按照日期顺序打印出全部打卡记录,或按照学号顺序打印所有队员信息。

    7. 提供导出队员信息的功能,将队员信息以适当的格式导出到文件中。

    8. 在用户输入某行信息记录格式有误时进行错误处理,打印错误提示并跳过错误记录。

    这是一个大致的实现思路,您可以根据自己的需求进一步完善和优化代码。希望对您的编程有所帮助!

    评论
  • 杨得江-君临天下wyj 2023-09-24 08:19
    关注
    获得0.60元问题酬金
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdbool.h>
    typedef struct {
        unsigned int studentNumber;
        char *name;
        unsigned int checkInCount;
        struct CheckInRecord *checkInRecords;
    } TeamMember;
    typedef struct CheckInRecord {
        char *date;
        char *checkInTime;
        char *checkOutTime;
        struct CheckInRecord *next;
    } CheckInRecord;
    typedef struct Node {
        TeamMember data;
        struct Node *next;
    } Node;
    Node *head = NULL;
    // 创建新的队员节点
    Node *createNewNode(unsigned int studentNumber, char *name) {
        Node *newNode = (Node *) malloc(sizeof(Node));
        newNode->data.studentNumber = studentNumber;
        newNode->data.name = strdup(name);
        newNode->data.checkInCount = 0;
        newNode->data.checkInRecords = NULL;
        newNode->next = NULL;
        return newNode;
    }
    // 将队员信息插入链表
    void insertTeamMemberInfo(Node *node) {
        if (head == NULL) {
            head = node;
        } else {
            Node *temp = head;
            while (temp->next != NULL) {
                temp = temp->next;
            }
            temp->next = node;
        }
    }
    // 从链表中删除队员信息
    void deleteNode(unsigned int studentNumber) {
        Node *temp = head;
        Node *prev = NULL;
        while (temp != NULL && temp->data.studentNumber != studentNumber) {
            prev = temp;
            temp = temp->next;
        }
        if (temp == NULL) {
            printf("队员信息不存在!\n");
            return;
        }
        if (prev == NULL) {
            head = temp->next;
        } else {
            prev->next = temp->next;
        }
        free(temp->data.name);
        free(temp);
    }
    // 释放链表的内存
    void freeLinkedList() {
        Node *temp = head;
        while (temp != NULL) {
            Node *prev = temp;
            temp = temp->next;
            free(prev->data.name);
            free(prev);
        }
    }
    // 检查输入的打卡记录格式是否正确
    int checkCheckInRecordFormat(char *record) {
        // 检查格式,省略具体实现
        return 1;
    }
    // 检查学号是否冲突
    int checkStudentNumberConflict(unsigned int studentNumber) {
        Node *temp = head;
        while (temp != NULL) {
            if (temp->data.studentNumber == studentNumber) {
                return 1;
            }
            temp = temp->next;
        }
        return 0;
    }
    // 检查打卡次数和打卡记录是否匹配
    int checkCheckInCountAndRecords(unsigned int checkInCount, char *records) {
        // 检查匹配,省略具体实现
        return 1;;
    }
    // 检查打卡时间是否在范围内
    int checkCheckInTime(char *time) {
        // 检查时间,省略具体实现
        return 1;
    }
    // 从文件中加载初始信息
    void loadInitialInfoFromFile(char *filename) {
        // 读取文件并解析初始化信息,省略具体实现
    }
    // 新增队员信息
    void addTeamMemberInfo(unsigned int studentNumber, char *name) {
        if (checkStudentNumberConflict(studentNumber)) {
            printf("学号冲突!\n");
            return;
        }
        Node *newNode = createNewNode(studentNumber, name);
        insertTeamMemberInfo(newNode);
    }
    // 删除队员信息
    void deleteTeamMemberInfo(unsigned int studentNumber) {
        deleteNode(studentNumber);
    }
    // 根据学号查询队员信息
    TeamMember *getTeamMemberInfoByStudentNumber(unsigned int studentNumber) {
        Node *temp = head;
        while (temp != NULL) {
            if (temp->data.studentNumber == studentNumber) {
                return &(temp->data);
            }
            temp = temp->next;
        }
        return NULL;
    }
    // 打印打卡记录按照日期顺序
    void printCheckInRecordsByDate(unsigned int studentNumber) {
        TeamMember *teamMember = getTeamMemberInfoByStudentNumber(studentNumber);
        if (teamMember == NULL) {
            printf("队员信息不存在!\n");
            return;
        }
        // 按日期打印打卡记录,省略具体实现
    }
    // 打印所有队员信息按照学号顺序
    void printAllTeamMembersByStudentNumber() {
        Node *temp = head;
        while (temp != NULL) {
            printf("学号:%u,姓名:%s,打卡次数:%u\n", temp->data.studentNumber, temp->data.name, temp->data.checkInCount);
            temp = temp->next;
        }
    }
    // 导出队员信息到文件
    void exportTeamMemberInfoToFile(char *filename) {
        // 导出队员信息到文件,省略具体实现
    }
    int main() {
        loadInitialInfoFromFile("initial_info.txt");
        addTeamMemberInfo(2001, "yzl");
        addTeamMemberInfo(2005, "zh");
        addTeamMemberInfo(2022, "wk");
        printAllTeamMembersByStudentNumber();
        deleteTeamMemberInfo(2005);
        printAllTeamMembersByStudentNumber();
        exportTeamMemberInfoToFile("exported_info.txt");
        freeLinkedList();
        return 0;
    }
    
    
    评论
  • 玥轩_521 2023-09-24 21:05
    关注
    获得0.40元问题酬金

    援引讯飞星火:
    解析:

    1. 定义一个结构体,包含学号、姓名、打卡次数、打卡记录等信息。
    2. 使用链表存储所有队员信息。
    3. 实现新增、删除队员信息的功能。
    4. 根据学号查询队员信息。
    5. 打印队员信息,可以选择按照日期顺序或者学号顺序。
    6. 将队员信息导出成文件。
    7. 对输入的信息进行合法性检查,如有错误则打印报错并跳过。

    代码:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    typedef struct Attendance {
        unsigned int id;
        char name[20];
        unsigned int count;
        struct TimeRecord {
            int year, month, day;
            char come[20], leave[20];
        } records[65536];
        struct Attendance *next;
    } Attendance;
    
    Attendance *head = NULL;
    
    void add_member(unsigned int id, const char *name, unsigned int count, const struct TimeRecord *records) {
        Attendance *new_member = (Attendance *)malloc(sizeof(Attendance));
        new_member->id = id;
        strcpy(new_member->name, name);
        new_member->count = count;
        for (int i = 0; i < count; i++) {
            new_member->records[i].year = records[i].year - 1900;
            new_member->records[i].month = records[i].month - 1;
            new_member->records[i].day = records[i].day;
            sscanf(records[i].come, "%d:%d—%d:%d", &new_member->records[i].come[0], &new_member->records[i].come[1], &new_member->records[i].leave[0], &new_member->records[i].leave[1]);
            new_member->records[i].come[3] = '\0';
            new_member->records[i].leave[3] = '\0';
        }
        new_member->next = head;
        head = new_member;
    }
    
    void delete_member(unsigned int id) {
        Attendance *current = head;
        Attendance *previous = NULL;
        while (current != NULL) {
            if (current->id == id) {
                if (previous == NULL) {
                    head = current->next;
                } else {
                    previous->next = current->next;
                }
                free(current);
                return;
            }
            previous = current;
            current = current->next;
        }
    }
    
    Attendance *find_member(unsigned int id) {
        Attendance *current = head;
        while (current != NULL) {
            if (current->id == id) {
                return current;
            }
            current = current->next;
        }
        return NULL;
    }
    
    void print_members() {
        Attendance *current = head;
        printf("学号\t姓名\t打卡次数\t打卡记录
    ");
        while (current != NULL) {
            for (int i = 0; i < current->count; i++) {
                printf("%u\t%s\t%u\t%s
    ", current->id, current->name, current->count, current->records[i].year + 1900 << 12 | current->records[i].month << 8 | current->records[i].day);
            }
            current = current->next;
        }
    }
    
    void export_members(const char *filename) {
        FILE *file = fopen(filename, "w");
        if (file == NULL) {
            printf("无法打开文件:%s
    ", filename);
            return;
        }
        Attendance *current = head;
        while (current != NULL) {
            fprintf(file, "%u\t%s\t%u\t%s
    ", current->id, current->name, current->count, current->records[0].year + 1900 << 12 | current->records[0].month << 8 | current->records[0].day);
            current = current->next;
        }
        fclose(file);
    }
    
    int main() {
        // 示例代码,实际应用中应从文件或其他途径读取数据
        add_member(1001, "张三", 2, NULL);
        add_member(1002, "李四", 1, NULL);
        print_members();
        export_members("members.txt");
        return 0;
    }
    
    评论
  • coder_small_bell 2023-09-24 21:33
    关注
    获得0.40元问题酬金

    csdn就有相应的crud代码吧

    评论
  • 心梓知识 2023-09-24 22:45
    关注
    获得0.40元问题酬金

    结合GPT给出回答如下请题主参考
    以下是一个简单的团队考勤系统的实现,使用了结构体和文件操作:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    #define MAX_NAME_LEN 20
    #define MAX_RECORDS 100
    
    typedef struct {
        int id;
        char name[MAX_NAME_LEN];
        int punch_count;
        time_t punch_records[MAX_RECORDS];
        time_t work_time;
    } Member;
    
    Member *team;
    int team_size;
    
    // 读取团队成员信息
    void read_team_info() {
        FILE *fp = fopen("team.txt", "r");
        if (!fp) {
            printf("Failed to open file.\n");
            return;
        }
    
        fscanf(fp, "%d", &team_size);
        team = (Member*)malloc(team_size * sizeof(Member));
    
        for (int i = 0; i < team_size; i++) {
            fscanf(fp, "%d %s %d %ld", &team[i].id, team[i].name, &team[i].punch_count, &team[i].work_time);
            for (int j = 0; j < team[i].punch_count; j++) {
                fscanf(fp, "%ld", &team[i].punch_records[j]);
            }
        }
    
        fclose(fp);
    }
    
    // 保存团队成员信息
    void save_team_info() {
        FILE *fp = fopen("team.txt", "w");
        if (!fp) {
            printf("Failed to open file.\n");
            return;
        }
    
        fprintf(fp, "%d\n", team_size);
        for (int i = 0; i < team_size; i++) {
            fprintf(fp, "%d %s %d %ld", team[i].id, team[i].name, team[i].punch_count, team[i].work_time);
            for (int j = 0; j < team[i].punch_count; j++) {
                fprintf(fp, " %ld", team[i].punch_records[j]);
            }
            fprintf(fp, "\n");
        }
    
        fclose(fp);
    }
    
    // 新增团队成员
    void add_member() {
        team = (Member*)realloc(team, (team_size+1) * sizeof(Member));
    
        printf("Enter Member ID: ");
        scanf("%d", &team[team_size].id);
    
        printf("Enter Member Name: ");
        scanf("%s", team[team_size].name);
    
        team[team_size].punch_count = 0;
        team[team_size].work_time = 0;
    
        team_size++;
    
        save_team_info();
    }
    
    // 删除团队成员
    void delete_member() {
        int id;
        printf("Enter Member ID to delete: ");
        scanf("%d", &id);
    
        for (int i = 0; i < team_size; i++) {
            if (team[i].id == id) {
                for (int j = i; j < team_size-1; j++) {
                    team[j] = team[j+1];
                }
                team_size--;
    
                save_team_info();
                printf("Member deleted.\n");
                return;
            }
        }
    
        printf("Member ID not found.\n");
    }
    
    // 打印团队成员信息
    void print_member_info(Member member) {
        printf("ID: %d\n", member.id);
        printf("Name: %s\n", member.name);
        printf("Punch Count: %d\n", member.punch_count);
        printf("Punch Records: ");
        for (int i = 0; i < member.punch_count; i++) {
            printf("%s", ctime(&member.punch_records[i]));
        }
        printf("Work Time: %ld seconds\n", member.work_time);
    }
    
    // 按学号查询成员信息
    void search_member_by_id() {
        int id;
        printf("Enter Member ID to search: ");
        scanf("%d", &id);
    
        for (int i = 0; i < team_size; i++) {
            if (team[i].id == id) {
                print_member_info(team[i]);
                return;
            }
        }
    
        printf("Member ID not found.\n");
    }
    
    // 按照学号打印所有成员信息
    void print_all_members() {
        for (int i = 0; i < team_size; i++) {
            print_member_info(team[i]);
            printf("\n");
        }
    }
    
    // 打卡
    void punch() {
        int id;
        printf("Enter Member ID: ");
        scanf("%d", &id);
    
        for (int i = 0; i < team_size; i++) {
            if (team[i].id == id) {
                time_t now = time(NULL);
                team[i].punch_records[team[i].punch_count++] = now;
    
                if (team[i].punch_count > 1) {
                    team[i].work_time += now - team[i].punch_records[team[i].punch_count-2];
                }
    
                save_team_info();
                printf("Punch recorded.\n");
                return;
            }
        }
    
        printf("Member ID not found.\n");
    }
    
    int main() {
        read_team_info();
    
        int choice;
        do {
            printf("1. Add Member\n");
            printf("2. Delete Member\n");
            printf("3. Search Member\n");
            printf("4. Print All Members\n");
            printf("5. Punch\n");
            printf("6. Exit\n");
            printf("Enter your choice: ");
            scanf("%d", &choice);
    
            switch (choice) {
                case 1:
                    add_member();
                    break;
                case 2:
                    delete_member();
                    break;
                case 3:
                    search_member_by_id();
                    break;
                case 4:
                    print_all_members();
                    break;
                case 5:
                    punch();
                    break;
                case 6:
                    printf("Goodbye!\n");
                    break;
                default:
                    printf("Invalid choice.\n");
                    break;
            }
        } while (choice != 6);
    
        free(team);
    
        return 0;
    }
    

    其中,团队成员信息从文件 "team.txt" 中读取和保存,文件格式如下:

    3
    1 John 2 3600 1628427268 1628427270
    2 Mary 1 1800 1628427255
    3 Bob 0 0
    

    文件的第一行是团队成员数量,之后每行表示一个团队成员的信息,包括学号、姓名、打卡次数、总工作时间和打卡记录。打卡记录按照时间戳的方式存储,打卡时间可以通过 ctime() 函数转换为字符串格式输出。注意,在新增和删除成员的时候需要重新保存文件。

    可以根据需要修改文件路径和格式。

    评论
  • 想你依然心痛 全栈领域新星创作者 2023-09-25 09:48
    关注
    获得0.60元问题酬金
    
    以下是一个团队考勤系统的实现:
    
    ```c
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    // 打卡记录结构体
    typedef struct {
        int year;
        int month;
        int day;
        int come_hour;
        int come_minute;
        int leave_hour;
        int leave_minute;
    } AttendanceRecord;
    
    // 队员信息结构体
    typedef struct team_member {
        int id;
        char *name;
        int attendance_count;
        AttendanceRecord *attendance_records; // 指向打卡记录链表的指针
        struct team_member *next; // 指向下一个队员的指针
    } TeamMember;
    
    // 创建打卡记录结构体
    AttendanceRecord *create_attendance_record(int year, int month, int day,
                                                int come_hour, int come_minute,
                                                int leave_hour, int leave_minute) {
        AttendanceRecord *record = malloc(sizeof(AttendanceRecord));
        record->year = year;
        record->month = month;
        record->day = day;
        record->come_hour = come_hour;
        record->come_minute = come_minute;
        record->leave_hour = leave_hour;
        record->leave_minute = leave_minute;
        return record;
    }
    
    // 创建队员信息结构体
    TeamMember *create_team_member(int id, char *name, int attendance_count,
                                    AttendanceRecord *attendance_records) {
        TeamMember *member = malloc(sizeof(TeamMember));
        member->id = id;
        member->name = malloc(strlen(name) + 1);
        strcpy(member->name, name);
        member->attendance_count = attendance_count;
        member->attendance_records = attendance_records;
        member->next = NULL;
        return member;
    }
    
    // 释放打卡记录链表的内存
    void free_attendance_records(AttendanceRecord *records) {
        AttendanceRecord *record = records;
        while (record != NULL) {
            AttendanceRecord *next_record = record->next;
            free(record);
            record = next_record;
        }
    }
    
    // 释放队员信息链表的内存
    void free_team_members(TeamMember *members) {
        TeamMember *member = members;
        while (member != NULL) {
            TeamMember *next_member = member->next;
            free(member->name);
            free_attendance_records(member->attendance_records);
            free(member);
            member = next_member;
        }
    }
    
    // 新增队员信息
    void add_team_member(TeamMember **members_ptr, int id, char *name) {
        TeamMember *member = create_team_member(id, name, 0, NULL);
        member->next = *members_ptr;
        *members_ptr = member;
    }
    
    // 删除队员信息
    void delete_team_member(TeamMember **members_ptr, int id) {
        TeamMember *prev_member = NULL;
        TeamMember *member = *members_ptr;
        while (member != NULL) {
            if (member->id == id) {
                if (prev_member == NULL) {
                    *members_ptr = member->next;
                } else {
                    prev_member->next = member->next;
                }
                free(member->name);
                free_attendance_records(member->attendance_records);
                free(member);
                return;
            }
            prev_member = member;
            member = member->next;
        }
    }
    
    // 根据学号查询队员信息
    TeamMember *find_team_member(TeamMember *members, int id) {
        TeamMember *member = members;
        while (member != NULL) {
            if (member->id == id) {
                return member;
            }
            member = member->next;
        }
        return NULL;
    }
    
    // 打印打卡记录
    void print_attendance_records(TeamMember *member) {
        AttendanceRecord *record = member->attendance_records;
        while (record != NULL) {
            printf("%04d.%02d.%02d %02d:%02d~%02d:%02d\n", record->year, record->month, record->day,
                   record->come_hour, record->come_minute, record->leave_hour, record->leave_minute);
            record = record->next;
        }
    }
    
    // 打印队员信息
    void print_team_member(TeamMember *member) {
        printf("%04d %s %d\n", member->id, member->name, member->attendance_count);
        print_attendance_records(member);
    }
    
    // 按学号顺序打印所有队员信息
    void print_all_team_members(TeamMember *members) {
        TeamMember *cur_member = members;
        while (cur_member != NULL) {
            print_team_member(cur_member);
            cur_member = cur_member->next;
        }
    }
    
    // 导出队员信息到文件
    void export_team_members(TeamMember *members, char *filename) {
        FILE *file = fopen(filename, "w");
        if (file == NULL) {
            printf("Failed to export team member information to file %s\n", filename);
            return;
        }
        TeamMember *cur_member = members;
        while (cur_member != NULL) {
            fprintf(file, "%04d %s %d", cur_member->id, cur_member->name, cur_member->attendance_count);
            AttendanceRecord *record = cur_member->attendance_records;
            while (record != NULL) {
                fprintf(file, " %04d.%02d.%02d %02d:%02d~%02d:%02d", record->year, record->month, record->day,
                        record->come_hour, record->come_minute, record->leave_hour, record->leave_minute);
                record = record->next;
            }
            fprintf(file, "\n");
            cur_member = cur_member->next;
        }
        fclose(file);
    }
    
    // 解析打卡记录字符串,返回打卡记录结构体指针,错误返回NULL
    AttendanceRecord *parse_attendance_record(char *record_str) {
        int year, month, day, come_hour, come_minute, leave_hour, leave_minute;
        int parsed = sscanf(record_str, "%d.%d.%d %d:%d~%d:%d", &year, &month, &day,
                            &come_hour, &come_minute, &leave_hour, &leave_minute);
        if (parsed != 7) {
            printf("Invalid attendance record string: %s\n", record_str);
            return NULL;
        }
        if (come_hour < 0 || come_hour > 23 || come_minute < 0 || come_minute > 59 ||
            leave_hour < 0 || leave_hour > 23 || leave_minute < 0 || leave_minute > 59) {
            printf("Invalid attendance record time: %s\n", record_str);
            return NULL;
        }
        if (day < 1 || day > 30) {
            printf("Invalid attendance record day: %s\n", record_str);
            return NULL;
        }
        AttendanceRecord *record = create_attendance_record(year, month, day,
                                                            come_hour, come_minute,
                                                            leave_hour, leave_minute);
        return record;
    }
    
    // 从文件中导入队员信息
    void import_team_members(TeamMember **members_ptr, char *filename) {
        FILE *file = fopen(filename, "r");
        if (file == NULL) {
            printf("Failed to import team member information from file %s\n", filename);
            return;
        }
        char line[1024];
        while (fgets(line, sizeof(line), file) != NULL) {
            int id, attendance_count;
            char name[1024];
            AttendanceRecord *attendance_records = NULL;
            int parsed = sscanf(line, "%d %s %d", &id, name, &attendance_count);
            if (parsed != 3) {
                printf("Invalid team member information line: %s\n", line);
                continue;
            }
            TeamMember *member = create_team_member(id, name, attendance_count, NULL);
            char *record_str = strtok(line + strlen(line) - 1, " "); // 获取最后一个打卡记录字符串
            while (record_str != NULL) {
                AttendanceRecord *record = parse_attendance_record(record_str);
                if (record != NULL) {
                    record->next = attendance_records;
                    attendance_records = record;
                }
                record_str = strtok(NULL, " ");
            }
            member->attendance_records = attendance_records;
            member->next = *members_ptr;
            *members_ptr = member;
        }
        fclose(file);
    }
    
    // 读取用户输入的整数,错误输入返回-1
    int read_int() {
        int value;
        if (scanf("%d", &value) != 1) {
            printf("Invalid input\n");
            value = -1;
        }
        return value;
    }
    
    // 读取用户输入的字符串,返回一个指向该字符串的指针
    char *read_string() {
        char buffer[1024];
        fgets(buffer, sizeof(buffer), stdin);
        buffer[strlen(buffer) - 1] = '\0'; // 去掉末尾的回车符
        char *str = malloc(strlen(buffer) + 1);
        strcpy(str, buffer);
        return str;
    }
    
    void print_menu() {
        printf("1. Add team member\n");
        printf("2. Delete team member\n");
        printf("3. Find team member\n");
        printf("4. Print all team members\n");
        printf("5. Export team member information to file\n
    
    评论
  • 封尘绝念丶 2023-09-25 11:19
    关注
    获得0.40元问题酬金
    
    ```c
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define MAX_NAME_LENGTH 50
    #define MAX_MEMBERS 100
    
    struct Member {
        char name[MAX_NAME_LENGTH];
        int attendance;
    };
    
    struct Team {
        struct Member members[MAX_MEMBERS];
        int memberCount;
    };
    
    void addMember(struct Team* team, const char* name) {
        if (team->memberCount >= MAX_MEMBERS) {
            printf("团队成员已满,无法添加新成员。\n");
            return;
        }
        
        strcpy(team->members[team->memberCount].name, name);
        team->members[team->memberCount].attendance = 0;
        team->memberCount++;
        printf("成员 %s 已成功添加到团队。\n", name);
    }
    
    void markAttendance(struct Team* team, const char* name) {
        for (int i = 0; i < team->memberCount; i++) {
            if (strcmp(team->members[i].name, name) == 0) {
                team->members[i].attendance++;
                printf("成员 %s 的考勤已成功标记。\n", name);
                return;
            }
        }
        
        printf("未找到成员 %s ,请重新输入。\n", name);
    }
    
    void printAttendance(struct Team* team) {
        printf("团队考勤情况:\n");
        for (int i = 0; i < team->memberCount; i++) {
            printf("成员 %s 的出勤次数:%d\n", team->members[i].name, team->members[i].attendance);
        }
    }
    
    int main() {
        struct Team myTeam;
        myTeam.memberCount = 0;
    
        addMember(&myTeam, "张三");
        addMember(&myTeam, "李四");
        addMember(&myTeam, "王五");
    
        markAttendance(&myTeam, "张三");
        markAttendance(&myTeam, "张三");
        markAttendance(&myTeam, "李四");
    
        printAttendance(&myTeam);
    
        return 0;
    }
    

    ```

    评论 编辑记录
  • 紫薇东风折 2023-09-25 19:48
    关注
    获得0.20元问题酬金

    以下内容引用了AI回答:
    以下是一个基于 C 语言的团队考勤系统实现。程序从文件中读取初始信息,支持新增、删除队员信息,以及根据学号查询队员信息。队员信息按学号顺序打印,或者按日期顺序打印打卡记录。同时,队员信息可以导出为文件。
    注意:这个实现没有错误处理和输入验证,这是一个基本的实现,你可以根据需要添加这些功能。

    #include <stdio.h>  
    #include <stdlib.h>  
    #include <string.h>
    typedef struct {  
       int id;  
       char name[20];  
       int count;  
       char record[20][20];  
    } Member;
    typedef struct {  
       Member *head;  
       int size;  
    } MemberList;
    void add_member(MemberList *list, const char *id, const char *name, int count, const char *record) {  
       Member *new_member = (Member *)malloc(sizeof(Member));  
       new_member->id = strtol(id, NULL, 10);  
       strcpy(new_member->name, name);  
       new_member->count = count;  
       strcpy(new_member->record, record);
       list->head = (Member *)realloc(list->head, (list->size + 1) * sizeof(Member *));  
       list->head[list->size++] = new_member;  
    }
    void remove_member(MemberList *list, int id) {  
       int index = -1;  
       for (int i = 0; i < list->size; i++) {  
           if (list->head[i]->id == id) {  
               index = i;  
               break;  
           }  
       }
       if (index!= -1) {  
           Member *member = list->head[index];  
           list->head = (Member *)realloc(list->head, (list->size - 1) * sizeof(Member *));  
           list->head[index] = member->next;  
           free(member);  
           list->size--;  
       }  
    }
    void print_member(const Member *member) {  
       printf("ID: %d, Name: %s, Count: %d, Record: ", member->id, member->name, member->count);  
       for (int i = 0; i < member->count; i++) {  
           printf("%s", member->record[i]);  
       }  
       printf("\n");  
    }
    void print_members(const MemberList *list) {  
       for (int i = 0; i < list->size; i++) {  
           print_member(list->head[i]);  
       }  
    }
    void print_records(const Member *member) {  
       for (int i = 0; i < member->count; i++) {  
           printf("%s, %s", member->record[i], member->record[i + 1]);  
       }  
       printf("\n");  
    }
    void print_records_by_date(const Member *member) {  
       for (int i = 0; i < member->count; i++) {  
           printf("%s.%d.%d, %s", member->record[i].substr(0, 4).c_str(),  
                  member->record[i].substr(4, 2).c_str(), member->record[i].substr(6, 2).c_str(),  
                  member->record[i + 1].substr(0, 4).c_str());  
           printf("%s", member->record[i + 1].substr(4, 2).c_str());  
           printf("\n");  
       }  
    }
    void save_to_file(const char *filename, const MemberList *list) {  
       FILE *file = fopen(filename, "w");  
       for (int i = 0; i < list->size; i++) {  
           fprintf(file, "%d,%s,%d,%s\n", list->head[i]->id, list->head[i]->name,  
                  list->head[i]->count, list->head[i]->record[0]);  
           for (int j = 1; j < list->head[i]->count; j++) {  
               fprintf(file, ",%s", list->head[i]->record[j]);  
           }  
           fprintf(file, "\n
    
    
    
    
    
    
    
    
    评论
  • yy64ll826 2023-09-26 16:15
    关注
    获得0.40元问题酬金

    c语言公司考勤系统

    
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h> 
    #include<time.h>
    
    #define gohour 8 //上午上班时 
    #define gominuter 0 //上午上班分 
    #define outhour 11 //上午下班时 
    #define outminuter 30//上午下班分 
    #define gohour1 13 //下午上班时 
    #define gominuter1 0 //下午上班分 
    #define outhour1 14 //下午下班时 
    #define outminuter1 30  //下午下班分 
    char password[50]="123456";
    char *weekstr[]={"星期一","星期二","星期三","星期四","星期五"};
    struct staff//员工结构体
    {
    int id;//员工号
    char name[50];   //姓名
    int state;//所在状态
    struct staff *next;
    }
    pstaff[1000];//定义一个员工对象
    int  staffnum=0;//定义员工对象数量初始为0
    
    
    struct attendance//考勤结构体
    {
    int id;//考勤编号
    int staffid;//职工编号
    int hour;//考勤时
    int minuter;//考勤分
    char type[50];   //考勤类型
    char detail[50];   //详细情况
    char xingqi[50];//这个是星期几 
    struct attendance *next;//下一个节点的指针 
    }
    pattence[1000];//定义一个考勤对象
    int  attencenum=0;//定义考勤对象数量初始为0
    
    
    
    
    评论
  • Leodong. 2023-09-27 11:46
    关注
    获得0.40元问题酬金

    可以参考下这篇文章:

    以下回答通过自己思路及引用到GPTᴼᴾᴱᴺᴬᴵ搜索,得到内容具体如下:
    解析:

    1. 定义一个结构体,包含学号、姓名、打卡次数、打卡记录等信息。
    2. 创建一个链表,用于存储所有队员的信息。
    3. 编写函数,用于从文件中读取初始信息并存入链表。
    4. 编写函数,用于新增队员信息到链表中。
    5. 编写函数,用于删除队员信息从链表中。
    6. 编写函数,根据学号查询队员信息并打印。
    7. 编写函数,按照日期或学号顺序打印所有队员信息。
    8. 编写函数,将链表中的队员信息导出到文件。
    9. 在主函数中,接收用户输入的指令,调用相应的函数。

    代码如下:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    
    typedef struct {
        unsigned int id;
        char name[20];
        unsigned int count;
        struct timespec record[100];
    } TeamMember;
    
    typedef struct Node {
        TeamMember data;
        struct Node *next;
    } Node;
    
    Node *head = NULL;
    
    void read_data(const char *filename) {
        FILE *fp = fopen(filename, "r");
        if (fp == NULL) {
            printf("Failed to open file: %s
    ", filename);
            exit(1);
        }
        Node *p = head;
        while (fscanf(fp, "%u %s %u", &(p->data.id), p->data.name, &(p->data.count)) != EOF) {
            p->next = (Node *)malloc(sizeof(Node));
            p = p->next;
        }
        fclose(fp);
    }
    
    void add_member() {
        // TODO: implement this function
    }
    
    void delete_member() {
        // TODO: implement this function
    }
    
    void query_member() {
        // TODO: implement this function
    }
    
    void print_members() {
        // TODO: implement this function
    }
    
    void export_data() {
        // TODO: implement this function
    }
    
    int main() {
        char command[20];
        while (scanf("%s", command) != EOF) {
            if (strcmp(command, "read") == 0) {
                read_data("members.txt");
            } else if (strcmp(command, "add") == 0) {
                add_member();
            } else if (strcmp(command, "delete") == 0) {
                delete_member();
            } else if (strcmp(command, "query") == 0) {
                query_member();
            } else if (strcmp(command, "print") == 0) {
                print_members();
            } else if (strcmp(command, "export") == 0) {
                export_data();
            } else {
                printf("Invalid command: %s
    ", command);
            }
        }
        return 0;
    }
    

    注意:这只是一个基本的框架,你需要自己实现每个函数的具体功能。


    如果以上回答对您有所帮助,点击一下采纳该答案~谢谢

    评论
  • bug菌¹ Java领域优质创作者 2023-09-28 00:48
    关注
    获得0.80元问题酬金

    该回答引用ChatGPT,希望对题主有所帮助,如有帮助,还望采纳。


    记录可以定义为一个结构体,如下:

    typedef struct {
        int id;  // 学号
        char *name;  // 姓名
        int punch_times;  // 打卡次数
        PunchRecord *punch_records;  // 打卡记录
        int total_work_time;  // 总工作时间(分钟)
    } TeamMember;
    

    其中,PunchRecord 可以定义为另外一个结构体,如下:

    typedef struct {
        int year;  // 年
        int month;  // 月
        int day;  // 日
        int punch_in_hour;  // 打卡开始小时
        int punch_in_minute;  // 打卡开始分钟
        int punch_out_hour;  // 打卡结束小时
        int punch_out_minute;  // 打卡结束分钟
    } PunchRecord;
    

    接下来可以使用链表来存储所有队员的信息,定义一个链表节点如下:

    typedef struct team_member_node {
        TeamMember *member;  // 队员信息
        struct team_member_node *next;  // 下一个节点指针
    } TeamMemberNode;
    

    然后可以实现以下几个函数来完成团队考勤系统的功能:

    1. read_data():从文件中读取初始数据,创建一个链表存储所有队员信息。
    2. add_member():新增一个队员信息,插入到链表末尾。
    3. delete_member():删除一个队员信息,从链表中移除并释放内存。
    4. find_member_by_id():根据学号查找队员信息,返回一个指向 TeamMember 结构体的指针。
    5. print_member_punch_records():打印某个队员的所有打卡记录,按照日期顺序。
    6. print_all_members():打印所有队员的学号、姓名、打卡次数,按照学号顺序。
    7. export_data():将所有队员信息导出到文件中。

    在实现这些函数时,需要注意以下几个问题:

    1. 在读取数据和新增队员时,需要检查输入数据格式是否正确,如果不正确则打印错误信息并跳过该行记录。
    2. 在新增队员和打卡记录时,需要动态分配内存,使用完毕后需要记得释放。
    3. 在打印打卡记录和所有队员信息时,需要使用指向链表头部的指针遍历整个链表,每次打印一个节点的信息。
    4. 在导出队员信息到文件中时,需要按照指定格式输出每个队员的信息。
    评论
  • 关注
    获得0.40元问题酬金

    开源社区代码其实挺多的你这样代码需求成品,你可以试试搜索

    评论

报告相同问题?

问题事件

  • 系统已结题 10月1日
  • 修改了问题 9月23日
  • 创建了问题 9月23日

悬赏问题

  • ¥20 反编译一款APP手游,解密出lua脚本。
  • ¥15 改一下,代码,让代码符合要求
  • ¥15 报错问题,只有两个错误,如图片所示,i多次初始化
  • ¥15 matlab runtime 如何收费
  • ¥20 用C语言绘制cs1.6方框透视 出现了点问题 绘制不上去 矩阵数据 和敌人坐标都是正确的
  • ¥15 Tpad api账户 api口令
  • ¥30 ppt进度条制作,vba语言
  • ¥15 生信simpleaffy包下载
  • ¥15 在二层网络中,掩码存在包含关系即可通信
  • ¥15 端口转发器解析失败不知道电脑设置了啥