您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關C語言如何實現學生成績管理系統的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
設計一個學生成績管理系統,實現對學生成績的動態管理,實現對學生成績的輸入,顯示,刪除,查找,插入,最佳,保存,計算,排序等主要功能。
功能要求
1、每一條記錄包括一個學生的學號、姓名、3門課成績、平均成績。
2、輸入功能:可以一次完成若干條記錄的輸入。
3、顯示功能:完成全部學生記錄的顯示。
4、查找功能:完成按姓名查找學生記錄,并顯示。
5、排序功能:按學生平均成績進行排序。
6、插入功能:按平均成績高低插入一條學生記錄
7、刪除功能:如果輸入錯誤,可以刪除學生記錄;
8、退出。
代碼:
#include<stdio.h> #include<stdlib.h> #include<string.h> #define SIZE_NAME 10 #define SIZE_ID 20 int Record = 0; typedef struct { char name[SIZE_NAME]; char id[SIZE_ID]; int a, b, c; int ava; }pInfo; typedef struct node { pInfo people; struct node *next; }linkList; int menu(); int create(linkList *head); int display(linkList *head); int search(linkList *head, char *info); int modify(linkList *head, char *pid); int add2(linkList *head, char *pid); int delt(linkList *head, char *info); int compare(int ava1, int ava2); int sort(linkList *head, int boolean);//1升序 0降序 int main() { linkList head, *p; char info[SIZE_ID]; int temp, chus, i; head.next = NULL; while (1) { switch (menu()) { case 1: create(&head); break; case 2: display(&head); break; case 3: printf("請輸入需要查詢的學號或姓名: "); scanf("%s", info); p = &head; p = p->next; for (i = 0; i < search(&head, info); i++) { p = p->next; } printf("搜索到:\n"); printf("\t\t\t\t學生信息\n"); printf("--------------------------------------------------------------------------------\n"); printf("\t\t學號\t\t姓名\t\t\t平均成績\n"); printf("--------------------------------------------------------------------------------\n"); printf("%20s\t", p->people.id); printf("%10s\t", p->people.name); printf("%20d\n", p->people.ava); break; case 4: printf("請輸入需要修改的學號: "); scanf("%s", info); modify(&head, info); break; case 5: printf("請輸入需要添加的學號: "); scanf("%s", info); add2(&head, info); break; case 6: printf("請輸入需要刪除的學號或姓名: "); scanf("%s", info); delt(&head, info); break; case 7: printf("請輸入1或0:\n\t1:升序\n\t0:降序\n"); scanf("%d", &temp); sort(&head, temp); break; case 8: exit(0); break; default: printf("輸錯了,再來一次\n"); } system("pause"); system("cls"); } system("pause"); return 0; } int menu() { int chus; printf("\t學生信息\n\n"); printf("請輸入(1 -- 8):\n"); printf("\t1.創建學生信息\n"); printf("\t2.顯示學生信息\n"); printf("\t3.查詢學生信息\n"); printf("\t4.修改學生信息\n"); printf("\t5.添加學生信息\n"); printf("\t6.刪除學生信息\n"); printf("\t7.排序學生成績\n"); printf("\t8.退出\n"); scanf("%d", &chus); return chus; } int create(linkList *head) { linkList *s, *p; p = head; printf("請輸入學號 姓名 三科成績,輸入end結束\n"); while (1) { s = (linkList*)malloc(sizeof(linkList)); scanf("%s", s->people.id); if (!strcmp(s->people.id, "end")) { return 0; } scanf("%s", s->people.name); scanf("%d", &s->people.a); scanf("%d", &s->people.b); scanf("%d", &s->people.c); s->people.ava = (s->people.a + s->people.b + s->people.c) / 3; s->next = p->next; p->next = s; p = s; Record++; } return 0; } int display(linkList *head) { int i; linkList *p; p = head; p = p->next; printf("\t\t\t\t學生信息\n"); printf("--------------------------------------------------------------------------------\n"); printf("\t\t學號\t\t姓名\t\t\t平均成績\n"); printf("--------------------------------------------------------------------------------\n"); for (i = 0; i < Record; i++, p = p->next) { printf("%20s\t", p->people.id); printf("%10s\t", p->people.name); printf("%20d\n", p->people.ava); } return 0; } int search(linkList *head, char *info) { int i; linkList *p; p = head; p = p->next; for (i = 0; i < Record; i++, p = p->next) { if ((!strcmp(p->people.id, info)) || (!strcmp(info, p->people.name))) { return i; } } return -1; } int modify(linkList *head, char *pid) { int i; linkList *p; p = head; p = p->next; for (i = 0; i < search(head, pid); i++) { p = p->next; } printf("請輸入新信息:\n"); scanf("%s", p->people.id); scanf("%s", p->people.name); scanf("%d", &p->people.a); scanf("%d", &p->people.b); scanf("%d", &p->people.c); p->people.ava = (p->people.a + p->people.b + p->people.c) / 3; return 0; } int add2(linkList *head, char *pid) { int i; linkList *p, *s; p = head; p = p->next; s = (linkList*)malloc(sizeof(linkList)); while (p->next != NULL) { p = p->next; } printf("請輸入需要添加的姓名和成績:\n"); strcpy(s->people.id, pid); scanf("%s", s->people.name); scanf("%d", &s->people.a); scanf("%d", &s->people.b); scanf("%d", &s->people.c); s->people.ava = (s->people.a + s->people.b + s->people.c) / 3; if (search(head, s->people.id) == -1) { s->next = p->next; p->next = s; Record++; } else { printf("學號重復了\n"); } sort(head, 0); return 0; } int delt(linkList *head, char *info) { int i, n; linkList *p, *s; p = head; n = search(head, info); if (-1 == n) { printf("沒有找到\n"); return 0; } for (i = 0; i < n; i++) { p = p->next; } p->next = p->next->next; Record--; return 0; } int compare(int ava1, int ava2) { if (ava1 < ava2) { return 1; } return 0; } int sort(linkList *head, int boolean) { linkList *p, *pre; pInfo temp; if (boolean) { for (p = head->next; p != NULL; p = p->next) { for (pre = p->next; pre != NULL; pre = pre->next) { if (0 == compare(p->people.ava, pre->people.ava)) { temp = p->people; p->people = pre->people; pre->people = temp; } } } } else { for (p = head->next; p != NULL; p = p->next) { for (pre = p->next; pre != NULL; pre = pre->next) { if (1 == compare(p->people.ava, pre->people.ava)) { temp = p->people; p->people = pre->people; pre->people = temp; } } } } return 0; }
感謝各位的閱讀!關于“C語言如何實現學生成績管理系統”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。