C语言设计一考勤系统。考勤信息记录了学生的缺课情况,它包括:缺课日期、第几节课、课程名称、学生姓名、学生学号、缺课类型(迟到、早退、请假及旷课)。系统具有以下功能: 1、 录入学生的缺课记录; 2、 修改某个学生的缺课记录; 3、 查询某个学生的缺课情况; 4、 统计某段时间内,旷课学生姓名及旷课次数,按旷课次数由多到少排序; 5、 统计某段时间内,有学生旷课的课程及旷课人次,按旷课人次由多到少排序; 6、 系统以菜单方式工作。

时间: 2023-07-10 14:03:59 浏览: 40
以下是一个基本的考勤系统的C语言实现: ```c #include <stdio.h> #include <string.h> #define MAX_STUDENTS 100 #define MAX_ABSENCES 200 typedef struct { int day; int period; char course[50]; char name[50]; char id[20]; char type[10]; } Absence; typedef struct { char name[50]; char id[20]; int num_absences; Absence absences[MAX_ABSENCES]; } Student; Student students[MAX_STUDENTS]; int num_students = 0; void add_absence() { printf("Enter absence information:\n"); Absence absence; printf("Day: "); scanf("%d", &absence.day); printf("Period: "); scanf("%d", &absence.period); printf("Course: "); scanf("%s", absence.course); printf("Name: "); scanf("%s", absence.name); printf("ID: "); scanf("%s", absence.id); printf("Type (late, early, leave, absent): "); scanf("%s", absence.type); // Find the student and add the absence to their record int i; for (i = 0; i < num_students; i++) { if (strcmp(students[i].name, absence.name) == 0 && strcmp(students[i].id, absence.id) == 0) { students[i].absences[students[i].num_absences] = absence; students[i].num_absences++; printf("Absence added.\n"); return; } } // If the student wasn't found, create a new record for them Student student; strcpy(student.name, absence.name); strcpy(student.id, absence.id); student.absences[0] = absence; student.num_absences = 1; students[num_students] = student; num_students++; printf("Student and absence added.\n"); } void modify_absence() { char name[50]; char id[20]; printf("Enter the name and ID of the student whose absence you want to modify:\n"); scanf("%s %s", name, id); // Find the student int i, j; for (i = 0; i < num_students; i++) { if (strcmp(students[i].name, name) == 0 && strcmp(students[i].id, id) == 0) { // Display the student's absences and prompt the user to choose one to modify printf("Student found. Here are their absences:\n"); for (j = 0; j < students[i].num_absences; j++) { printf("%d %d %s %s %s %s\n", students[i].absences[j].day, students[i].absences[j].period, students[i].absences[j].course, students[i].absences[j].name, students[i].absences[j].id, students[i].absences[j].type); } printf("Enter the number of the absence you want to modify:\n"); int num; scanf("%d", &num); if (num < 0 || num >= students[i].num_absences) { printf("Invalid absence number.\n"); return; } // Modify the absence Absence absence = students[i].absences[num]; printf("Enter new information for the absence:\n"); printf("Day: "); scanf("%d", &absence.day); printf("Period: "); scanf("%d", &absence.period); printf("Course: "); scanf("%s", absence.course); printf("Name: "); scanf("%s", absence.name); printf("ID: "); scanf("%s", absence.id); printf("Type (late, early, leave, absent): "); scanf("%s", absence.type); students[i].absences[num] = absence; printf("Absence modified.\n"); return; } } printf("Student not found.\n"); } void display_student() { char name[50]; char id[20]; printf("Enter the name and ID of the student whose absences you want to display:\n"); scanf("%s %s", name, id); // Find the student and display their absences int i, j; for (i = 0; i < num_students; i++) { if (strcmp(students[i].name, name) == 0 && strcmp(students[i].id, id) == 0) { printf("Student found. Here are their absences:\n"); for (j = 0; j < students[i].num_absences; j++) { printf("%d %d %s %s %s %s\n", students[i].absences[j].day, students[i].absences[j].period, students[i].absences[j].course, students[i].absences[j].name, students[i].absences[j].id, students[i].absences[j].type); } return; } } printf("Student not found.\n"); } void sort_students(int arr[], int n) { int i, j; for (i = 0; i < n-1; i++) { for (j = 0; j < n-i-1; j++) { if (arr[j] < arr[j+1]) { int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } } void display_ranked_students() { int start_day, end_day; printf("Enter the starting and ending days of the period you want to check:\n"); scanf("%d %d", &start_day, &end_day); // Count the number of absences for each student in the period int num_absences[num_students]; int i, j; for (i = 0; i < num_students; i++) { num_absences[i] = 0; for (j = 0; j < students[i].num_absences; j++) { if (students[i].absences[j].day >= start_day && students[i].absences[j].day <= end_day && strcmp(students[i].absences[j].type, "absent") == 0) { num_absences[i]++; } } } // Sort the students by number of absences and display them sort_students(num_absences, num_students); printf("Students ranked by number of absences:\n"); for (i = 0; i < num_students; i++) { for (j = 0; j < num_students; j++) { if (num_absences[i] == 0) { break; } if (strcmp(students[j].id, "") != 0 && num_absences[i] == students[j].num_absences) { printf("%s: %d absences\n", students[j].name, num_absences[i]); students[j].id[0] = '\0'; // Mark the student as already displayed break; } } } } void display_ranked_courses() { int start_day, end_day; printf("Enter the starting and ending days of the period you want to check:\n"); scanf("%d %d", &start_day, &end_day); // Count the number of absences for each course in the period char courses[MAX_ABSENCES][50]; int num_absences[MAX_ABSENCES]; int num_courses = 0; int i, j, k; for (i = 0; i < num_students; i++) { for (j = 0; j < students[i].num_absences; j++) { if (students[i].absences[j].day >= start_day && students[i].absences[j].day <= end_day && strcmp(students[i].absences[j].type, "absent") == 0) { // Check if the course has already been added to the array int found = 0; for (k = 0; k < num_courses; k++) { if (strcmp(courses[k], students[i].absences[j].course) == 0) { num_absences[k]++; found = 1; break; } } // If not, add it if (!found) { strcpy(courses[num_courses], students[i].absences[j].course); num_absences[num_courses] = 1; num_courses++; } } } } // Sort the courses by number of absences and display them sort_students(num_absences, num_courses); printf("Courses ranked by number of absences:\n"); for (i = 0; i < num_courses; i++) { for (j = 0; j < num_courses; j++) { if (num_absences[i] == 0) { break; } if (strcmp(courses[j], "") != 0 && num_absences[i] == num_absences[j]) { printf("%s: %d absences\n", courses[j], num_absences[i]); courses[j][0] = '\0'; // Mark the course as already displayed break; } } } } int main() { int choice; do { printf("\nAttendance System Main Menu\n"); printf("1. Add an absence\n"); printf("2. Modify an absence\n"); printf("3. Display a student's absences\n"); printf("4. Display ranked list of students with most absences\n"); printf("5. Display ranked list of courses with most absences\n"); printf("6. Quit\n"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: add_absence(); break; case 2: modify_absence(); break; case 3: display_student(); break; case 4: display_ranked_students(); break; case 5: display_ranked_courses(); break; case 6: printf("Goodbye!\n"); break; default: printf("Invalid choice.\n"); break; } } while (choice != 6); return 0; } ``` 该程序使用结构体来存储每个学生的考勤记录,并提供了菜单选项来添加、修改、查询和统计缺课记录。`sort_students`函数使用冒泡排序将一个整数数组按降序排列。`display_ranked_students`和`display_ranked_courses`函数分别统计某段时间内旷课最多的学生和课程,并按旷课次数由多到少排序后显示。

