|
|
|
@ -1,65 +1,97 @@
|
|
|
|
|
# Student_registration_management_system
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
// 定义学生结构体
|
|
|
|
|
struct Student {
|
|
|
|
|
char id[20];
|
|
|
|
|
char clas[20];
|
|
|
|
|
char id[10];
|
|
|
|
|
int class;
|
|
|
|
|
char name[20];
|
|
|
|
|
double score1;
|
|
|
|
|
double score2;
|
|
|
|
|
double score3;
|
|
|
|
|
double score;
|
|
|
|
|
float score1;
|
|
|
|
|
float score2;
|
|
|
|
|
float score3;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Function prototypes
|
|
|
|
|
void inputStudent(struct Student *stu);
|
|
|
|
|
void deleteStudent(struct Student *stu, int *numStudents);
|
|
|
|
|
void selectStudent(struct Student *stu, int numStudents);
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
struct Student students[100]; // Adjust the size as needed
|
|
|
|
|
int numStudents = 0;
|
|
|
|
|
int option;
|
|
|
|
|
// 修改学生信息函数
|
|
|
|
|
void modifyStudent(struct Student students[], int numStudents, char key[], int newClass, char newName[], float newScore1, float newScore2, float newScore3) {
|
|
|
|
|
// 查找待修改学生的位置
|
|
|
|
|
for (int i = 0; i < numStudents; i++) {
|
|
|
|
|
if (strcmp(students[i].id, key) == 0) {
|
|
|
|
|
// 找到学生,修改信息
|
|
|
|
|
students[i].class = newClass;
|
|
|
|
|
strcpy(students[i].name, newName);
|
|
|
|
|
students[i].score1 = newScore1;
|
|
|
|
|
students[i].score2 = newScore2;
|
|
|
|
|
students[i].score3 = newScore3;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
// Display menu
|
|
|
|
|
printf("1. Input\n2. Delete\n3. Select\n4. Order\n5. Output\n6. Quit\n");
|
|
|
|
|
printf("Please input your option: ");
|
|
|
|
|
scanf("%d", &option);
|
|
|
|
|
// 输出学生信息函数
|
|
|
|
|
void printStudents(struct Student students[], int numStudents) {
|
|
|
|
|
for (int i = 0; i < numStudents; i++) {
|
|
|
|
|
if (i == 0 || students[i].class != students[i - 1].class) {
|
|
|
|
|
// 输出班级信息
|
|
|
|
|
printf("%d %s %s %.1f %.1f %.1f", students[i].class, students[i].id, students[i].name, students[i].score1, students[i].score2, students[i].score3);
|
|
|
|
|
} else {
|
|
|
|
|
// 缩进输出
|
|
|
|
|
printf(" %s %s %.1f %.1f %.1f", students[i].id, students[i].name, students[i].score1, students[i].score2, students[i].score3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (option) {
|
|
|
|
|
case 1:
|
|
|
|
|
inputStudent(&students[numStudents]);
|
|
|
|
|
numStudents++;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
deleteStudent(students, &numStudents);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
selectStudent(students, numStudents);
|
|
|
|
|
break;
|
|
|
|
|
// Add cases for other options (order, output) if needed
|
|
|
|
|
case 6:
|
|
|
|
|
printf("Exiting the program.\n");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("Invalid option. Please try again.\n");
|
|
|
|
|
if (i == numStudents - 1) {
|
|
|
|
|
// 输出 modified
|
|
|
|
|
printf(" modified");
|
|
|
|
|
}
|
|
|
|
|
} while (option != 6);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void inputStudent(struct Student *stu) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
int main() {
|
|
|
|
|
// 初始化已有学生信息
|
|
|
|
|
struct Student students[3] = {
|
|
|
|
|
{"10001", 11, "Zhang", 99.5, 88.5, 89.5},
|
|
|
|
|
{"10002", 12, "Yang", 77.9, 56.5, 87.5},
|
|
|
|
|
{"10003", 11, "Liang", 92.5, 99.0, 60.5}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void deleteStudent(struct Student *stu, int *numStudents) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
int numStudents = 3; // 已有学生数量
|
|
|
|
|
|
|
|
|
|
void selectStudent(struct Student *stu, int numStudents) {
|
|
|
|
|
|
|
|
|
|
// 输入待修改学生的信息
|
|
|
|
|
char key[10];
|
|
|
|
|
int newClass;
|
|
|
|
|
char newName[20];
|
|
|
|
|
float newScore1, newScore2, newScore3;
|
|
|
|
|
|
|
|
|
|
printf("请输入待修改学生的学号:");
|
|
|
|
|
scanf("%s", key);
|
|
|
|
|
|
|
|
|
|
// 查找学生并输入新的信息
|
|
|
|
|
for (int i = 0; i < numStudents; i++) {
|
|
|
|
|
if (strcmp(students[i].id, key) == 0) {
|
|
|
|
|
printf("请输入新的班级:");
|
|
|
|
|
scanf("%d", &newClass);
|
|
|
|
|
printf("请输入新的姓名:");
|
|
|
|
|
scanf("%s", newName);
|
|
|
|
|
printf("请输入新的成绩1:");
|
|
|
|
|
scanf("%f", &newScore1);
|
|
|
|
|
printf("请输入新的成绩2:");
|
|
|
|
|
scanf("%f", &newScore2);
|
|
|
|
|
printf("请输入新的成绩3:");
|
|
|
|
|
scanf("%f", &newScore3);
|
|
|
|
|
|
|
|
|
|
// 调用修改函数
|
|
|
|
|
modifyStudent(students, numStudents, key, newClass, newName, newScore1, newScore2, newScore3);
|
|
|
|
|
|
|
|
|
|
// 输出更新后的学生信息
|
|
|
|
|
printStudents(students, numStudents);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果未找到学生,直接输出原有学生信息
|
|
|
|
|
printStudents(students, numStudents);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|