用c语言写一个中文系统,要求如下: 学生档案管理系统 系统中的学生属性:学号,姓名,性别,出生日期,所在院系,班级名, 宿舍号码、电话号码等。其中出生日期可以使用结构体。 功能要求: 1、主菜单设计:按基本要求进行。 2、记录输入:对每个学生的学号、姓名、性别、出生日期、所在院系、班级名, 电话, 进行输入并存储在数据文件中。 3、显示记录:以列表方式显示全部记录。 4、维护记录。能够实现添加、删除、修改学生记录,结果存储到文件中。修改 纪录可以对任意记录的数据进行修改并在修改前后对记录内容进行显示;删除记 录可以删除文件中的任意一个纪录。 5、查询记录。根据学号、姓名、性别、班级等查询学生的信息。如:根据学号 显示某生的记录;根据姓名显示记录;根据性别、班级显示记录,可能有多个记 录。 6、统计记录。计算各班的人数,并以列表的方式显示;分别统计男女生人数。 7、设计学生数据记录
时间: 2024-04-19 18:25:43 浏览: 93
好的,我明白了。下面是一个用C语言编写的简单的学生档案管理系统示例代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100
struct Date {
int day;
int month;
int year;
};
struct Student {
int studentID;
char name[50];
char gender[10];
struct Date birthDate;
char department[50];
char className[50];
char phoneNumber[20];
};
struct Student students[MAX_STUDENTS];
int numStudents = 0;
void displayMenu() {
printf("\n\n----- 学生档案管理系统 -----");
printf("\n1. 记录输入");
printf("\n2. 显示记录");
printf("\n3. 维护记录");
printf("\n4. 查询记录");
printf("\n5. 统计记录");
printf("\n0. 退出系统");
printf("\n请选择操作:");
}
void addStudent() {
struct Student newStudent;
printf("\n请输入学生学号: ");
scanf("%d", &newStudent.studentID);
printf("请输入学生姓名: ");
scanf("%s", newStudent.name);
printf("请输入学生性别: ");
scanf("%s", newStudent.gender);
printf("请输入学生出生日期 (格式:dd mm yyyy): ");
scanf("%d %d %d", &newStudent.birthDate.day, &newStudent.birthDate.month, &newStudent.birthDate.year);
printf("请输入学生所在院系: ");
scanf("%s", newStudent.department);
printf("请输入学生班级名: ");
scanf("%s", newStudent.className);
printf("请输入学生电话号码: ");
scanf("%s", newStudent.phoneNumber);
students[numStudents++] = newStudent;
printf("\n学生记录添加成功!\n");
}
void displayStudents() {
if (numStudents == 0) {
printf("\n没有学生记录!\n");
return;
}
printf("\n----- 学生记录 -----\n");
for (int i = 0; i < numStudents; i++) {
printf("学号: %d\n", students[i].studentID);
printf("姓名: %s\n", students[i].name);
printf("性别: %s\n", students[i].gender);
printf("出生日期: %d/%d/%d\n", students[i].birthDate.day, students[i].birthDate.month, students[i].birthDate.year);
printf("院系: %s\n", students[i].department);
printf("班级名: %s\n", students[i].className);
printf("电话号码: %s\n\n", students[i].phoneNumber);
}
}
void deleteStudent() {
int studentID;
int found = 0;
printf("\n请输入要删除的学生学号: ");
scanf("%d", &studentID);
for (int i = 0; i < numStudents; i++) {
if (students[i].studentID == studentID) {
found = 1;
for (int j = i; j < numStudents - 1; j++) {
students[j] = students[j + 1];
}
numStudents--;
printf("\n学生记录删除成功!\n");
break;
}
}
if (!found) {
printf("\n找不到该学生学号的记录!\n");
}
}
void modifyStudent() {
int studentID;
int found = 0;
printf("\n请输入要修改的学生学号: ");
scanf("%d", &studentID);
for (int i = 0; i < numStudents; i++) {
if (students[i].studentID == studentID) {
found = 1;
printf("请输入学生姓名: ");
scanf("%s", students[i].name);
printf("请输入学生性别: ");
scanf("%s", students[i].gender);
printf("请输入学生出生日期 (格式:dd mm yyyy): ");
scanf("%d %d %d", &students[i].birthDate.day, &students[i].birthDate.month, &students[i].birthDate.year);
printf("请输入学生所在院系: ");
scanf("%s", students[i].department);
printf("请输入学生班级名: ");
scanf("%s", students[i].className);
printf("请输入学生电话号码: ");
scanf("%s", students[i].phoneNumber);
printf("\n学生记录修改成功!\n");
break;
}
}
if (!found) {
printf("\n找不到该学生学号的记录!\n");
}
}
void searchStudents() {
int choice;
char searchValue[50];
int found = 0;
printf("\n请选择查询方式:");
printf("\n1. 根据学号查询");
printf("\n2. 根据姓名查询");
printf("\n3. 根据性别查询");
printf("\n4. 根据班级查询");
printf("\n请选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\n请输入学号: ");
scanf("%s", searchValue);
for (int i = 0; i < numStudents; i++) {
if (students[i].studentID == atoi(searchValue)) {
found = 1;
printf("\n----- 学生记录 -----\n");
printf("学号: %d\n", students[i].studentID);
printf("姓名: %s\n", students[i].name);
printf("性别: %s\n", students[i].gender);
printf("出生日期: %d/%d/%d\n", students[i].birthDate.day, students[i].birthDate.month, students[i].birthDate.year);
printf("院系: %s\n", students[i].department);
printf("班级名: %s\n", students[i].className);
printf("电话号码: %s\n\n", students[i].phoneNumber);
}
}
break;
case 2:
printf("\n请输入姓名: ");
scanf("%s", searchValue);
for (int i = 0; i < numStudents; i++) {
if (strcmp(students[i].name, searchValue) == 0) {
found = 1;
printf("\n----- 学生记录 -----\n");
printf("学号: %d\n", students[i].studentID);
printf("姓名: %s\n", students[i].name);
printf("性别: %s\n", students[i].gender);
printf("出生日期: %d/%d/%d\n", students[i].birthDate.day, students[i].birthDate.month, students[i].birthDate.year);
printf("院系: %s\n", students[i].department);
printf("班级名: %s\n", students[i].className);
printf("电话号码: %s\n\n", students[i].phoneNumber);
}
}
break;
case 3:
printf("\n请输入性别: ");
scanf("%s", searchValue);
for (int i = 0; i < numStudents; i++) {
if (strcmp(students[i].gender, searchValue) == 0) {
found = 1;
printf("\n----- 学生记录 -----\n");
printf("学号: %d\n", students[i].studentID);
printf("姓名: %s\n", students[i].name);
printf("性别: %s\n", students[i].gender);
printf("出生日期: %d/%d/%d\n", students[i].birthDate.day, students[i].birthDate.month, students[i].birthDate.year);
printf("院系: %s\n", students[i].department);
printf("班级名: %s\n", students[i].className);
printf("电话号码: %s\n\n", students[i].phoneNumber);
}
}
break;
case 4:
printf("\n请输入班级名: ");
scanf("%s", searchValue);
for (int i = 0; i < numStudents; i++) {
if (strcmp(students[i].className, searchValue) == 0) {
found = 1;
printf("\n----- 学生记录 -----\n");
printf("学号: %d\n", students[i].studentID);
printf("姓名: %s\n", students[i].name);
printf("性别: %s\n", students[i].gender);
printf("出生日期: %d/%d/%d\n", students[i].birthDate.day, students[i].birthDate.month, students[i].birthDate.year);
printf("院系: %s\n", students[i].department);
printf("班级名: %s\n", students[i].className);
printf("电话号码: %s\n\n", students[i].phoneNumber);
}
}
break;
default:
printf("\n无效的选择!\n");
return;
}
if (!found) {
printf("\n找不到符合条件的记录!\n");
}
}
void countStudents() {
int maleCount = 0;
int femaleCount = 0;
int classes[MAX_STUDENTS];
int numClasses = 0;
for (int i = 0; i < numStudents; i++) {
int classExists = 0;
for (int j = 0; j < numClasses; j++) {
if (strcmp(students[i].className, students[j].className) == 0) {
classExists = 1;
break;
}
}
if (!classExists) {
classes[numClasses++] = i;
}
if (strcmp(students[i].gender, "男") == 0) {
maleCount++;
} else if (strcmp(students[i].gender, "女") == 0) {
femaleCount++;
}
}
printf("\n----- 班级人数 -----\n");
for (int i = 0; i < numClasses; i++) {
int count = 0;
for (int j = 0; j < numStudents; j++) {
if (strcmp(students[j].className, students[classes[i]].className) == 0) {
count++;
}
}
printf("%s: %d\n", students[classes[i]].className, count);
}
printf("\n男生人数: %d\n", maleCount);
printf("女生人数: %d\n", femaleCount);
}
int main() {
int choice;
while (1) {
displayMenu();
scanf("%d", &choice);
switch (choice) {
case 1:
addStudent();
break;
case 2:
displayStudents();
break;
case 3:
modifyStudent();
break;
case 4:
deleteStudent();
break;
case 5:
searchStudents();
break;
case 6:
countStudents();
break;
case 0:
printf("\n感谢使用学生档案管理系统!再见!\n");
exit(0);
default:
printf("\n无效的选择!\n");
}
}
return 0;
}
```
这个示例代码实现了一个简单的学生档案管理系统,具有添加、显示、修改、删除、查询和统计记录的功能。你可以根据需要进行修改和扩展。
阅读全文