parent
dbd3dc9057
commit
8e56917bec
@ -1,65 +1,69 @@
|
||||
# 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);
|
||||
// 删除学生函数
|
||||
void deleteStudent(struct Student students[], int *numStudents, char key[]) {
|
||||
int i, j;
|
||||
|
||||
int main() {
|
||||
struct Student students[100]; // Adjust the size as needed
|
||||
int numStudents = 0;
|
||||
int option;
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
// 查找待删除学生的位置
|
||||
for (i = 0; i < *numStudents; i++) {
|
||||
if (strcmp(students[i].id, key) == 0 || strcmp(students[i].name, key) == 0) {
|
||||
break;
|
||||
}
|
||||
} while (option != 6);
|
||||
}
|
||||
|
||||
return 0;
|
||||
// 如果找到了学生,删除并保持数组有序
|
||||
if (i < *numStudents) {
|
||||
for (j = i; j < *numStudents - 1; j++) {
|
||||
students[j] = students[j + 1];
|
||||
}
|
||||
(*numStudents)--;
|
||||
}
|
||||
}
|
||||
|
||||
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}
|
||||
};
|
||||
|
||||
int numStudents = 3; // 已有学生数量
|
||||
|
||||
}
|
||||
char key[20]; // 待删除学生的学号或姓名
|
||||
printf("请输入待删除学生的学号或姓名:");
|
||||
scanf("%s", key);
|
||||
|
||||
void deleteStudent(struct Student *stu, int *numStudents) {
|
||||
// 调用删除函数
|
||||
deleteStudent(students, &numStudents, key);
|
||||
|
||||
}
|
||||
// 输出剩余学生信息
|
||||
for (int i = 0; i < numStudents; i++) {
|
||||
printf("%s %d %s %.1f %.1f %.1f\n", students[i].id, students[i].class, students[i].name, students[i].score1, students[i].score2, students[i].score3);
|
||||
}
|
||||
|
||||
void selectStudent(struct Student *stu, int numStudents) {
|
||||
// 输出确认信息
|
||||
char confirm[3];
|
||||
printf("Are you sure(yes/no)? ");
|
||||
scanf("%s", confirm);
|
||||
|
||||
if (strcmp(confirm, "no") == 0) {
|
||||
// 用户选择不删除,再次输出所有学生信息
|
||||
for (int i = 0; i < numStudents; i++) {
|
||||
printf("%s %d %s %.1f %.1f %.1f\n", students[i].id, students[i].class, students[i].name, students[i].score1, students[i].score2, students[i].score3);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in new issue