相关推荐

最新推荐

recommend-type

C语言实现学生选修课程系统设计

主要为大家详细介绍了C语言实现学生选修课程系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C语言程序设计实现学生成绩记录簿

通过编写c语言《学生成绩记录簿系统》让我知道所学的编程语言是需要多练多编写代码锻炼出来的。 1)C语言课程设计的主要目的是培养学生综合运用C语言程序设计课程所学到的知识,编写C程序解决实际问题的能力,以及...
recommend-type

C语言数组实现学生信息管理系统设计

主要为大家详细介绍了C语言数组实现学生信息管理系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C语言课程设计论文-学生考勤系统设计

◎录入功能:使用结构体,要求用户输入姓名、性别、学号、日期、节次、当前出勤情况等信息,并写入文件。 ◎修改功能:使用户输入学号,姓名其中一项可以修改考勤其信息。对于修改功能的实现,是先将所有文件内容...
recommend-type

小学生测验C语言课程设计报告

1.通过本课程设计,培养上机动手能力,使学生巩固《C语言程序设计》课程学习的内容,掌握工程软件设计的基本方法,强化上机动手能力,闯过编程关; 2.为后续各门计算机课程的学习打下坚实基础; 3.理解程序设计的思路...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用matlab绘制高斯色噪声情况下的频率估计CRLB,其中w(n)是零均值高斯色噪声,w(n)=0.8*w(n-1)+e(n),e(n)服从零均值方差为se的高斯分布

以下是用matlab绘制高斯色噪声情况下频率估计CRLB的代码: ```matlab % 参数设置 N = 100; % 信号长度 se = 0.5; % 噪声方差 w = zeros(N,1); % 高斯色噪声 w(1) = randn(1)*sqrt(se); for n = 2:N w(n) = 0.8*w(n-1) + randn(1)*sqrt(se); end % 计算频率估计CRLB fs = 1; % 采样频率 df = 0.01; % 频率分辨率 f = 0:df:fs/2; % 频率范围 M = length(f); CRLB = zeros(M,1); for
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。