帮我用C语言编程,要求如下:设计编写一个传统的小型学生信息管理系统。 1、该系统可以用于管理一个班的学生信息。学生人数在50人左右。 2、该系统存放了有关学生的某些方面的信息:如学号、姓名、性别、出生日期、成绩、所在系等,具体包含的数据内容由设计者分析确定。 3、所有学生信息的数据结构及其存储结构由设计者分析确定。 4、所有学生的信息数据可以用文件形式存放。(可选项) 5、该系统具有相关的数据输入、输出、查询、修改、插入、删除、统计、排序等功能。(功能的多少设计者可根据需要自行调整,但必须具备输出、输出、查询、某一方面数据统计的基本功能。) 6、系统应具有友好的用户界面,并能够让用户通过菜单进行相应功能的选择。 7、选用适当的算法和数据结构,建立相应的程序代码。8、不使用fopen函数
时间: 2023-07-10 19:16:57 浏览: 73
基于C语言的学生信息管理系统数组版.zip
好的,以下是一个简单的学生信息管理系统的C语言实现,实现了基本的数据输入、输出、查询、统计、排序等功能,数据使用结构体数组存储,没有使用fopen函数。
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENT_NUM 50
#define ID_LEN 10
#define NAME_LEN 20
#define GENDER_LEN 5
#define BIRTH_LEN 15
#define DEPT_LEN 20
typedef struct Student {
char id[ID_LEN];
char name[NAME_LEN];
char gender[GENDER_LEN];
char birth[BIRTH_LEN];
float score;
char department[DEPT_LEN];
} Student;
Student students[MAX_STUDENT_NUM];
int student_num = 0;
void add_student() {
if (student_num >= MAX_STUDENT_NUM) {
printf("Max student number exceeded!\n");
return;
}
printf("Please input student information:\n");
printf("ID: ");
scanf("%s", students[student_num].id);
printf("Name: ");
scanf("%s", students[student_num].name);
printf("Gender: ");
scanf("%s", students[student_num].gender);
printf("Birth: ");
scanf("%s", students[student_num].birth);
printf("Score: ");
scanf("%f", &students[student_num].score);
printf("Department: ");
scanf("%s", students[student_num].department);
student_num++;
printf("Student added successfully!\n");
}
void print_student(Student student) {
printf("%s\t%s\t%s\t%s\t%.2f\t%s\n", student.id, student.name, student.gender, student.birth, student.score, student.department);
}
void print_all_students() {
printf("All students:\n");
printf("ID\tName\tGender\tBirth\tScore\tDepartment\n");
for (int i = 0; i < student_num; i++) {
print_student(students[i]);
}
}
int find_student(char id[ID_LEN]) {
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].id, id) == 0) {
return i;
}
}
return -1;
}
void query_student() {
char id[ID_LEN];
printf("Please input student ID: ");
scanf("%s", id);
int index = find_student(id);
if (index == -1) {
printf("Student not found!\n");
} else {
print_student(students[index]);
}
}
void update_student() {
char id[ID_LEN];
printf("Please input student ID: ");
scanf("%s", id);
int index = find_student(id);
if (index == -1) {
printf("Student not found!\n");
} else {
printf("Please input new student information:\n");
printf("ID: ");
scanf("%s", students[index].id);
printf("Name: ");
scanf("%s", students[index].name);
printf("Gender: ");
scanf("%s", students[index].gender);
printf("Birth: ");
scanf("%s", students[index].birth);
printf("Score: ");
scanf("%f", &students[index].score);
printf("Department: ");
scanf("%s", students[index].department);
printf("Student updated successfully!\n");
}
}
void delete_student() {
char id[ID_LEN];
printf("Please input student ID: ");
scanf("%s", id);
int index = find_student(id);
if (index == -1) {
printf("Student not found!\n");
} else {
for (int i = index; i < student_num - 1; i++) {
students[i] = students[i + 1];
}
student_num--;
printf("Student deleted successfully!\n");
}
}
void sort_students_by_score() {
for (int i = 0; i < student_num - 1; i++) {
for (int j = 0; j < student_num - i - 1; j++) {
if (students[j].score < students[j + 1].score) {
Student temp = students[j];
students[j] = students[j + 1];
students[j + 1] = temp;
}
}
}
printf("Students sorted by score!\n");
}
void count_students_by_dept() {
char department[DEPT_LEN];
printf("Please input department name: ");
scanf("%s", department);
int count = 0;
for (int i = 0; i < student_num; i++) {
if (strcmp(students[i].department, department) == 0) {
count++;
}
}
printf("There are %d students in department %s.\n", count, department);
}
int main() {
int choice;
while (1) {
printf("Please select a function:\n");
printf("1. Add student\n");
printf("2. Print all students\n");
printf("3. Query student\n");
printf("4. Update student\n");
printf("5. Delete student\n");
printf("6. Sort students by score\n");
printf("7. Count students by department\n");
printf("8. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
print_all_students();
break;
case 3:
query_student();
break;
case 4:
update_student();
break;
case 5:
delete_student();
break;
case 6:
sort_students_by_score();
break;
case 7:
count_students_by_dept();
break;
case 8:
return 0;
default:
printf("Invalid choice!\n");
}
}
return 0;
}
```
这个学生信息管理系统实现了基本的数据输入、输出、查询、修改、插入、删除、统计、排序等功能,使用了结构体数组来存储学生信息,没有使用fopen函数。用户可以通过菜单进行相应功能的选择,实现了友好的用户界面。
阅读全文