From 6b130f4facde5505a17244e5a1d473162437d04f Mon Sep 17 00:00:00 2001 From: pq52sx6n8 <2731407373@qq.com> Date: Wed, 21 May 2025 16:11:15 +0800 Subject: [PATCH] =?UTF-8?q?Delete=20'=E5=AD=A6=E7=94=9F=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B3=BB=E7=BB=9F.cpp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 学生成绩管理系统.cpp | 252 ----------------------------------- 1 file changed, 252 deletions(-) delete mode 100644 学生成绩管理系统.cpp diff --git a/学生成绩管理系统.cpp b/学生成绩管理系统.cpp deleted file mode 100644 index b89e96d..0000000 --- a/学生成绩管理系统.cpp +++ /dev/null @@ -1,252 +0,0 @@ -#include -#include -#include - -typedef struct { - char num[20]; // ѧ - char name[10]; // - int math_score; // ɼ - int datastruct_score; // ݽṹɼ - int English_score; // Ӣɼ - int physics_score; // ɼ - float average; // ƽ -} Student; - -typedef struct { - Student *data; - int length; -} funlist; - -// ʼԱ -void initlist(funlist *l) { - l->data = (Student *)malloc(100 * sizeof(Student)); - l->length = 0; -} - -// жǷΪձ -int isempty(funlist *l) { - return l->length == 0; -} - -// ȡֵ -int getelem(funlist l, int i, Student *e) { - if (i < 1 || i > l.length) { - printf("λòϷ\n"); - return 0; - } - *e = l.data[i - 1]; - return 1; -} - -// ƽ -float calculate_average(Student *s) { - return (s->math_score + s->datastruct_score + s->English_score + s->physics_score) / 4.0f; -} - -// ӡ -void printlist(funlist l) { - int i; - printf("ɼΪ:\n"); - for (i = 0; i < l.length; i++) { - printf("ѧ:%s :%s :%d ݽṹ:%d Ӣ:%d :%d ƽ:%.2f\n", - l.data[i].num, l.data[i].name, l.data[i].math_score, - l.data[i].datastruct_score, l.data[i].English_score, - l.data[i].physics_score, l.data[i].average); - } -} - -// ҲѧŲң -int locateelem1(funlist l, char *num) { - int i; - for (i = 0; i < l.length; i++) { - if (strcmp(l.data[i].num, num) == 0) - return i + 1; - } - return -1; -} - -// Ҳң -int locateelem2(funlist l, char *name) { - int i; - for (i = 0; i < l.length; i++) { - if (strcmp(l.data[i].name, name) == 0) - return i + 1; - } - return -1; -} - -// ɾ -int deleteelem(funlist *l, int i) { - int j; - if (i < 1 || i > l->length) { - printf("λòϷ\n"); - return 0; - } - for (j = i; j < l->length; j++) { - l->data[j - 1] = l->data[j]; - } - l->length--; - return 1; -} - -// -int listinsert(funlist *l, int i, Student e) { - if (i < 1 || i > l->length + 1) { - printf("λòϷ\n"); - return 0; - } - if (l->length >= 100) { - printf("Ա\n"); - return 0; - } - int j; - for (j = l->length - 1; j >= i - 1; j--) { - l->data[j + 1] = l->data[j]; - } - // 㲢ƽ - e.average = calculate_average(&e); - l->data[i - 1] = e; - l->length++; - return 1; // 1ʾɹ -} - -// ƽ -void sort_by_average(funlist *l) { - if (l->length <= 1) return; // - - int i, j; - for (i = 0; i < l->length - 1; i++) { - for (j = 0; j < l->length - i - 1; j++) { - if (l->data[j].average < l->data[j + 1].average) { - Student temp = l->data[j]; - l->data[j] = l->data[j + 1]; - l->data[j + 1] = temp; - } - } - } - printf("ѧѰƽֽ\n"); -} - -int main() { - funlist L; - initlist(&L); - - int choice; - char num[20]; - char name[10]; - int math_score; - int datastruct_score; - int English_score; - int physics_score; - int i; - - printf("1.ѧ\n"); - printf("2.ͨѧŲѯѧ\n"); - printf("3.ͨѯѧ\n"); - printf("4.ɾѧ\n"); - printf("5.ƽѧ\n"); - printf("6.˳\n"); - - while (1) { - printf("ѡ:"); - scanf("%d", &choice); - switch (choice) { - case 1: { - Student e; - printf(":"); - scanf("%s", name); - strcpy(e.name, name); - - printf("ѧ:"); - scanf("%s", num); - strcpy(e.num, num); - - printf("ɼ:"); - scanf("%d", &math_score); - e.math_score = math_score; - - printf("ݽṹɼ:"); - scanf("%d", &datastruct_score); - e.datastruct_score = datastruct_score; - - printf("Ӣɼ:"); - scanf("%d", &English_score); - e.English_score = English_score; - - printf("ɼ:"); - scanf("%d", &physics_score); - e.physics_score = physics_score; - - printf("λ(1-%d):\n", L.length + 1); - scanf("%d", &i); - - if (listinsert(&L, i, e)) { - printf("ɹ\n"); - } else { - printf("ʧ\n"); - } - printlist(L); - break; - } - - case 2: { - printf("ҵѧѧ:"); - scanf("%s", num); - i = locateelem1(L, num); - if (i != -1) { - Student e; - getelem(L, i, &e); - printf("ҵѧ: ѧ:%s :%s ƽ:%.2f\n", - e.num, e.name, e.average); - } else { - printf("δҵѧΪ%sѧ\n", num); - } - break; - } - - case 3: { - printf("ҵѧ:"); - scanf("%s", name); - i = locateelem2(L, name); - if (i != -1) { - Student e; - getelem(L, i, &e); - printf("ҵѧ: ѧ:%s :%s ƽ:%.2f\n", - e.num, e.name, e.average); - } else { - printf("δҵΪ%sѧ\n", name); - } - break; - } - - case 4: { - printf("ɾѧλ:"); - scanf("%d", &i); - if (deleteelem(&L, i)) { - printf("ɾɹ\n"); - } else { - printf("ɾʧ\n"); - } - printlist(L); - break; - } - - case 5: { - sort_by_average(&L); - printlist(L); - break; - } - - case 6: { - printf("˳ϵͳ\n"); - free(L.data); - return 0; - } - - default: - printf("Чѡ\n"); - } - } - - return 0; -}