用C语言写一个考场安排程序
时间: 2023-05-19 08:02:10 浏览: 103
C语言10个经典小程序
好的,我可以为您提供一个基本的考场安排程序的代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_EXAMS 100
#define MAX_STUDENTS 1000
typedef struct {
int id;
char name[50];
int exam_id;
} Student;
typedef struct {
int id;
char name[50];
int num_students;
int* student_ids;
} Exam;
int num_exams = 0;
Exam exams[MAX_EXAMS];
int num_students = 0;
Student students[MAX_STUDENTS];
void add_exam(char* name, int num_students, int* student_ids) {
exams[num_exams].id = num_exams + 1;
strcpy(exams[num_exams].name, name);
exams[num_exams].num_students = num_students;
exams[num_exams].student_ids = student_ids;
num_exams++;
}
void add_student(char* name, int exam_id) {
students[num_students].id = num_students + 1;
strcpy(students[num_students].name, name);
students[num_students].exam_id = exam_id;
num_students++;
}
void print_exam_schedule() {
printf("Exam Schedule:\n");
for (int i = 0; i < num_exams; i++) {
printf("Exam %d: %s\n", exams[i].id, exams[i].name);
printf("Students:\n");
for (int j = 0; j < exams[i].num_students; j++) {
int student_id = exams[i].student_ids[j];
printf("%d. %s\n", students[student_id].id, students[student_id].name);
}
printf("\n");
}
}
int main() {
// Add exams
int exam1_students[] = {0, 1, 2};
add_exam("Math", 3, exam1_students);
int exam2_students[] = {3, 4, 5};
add_exam("English", 3, exam2_students);
// Add students
add_student("Alice", 1);
add_student("Bob", 1);
add_student("Charlie", 1);
add_student("David", 2);
add_student("Eve", 2);
add_student("Frank", 2);
// Print exam schedule
print_exam_schedule();
return 0;
}
```
这个程序可以让您添加考试和学生,并打印出考试安排。请注意,这只是一个基本的示例,您可以根据需要进行修改和扩展。
阅读全文