commit b042fc3f1f5f8db79541efc3fbc55d90fbd313f7 Author: 何斐斐奕 <18408000108@stu.hut.edu.cn> Date: Tue Jan 8 16:05:31 2019 +0800 first commit diff --git a/学生成绩管理系统2.cpp b/学生成绩管理系统2.cpp new file mode 100644 index 0000000..4c4add0 --- /dev/null +++ b/学生成绩管理系统2.cpp @@ -0,0 +1,335 @@ +#include +#include +#include +#include + +/*ѧϢṹ*/ +typedef struct Node +{ + char Name[10]; //ѧ + char ID[15]; //ѧѧ + int Score[3]; //ƳɼѧӢݽṹ + float Ave_Sco; + struct Node *next; +}Lnode; + +void Display(); /*ʾ*/ +void getScore(Lnode *&h); /*ɼ¼뺯*/ +void PrintScore(Lnode *h); /*ɼӡ*/ +void ModifyScore(Lnode *h); /*ɼ޸ĺ*/ +void FindInf(Lnode *h); /*Ϣ*/ +void Delete(Lnode *h); /*ɾ*/ +void Quit(Lnode *h); /*˳*/ +void SaveInf(Lnode *h); +void LoadInf(Lnode *h); + +/*ʼ*/ +void InitList(Lnode *&head) +{ + head = (Lnode *)malloc(sizeof(Lnode)); + if (head == NULL) + { + printf("error!"); + exit(1); + } + head->next = NULL; //ʹͷڵָΪ +} + +int main() +{ + Lnode *ScoreList; //ɼѧϢڴ + int Function; + char flag; + int t = 0; + InitList(ScoreList); + LoadInf(ScoreList); + + while (1) + { + Display(); + printf("ѡ "); + scanf("%d", &Function); + switch (Function) + { + case 1: while (1) + { + getScore(ScoreList); + printf("Ƿ Y/N"); + scanf("%s", &flag); + if (flag == 'N' || flag == 'n')break; + } system("cls"); break; + case 2: PrintScore(ScoreList); _getch(); system("cls"); break; + case 3: ModifyScore(ScoreList); system("cls"); break; + case 4: FindInf(ScoreList); _getch(); system("cls"); break; + case 5: Delete(ScoreList); _getch(); system("cls"); break; + case 6: Quit(ScoreList); break; + + default: printf("Error 룺"); + break; + } //switch + } + + return 0; +} + +/*ϵͳʾ*/ +void Display() +{ + printf("\t\t**********************************************\n"); + printf("\t\t*************ӭʹóɼϵͳ*************\n"); + printf("\t\t**********************************************\n"); + printf("\t\t\t\t1¼ɼ\n"); + printf("\t\t\t\t2ӡɼ\n"); + printf("\t\t\t\t3޸ijɼ\n"); + printf("\t\t\t\t4ѧϢ\n"); + printf("\t\t\t\t5ɾѧϢ\n"); + printf("\t\t\t\t6˳ϵͳ\n"); + printf("\n\n\n\n\n\n"); +} + +/*ɼ¼*/ +void getScore(Lnode *&h) +{ + Lnode *p, *q = h; + char name[10], id[15]; + int Math, English, Datastruct; + p = (Lnode *)malloc(sizeof(Lnode)); //ΪѧϢڵ + printf("ѧϢ\n"); + printf(" ѧ ѧ Ӣ ݽṹ\n"); + scanf("%s %s %d %d %d", &name, &id, &Math, &English, &Datastruct); + + for (; q->next != NULL; q = q->next){;} //ƶβڵ + + strcpy(p->Name, name); + strcpy(p->ID, id); + p->Score[0] = Math; + p->Score[1] = English; + p->Score[2] = Datastruct; + p->Ave_Sco = ((float)((p->Score[0] + p->Score[1] + p->Score[2]) - 150)) / 30; + + p->next = NULL; + q->next = p; + q = p; +} + +/*ɼӡ*/ +void PrintScore(Lnode *h) +{ + + Lnode *p = h->next; + printf("%-14s%-8s%-8s%-8s%-8s%-8s\n","", "ѧ", "", "ѧ", "Ӣ", "ݽṹ", "ƽ"); + while (p != NULL) + { + printf("%-14s%-8s%-8d%-8d%-8d%.2f\n", p->ID, p->Name, p->Score[0], p->Score[1], p->Score[2], p->Ave_Sco); + p = p->next; + } +} + +/*ɼ޸*/ +void ModifyScore(Lnode *h) +{ + Lnode *p = h->next; + char name[10], id[15]; + int Math, English, Datastruct; + printf("ѧ"); + scanf("%s", name); + printf("ѧѧţ"); + scanf("%s", id); + + while (p) + { + if (strcmp(p->Name, name)==0 && strcmp(p->ID, id)==0) + { + printf("ǰѧϢ:\n"); + printf("%-14s%-8s%-8s%-8s%-8s\n", "ѧ", "", "ѧ", "Ӣ", "ݽṹ"); + printf("%-14s%-8s%-8d%-8d%-8d\n", p->ID, p->Name, p->Score[0], p->Score[1], p->Score[2]); + printf("ѧɼ"); + scanf("%d", &Math); + printf("Ӣɼ"); + scanf("%d", &English); + printf("ݽṹɼ"); + scanf("%d", &Datastruct); + p->Score[0] = Math; + p->Score[1] = English; + p->Score[2] = Datastruct; + break; + } + else + { + p = p->next; + } + }//whileѭ +} + +/*Ϣ*/ +void FindInf(Lnode *h) +{ + Lnode *p = h->next; + char name[10], id[15]; + printf("ѧ"); + scanf("%s", name); + printf("ѧѧţ"); + scanf("%s", id); + + while (p) + { + if (strcmp(p->Name, name) == 0 && strcmp(p->ID, id) == 0) + { + printf("ǰѧϢ:\n"); + printf("%-14s%-8s%-8s%-8s%-8s\n", "ѧ", "", "ѧ", "Ӣ", "ݽṹ"); + printf("%-14s%-8s%-8d%-8d%-8d\n", p->ID, p->Name, p->Score[0], p->Score[1], p->Score[2]); + break; + } + else + { + p = p->next; + } + }//whileѭ +} + +/*ɾ*/ +void Delete(Lnode *h) +{ + Lnode *p = h, *q; + q = p->next; + char name[10], id[15]; + printf("ѧ"); + scanf("%s", name); + printf("ѧѧţ"); + scanf("%s", id); + + while (q) + { + if (strcmp(q->Name, name) == 0 && strcmp(q->ID, id) == 0) + { + p->next = q->next; + free(q); //ɾpڵ + printf("ɾɹ\n"); + break; + } + else + { + p = p->next; + q = q->next; + } + }//whileѭ +} + +/*˳ϵͳ*/ +void Quit(Lnode *h) +{ + SaveInf(h); //˳ʱϢ + exit(0); +} + +/*ļ*/ +void LoadInf(Lnode *h) +{ + Lnode *p = h; + Lnode *q; //ʱ ڱļжȡϢ + FILE* file = fopen("student.txt", "rb"); + if (!file) + { + printf("ļʧܣ"); + return ; + } + + /* + ʹfeofжļǷΪҪע⣺ + ȡļʱfeofñ־Ϊ-1 + Ҫٶȡһκ󣬲ŻáҪȶһΡ + */ + q = (Lnode *)malloc(sizeof(Lnode)); + fread(q, sizeof(Lnode), 1, file); + while (!feof(file)) //һֱļĩβ + { + p->next = q; + p = q; + q = (Lnode *)malloc(sizeof(Lnode)); + fread(q, sizeof(Lnode), 1, file); + } //whileѭ + + p->next = NULL; + fclose(file); +} + +/*Ϣļ*/ +void SaveInf(Lnode *h) +{ + Lnode *p = h->next; + int flag; + FILE* file = fopen("student.txt", "wb"); + if (!file) + { + printf("ļʧܣ"); + return; + } + while (p != NULL) + { + flag = fwrite(p, sizeof(Lnode), 1, file); //pдļ + if (flag != 1) + { + break; + } + p = p->next; + } + fclose(file); +} + + +/*ɼ¼*/ +void GetScore(Lnode *&h) +{ + Lnode *p, *q = h; + char name[10], id[15]; + int Math, English, Datastruct; + p = (Lnode *)malloc(sizeof(Lnode)); //ΪѧϢڵ + printf("ѧϢ\n"); + printf(" ѧ ѧ Ӣ ݽṹ\n"); + scanf("%s %s %d %d %d", &name, &id, &Math, &English, &Datastruct); + + for (; q->next != NULL; q = q->next){;} //ƶβڵ + // + strcpy(p->Name, name); + strcpy(p->ID, id); + p->Score[0] = Math; + p->Score[1] = English; + p->Score[2] = Datastruct; + p->Ave_Sco = ((float)((p->Score[0] + p->Score[1] + p->Score[2]) - 150)) / 30; +//ʼָһڵ + p->next = NULL; + q->next = p; + q = p; +} + + +/*ļ*/ +void loadInf(Lnode *h) +{ + Lnode *p = h; + Lnode *q; //ʱ ڱļжȡϢ + FILE* file = fopen("student.txt", "rb"); + if (!file) + { + printf("ļʧܣ"); + return ; + } + + /* + ʹfeofжļǷΪҪע⣺ + ȡļʱfeofñ־Ϊ-1 + Ҫٶȡһκ󣬲ŻáҪȶһΡ + */ + q = (Lnode *)malloc(sizeof(Lnode)); + fread(q, sizeof(Lnode), 1, file); + while (!feof(file)) //һֱļĩβ + { + p->next = q; + p = q; + q = (Lnode *)malloc(sizeof(Lnode)); + fread(q, sizeof(Lnode), 1, file); + } //whileѭ + p->next = NULL; + fclose(file); +} + diff --git a/学生成绩管理系统2.exe b/学生成绩管理系统2.exe new file mode 100644 index 0000000..19d614b Binary files /dev/null and b/学生成绩管理系统2.exe differ