c语言学生管理系统数据结构设计
时间: 2024-01-11 20:04:36 浏览: 62
以下是一个简单的C语言学生管理系统的数据结构设计示例:
```c
#include <stdio.h>
#include <stdlib.h>
#define MAX_STUDENTS 100
typedef struct {
int studentID;
char name[50];
char gender[10];
int age;
char birthdate[20];
char address[100];
char phone[20];
char email[50];
} Student;
typedef struct {
Student students[MAX_STUDENTS];
int count;
} StudentDatabase;
void initializeDatabase(StudentDatabase *database) {
database->count = 0;
}
void addStudent(StudentDatabase *database, Student student) {
if (database->count < MAX_STUDENTS) {
database->students[database->count] = student;
database->count++;
printf("Student added successfully.\n");
} else {
printf("Database is full. Cannot add more students.\n");
}
}
void displayStudents(StudentDatabase database) {
printf("Student List:\n");
for (int i = 0; i < database.count; i++) {
printf("Student ID: %d\n", database.students[i].studentID);
printf("Name: %s\n", database.students[i].name);
printf("Gender: %s\n", database.students[i].gender);
printf("Age: %d\n", database.students[i].age);
printf("Birthdate: %s\n", database.students[i].birthdate);
printf("Address: %s\n", database.students[i].address);
printf("Phone: %s\n", database.students[i].phone);
printf("Email: %s\n", database.students[i].email);
printf("--\n");
}
}
int main() {
StudentDatabase database;
initializeDatabase(&database);
// 添加学生
Student student1 = {1, "John Doe", "Male", 20, "2000-01-01", "123 Main St", "123-456-7890", "john@example.com"};
addStudent(&database, student1);
Student student2 = {2, "Jane Smith", "Female", 22, "1998-05-10", "456 Elm St", "987-654-3210", "jane@example.com"};
addStudent(&database, student2);
// 显示学生列表
displayStudents(database);
return 0;
}
```
阅读全文