|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#define MAX_STUDENTS 100
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
int id;
|
|
|
|
|
char name[50];
|
|
|
|
|
int score;
|
|
|
|
|
} Student;
|
|
|
|
|
|
|
|
|
|
int displayMenu() {
|
|
|
|
|
printf("\nѧ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ\n");
|
|
|
|
|
printf("1. ¼<><C2BC>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("2. <20><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("3. <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("4. ɾ<><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("5. <20><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("6. <20><>ѯѧ<D1AF><D1A7><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
printf("7. <20>˳<EFBFBD>ϵͳ\n");
|
|
|
|
|
printf("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
|
|
|
|
|
int choice;
|
|
|
|
|
scanf("%d", &choice);
|
|
|
|
|
return choice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addStudent(Student students[], int *count) {
|
|
|
|
|
if (*count >= MAX_STUDENTS) {
|
|
|
|
|
printf("ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӹ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ID: ");
|
|
|
|
|
scanf("%d", &students[*count].id);
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
|
|
|
|
|
scanf("%s", students[*count].name);
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>: ");
|
|
|
|
|
scanf("%d", &students[*count].score);
|
|
|
|
|
(*count)++;
|
|
|
|
|
printf("ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ¼<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
}
|
|
|
|
|
c
|
|
|
|
|
|
|
|
|
|
void displayStudents(const Student students[], int count) {
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
printf("û<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
printf("ѧ<EFBFBD><EFBFBD>ID\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD>ɼ<EFBFBD>\n");
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
printf("%d\t%s\t%d\n", students[i].id, students[i].name, students[i].score);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void insertStudent(Student students[], int *count) {
|
|
|
|
|
if (*count >= MAX_STUDENTS) {
|
|
|
|
|
printf("ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӹ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Student newStudent;
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ID: ");
|
|
|
|
|
scanf("%d", &newStudent.id);
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
|
|
|
|
|
scanf("%s", newStudent.name);
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>: ");
|
|
|
|
|
scanf("%d", &newStudent.score);
|
|
|
|
|
|
|
|
|
|
int index = *count;
|
|
|
|
|
while (index > 0 &&students[index - 1].score < newStudent.score) {
|
|
|
|
|
students[index] = students[index - 1];
|
|
|
|
|
index--;
|
|
|
|
|
}
|
|
|
|
|
students[index] = newStudent;
|
|
|
|
|
(*count)++;
|
|
|
|
|
printf("ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void deleteStudent(Student students[], int *count) {
|
|
|
|
|
if (*count == 0) {
|
|
|
|
|
printf("û<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int id;
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ID: ");
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
|
|
|
|
|
int index = -1;
|
|
|
|
|
for (int i = 0; i < *count; i++) {
|
|
|
|
|
if (students[i].id == id) {
|
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
printf("δ<EFBFBD>ҵ<EFBFBD>ָ<EFBFBD><EFBFBD>ID<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = index; i < *count - 1; i++) {
|
|
|
|
|
students[i] = students[i + 1];
|
|
|
|
|
}
|
|
|
|
|
(*count)--;
|
|
|
|
|
printf("ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣɾ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void modifyStudent(Student students[], int count) {
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
printf("û<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int id;
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ĵ<EFBFBD>ѧ<EFBFBD><EFBFBD>ID: ");
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
|
|
|
|
|
int index = -1;
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
if (students[i].id == id) {
|
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
printf("δ<EFBFBD>ҵ<EFBFBD>ָ<EFBFBD><EFBFBD>ID<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
|
|
|
|
|
scanf("%s", students[index].name);
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD>ɼ<EFBFBD>: ");
|
|
|
|
|
scanf("%d", &students[index].score);
|
|
|
|
|
printf("ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ijɹ<EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
qsort(students, count, sizeof(Student), compareStudents);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int compareStudents(const void *a, const void *b) {
|
|
|
|
|
return ((Student *)b)->score - ((Student *)a)->score;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void queryStudent(const Student students[], int count) {
|
|
|
|
|
if (count == 0) {
|
|
|
|
|
printf("û<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int id;
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ID: ");
|
|
|
|
|
scanf("%d", &id);
|
|
|
|
|
|
|
|
|
|
int found = 0;
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
if (students[i].id == id) {
|
|
|
|
|
printf("ѧ<EFBFBD><EFBFBD>ID: %d, <20><><EFBFBD><EFBFBD>: %s, <20>ɼ<EFBFBD>: %d\n", students[i].id, students[i].name, students[i].score);
|
|
|
|
|
found = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
printf("δ<EFBFBD>ҵ<EFBFBD>ָ<EFBFBD><EFBFBD>ID<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
Student students[MAX_STUDENTS];
|
|
|
|
|
int count = 0;
|
|
|
|
|
int choice;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
choice = displayMenu();
|
|
|
|
|
switch (choice) {
|
|
|
|
|
case 1:
|
|
|
|
|
addStudent(students, &count);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
displayStudents(students, count);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
insertStudent(students, &count);
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
deleteStudent(students, &count);
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
modifyStudent(students, count);
|
|
|
|
|
break;
|
|
|
|
|
case 6:
|
|
|
|
|
queryStudent(students, count);
|
|
|
|
|
break;
|
|
|
|
|
case 7:
|
|
|
|
|
printf("<EFBFBD>˳<EFBFBD>ϵͳ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
printf("<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>롣\n");
|
|
|
|
|
}
|
|
|
|
|
} while (choice != 7);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
|