简单的学生成绩管理系统001版。求意见。
程序代码:
/* */ // 首部声明 /* */ // 头文件&宏定义 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <malloc.h> #include <windows.h> #include <time.h> #define LEN sizeof(StuInfo) /* */ // 结构体 typedef struct StuInfo { int order; // 序号 char stu_id[16]; // 学号 char name[16]; // 姓名 char sex[4]; // 性别 float score[3]; // 数学成绩 英语成绩 c语言成绩 float ave; // 学生平均成绩 float sum; // 总成绩 struct StuInfo *next; }StuInfo; /* */ // 模块声明 void menu(); StuInfo *input(); void output(StuInfo *); void search(StuInfo *); StuInfo *del(StuInfo *); StuInfo *modify(StuInfo *); StuInfo *order_sort(StuInfo *); void quit(); /* */ // 主函数 int main(void) { int i, select; char password[12]; StuInfo *head = NULL; printf("************************************************************\n"); printf("**********************欢迎进入学生成绩管理系统**************\n"); printf("************************************************************\n"); for(i = 1; i < 5; i++) { printf("\n请输入密码:"); gets(password); if (strcmp(password, "1") == 0) { while(1) { menu(); // 进入主界面 printf("请选择:"); do{ scanf("%d", &select); }while (select < 1 || select > 7); switch (select) { case 1: head = input(); break; case 2: output(head); break; case 3: search(head); break; case 4: head = del(head); break; case 5: head = modify(head); break; case 6: head = order_sort(head); break; case 7: quit(); break; } system("pause"); system("cls"); } } else { printf("密码错误请第%d次输入:", i + 1); gets(password); } } if (5 == i) { printf("密码验证失败!\n"); exit(0); } return 0; } void menu() { printf("********************************\n"); printf("********欢迎进入主菜单**********\n"); printf("********************************\n"); printf("\n本系统有如下功能:\n"); printf("1. 学生信息录入\n"); printf("2. 学生信息输出\n"); printf("3. 学生信息查询\n"); printf("4. 学生信息删除\n"); printf("5. 学生信息修改\n"); printf("6. 学生信息排序\n"); printf("7. 退出系统\n"); printf("\n"); } StuInfo *input() { StuInfo *head = NULL, *p; int i, flag = 1; float s = 0; system("cls"); while (1) { p = (StuInfo *)malloc(LEN); printf("\n请输入学生的序号:"); scanf("%d", &p -> order); if (p -> order <= 0) break; printf("\n请输入学生的学号:"); scanf("%s", p -> stu_id); printf("\n请输入学生的姓名:"); scanf("%s", p -> name); printf("\n请输入学生的性别:"); scanf("%s", p -> sex); printf("\n请输入3门课的成绩:"); for (i = 1; i <= 3; i++) { switch (i) { case 1: printf("\n请输入数学成绩:"); break; case 2: printf("\n请输入英语成绩:"); break; case 3: printf("\n请输入c语言成绩:"); break; } scanf("%f", &p -> score[i - 1]); while (p ->score[i - 1] < 0 || p -> score[i - 1] > 100) { printf("\n错误的输入,请重新输入:"); scanf("%f", &p -> score[i - 1]); } } for (i = 1; i <= 3; i++) s += p -> score[i]; p -> sum = s; p -> ave = s / 3; p -> next = head; head = p; } return (head); } void output(StuInfo *head) { StuInfo * p; int count = 0; // 统计学生数 p = head; if (p == NULL) printf("这是个空表,没有任何学生信息!\n"); else { printf("**********************学生信息***************************************\n"); printf("序号\t学号\t姓名\t性别\t数学\t英语\tc语言\n"); printf("-----------------------------------------------------------------\n"); while (p != NULL) { printf("%d\t%s\t%s\t%s\t%.2f\t%.2f\t%.2f\n", p -> order, p -> stu_id, p -> name, p -> sex, p -> score[0], p -> score[1], p -> score[2]); p = p -> next; count++; } printf("************************共有%d个学生信息**************************\n", count); printf("**************************** 结束 ********************************\n"); } } void search(StuInfo *head) { StuInfo *p; int count = 0; char subname[16]; // 存放姓名 system("cls"); printf("请输入你要查找的姓名:"); scanf("%s", subname); p = head; //头指针赋予移到指针 printf("序号\t学号\t姓名\t性别\t数学\t英语\tc语言\n"); printf("--------------------------------------------------------------------\n"); while (p != NULL) { if (strcmp(p -> name, subname) == 0) { count++; printf("%d\t%s\t%s\t%s\t%.2f\t%.2f\t%.2f\n", p -> order, p -> stu_id, p -> name, p -> sex, p -> score[0], p -> score[1], p -> score[2]); } p = p -> next; } printf("\n********找到%d个****************************************************\n", count); if (count == 0) printf("没有这个名字的学生信息!\n"); } StuInfo *del(StuInfo *head) { StuInfo *p, *q; int count = 0; char subname[16]; // 存放姓名 system("cls"); printf("请输入你要删除的学生姓名:"); scanf("%s", subname); if (head == NULL) { printf("这是个空表,没有任何学生信息!\n"); return(NULL); } if (strcmp(head -> name, subname) == 0) { head = head -> next; count++; } else { q = p = head; p = p -> next; while (p != NULL) { if (strcmp(p -> name, subname) == 0) { q -> next = p -> next; p = q -> next; count++; } else { q = p; p = p -> next; } } } if (count == 0) printf("没有这个名字的学生信息!\n"); else printf("\n********删除了%d个学生信息*******************************************\n", count); return head; } StuInfo *modify(StuInfo *head) { StuInfo *p, *q; int suborder; // 需要修改的序号 int i; float s; if (head == NULL) { printf("这是个空表,没有任何学生信息!\n"); return(NULL); } system("cls"); printf("请输入你要修改的学生序号: "); scanf("%d", &suborder); p = q = head; while (p != NULL) { if (p -> order == suborder) { printf("\n请重新输入学生的学号:"); scanf("%s", p -> stu_id); printf("\n请重新输入学生的姓名:"); scanf("%s", p -> name); printf("\n请重新输入学生的性别:"); scanf("%s", p -> sex); printf("\n请重新输入3门课的成绩:"); for (i = 1; i <= 3; i++) { switch (i) { case 1: printf("\n请输入数学成绩:"); break; case 2: printf("\n请输入英语成绩:"); break; case 3: printf("\n请输入c语言成绩:"); break; } scanf("%f", &p -> score[i - 1]); while (p ->score[i - 1] < 0 || p -> score[i - 1] > 100) { printf("\n错误的输入,请重新输入:"); scanf("%f", &p -> score[i - 1]); } } for (i = 1; i <= 3; i++) s += p -> score[i]; p -> sum = s; p -> ave = s / 3; } p = p -> next; } return head; } StuInfo *order_sort(StuInfo *head) { StuInfo *p, *q, *r, *s; StuInfo first, tail; int select; if (head == NULL) { printf("这是个空表,没有任何学生信息!\n"); return NULL; } printf("\n升序输入1\t降序输入2.\n请输入:"); scanf("%d", &select); if (select == 1) { first.next = head; p = &first; while (p -> next != NULL) { p = p -> next; } p -> next = &tail; p = &tail; while (p != first.next) { q = &first; r = q -> next; s = r -> next; while (s != p) { if ((r -> order) > (s -> order)) { r -> next = s -> next; s -> next = r; q -> next = s; q = s; s = r -> next; } else { q = r; r = s; s = s -> next; } } p = r; } while (p -> next != &tail) p = p -> next; p -> next = NULL; } if (select == 2) { first.next = head; p = &first; while (p -> next != NULL) { p = p -> next; } p -> next = &tail; p = &tail; while (p != first.next) { q = &first; r = q -> next; s = r -> next; while (s != p) { if ((r -> order) < (s -> order)) { r -> next = s -> next; s -> next = r; q -> next = s; q = s; s = r -> next; } else { q = r; r = s; s = s -> next; } } p = r; } while (p -> next != &tail) p = p -> next; p -> next = NULL; } return first.next; } void quit(void) { exit(0); }
[ 本帖最后由 有容就大 于 2012-3-5 20:48 编辑 ]