学籍档案管理程序+C语言程序设计
时间: 2023-12-14 19:05:56 浏览: 70
以下是一个简单的学籍档案管理程序的C语言代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct student {
char id[20];
char name[20];
char gender[10];
int age;
char birthdate[20];
char phone[20];
char email[50];
char hometown[50];
};
struct student students[MAX_STUDENTS];
int num_students = 0;
void add_student() {
if (num_students >= MAX_STUDENTS) {
printf("Error: too many students\n");
return;
}
struct student s;
printf("Enter student ID: ");
scanf("%s", s.id);
printf("Enter student name: ");
scanf("%s", s.name);
printf("Enter student gender: ");
scanf("%s", s.gender);
printf("Enter student age: ");
scanf("%d", &s.age);
printf("Enter student birthdate: ");
scanf("%s", s.birthdate);
printf("Enter student phone: ");
scanf("%s", s.phone);
printf("Enter student email: ");
scanf("%s", s.email);
printf("Enter student hometown: ");
scanf("%s", s.hometown);
students[num_students++] = s;
printf("Student added successfully\n");
}
void print_student(struct student s) {
printf("ID: %s\n", s.id);
printf("Name: %s\n", s.name);
printf("Gender: %s\n", s.gender);
printf("Age: %d\n", s.age);
printf("Birthdate: %s\n", s.birthdate);
printf("Phone: %s\n", s.phone);
printf("Email: %s\n", s.email);
printf("Hometown: %s\n", s.hometown);
}
void browse_students() {
if (num_students == 0) {
printf("No students found\n");
return;
}
for (int i = 0; i < num_students; i++) {
printf("Student %d:\n", i + 1);
print_student(students[i]);
}
}
void modify_student() {
if (num_students == 0) {
printf("No students found\n");
return;
}
char id[20];
printf("Enter student ID to modify: ");
scanf("%s", id);
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].id, id) == 0) {
printf("Enter new student information:\n");
printf("Enter student name: ");
scanf("%s", students[i].name);
printf("Enter student gender: ");
scanf("%s", students[i].gender);
printf("Enter student age: ");
scanf("%d", &students[i].age);
printf("Enter student birthdate: ");
scanf("%s", students[i].birthdate);
printf("Enter student phone: ");
scanf("%s", students[i].phone);
printf("Enter student email: ");
scanf("%s", students[i].email);
printf("Enter student hometown: ");
scanf("%s", students[i].hometown);
printf("Student modified successfully\n");
return;
}
}
printf("Error: student not found\n");
}
void delete_student() {
if (num_students == 0) {
printf("No students found\n");
return;
}
char id[20];
printf("Enter student ID to delete: ");
scanf("%s", id);
for (int i = 0; i < num_students; i++) {
if (strcmp(students[i].id, id) == 0) {
for (int j = i; j < num_students - 1; j++) {
students[j] = students[j + 1];
}
num_students--;
printf("Student deleted successfully\n");
return;
}
}
printf("Error: student not found\n");
}
int main() {
int choice;
while (1) {
printf("\n");
printf("1. Add student\n");
printf("2. Browse students\n");
printf("3. Modify student\n");
printf("4. Delete student\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
browse_students();
break;
case 3:
modify_student();
break;
case 4:
delete_student();
break;
case 5:
exit(0);
default:
printf("Invalid choice\n");
}
}
return 0;
}
```
阅读全文