user-0 提问: 学生成绩管理系统，请大家指正。

回复:
user: user-0
content: 引用 10 楼 u010165006 的回复:引用 9 楼 ruying1389279 的回复:[quote=引用 7 楼 u010165006 的回复:] 楼主对图形用户界面的管理系统有没有兴趣？初学新手，还没到学到图形呢 可以看下这个，说不定是你以后的选择呢 从C语言的菜单界面管理系统到C++ Builder的图形用户界面，一个简单的电话簿Demo例子 [/quote]好的，谢谢

user: user-1
content: 引用 9 楼 ruying1389279 的回复:引用 7 楼 u010165006 的回复:楼主对图形用户界面的管理系统有没有兴趣？初学新手，还没到学到图形呢 可以看下这个，说不定是你以后的选择呢 从C语言的菜单界面管理系统到C++ Builder的图形用户界面，一个简单的电话簿Demo例子

user: user-0
content: 引用 7 楼 u010165006 的回复:楼主对图形用户界面的管理系统有没有兴趣？初学新手，还没到学到图形呢

user: user-1
content: 楼主对图形用户界面的管理系统有没有兴趣？

user: user-2
content: 以下代码也不算完美，Just for fun，改进几点： 1. 排序中明显重复的代码结构被精简，将来扩展排序方式也很方便，只需增加比较函数即可。 2. 不随便 exit() 调用，尽可能走逻辑退出程序而不是暴力退出，假设在退出程序时有很重要的事情要做呢？ 3. 排序后的显示和直接显示复用同一个函数，一种逻辑就不要重复实现的，万一哪天结构体内容变一下，岂不要改多处？ 4. 输入尝试做了个统一，增加字段时，添加比较容易，即使增加浮点型之类的字段也容易改造。  #include <stdio.h> #include <stdlib.h> #include <string.h>  #define MAX_STUDENTS 51  // Student data structure. typedef struct Student {   char name[20];   int id;   int math;   int chi;   int eng;   int sum;   int avg; } Student;  // Comparing function for Students. typedef bool (* LessFunction)(const Student*, const Student*);  void ClearScreen() {   system("cls"); }  void Pause() {   fflush(stdin);   getchar(); }  // Print a split line. void PrintSplit() {   printf("------------------------------------------------\n"); }  // Reckon the sum score and the average score of one specific student. void ReckonScores(Student* student) {   student->sum = student->math + student->chi + student->eng;   student->avg = student->sum / 3; }  // // 5 functions below are for inputting. // void InputAnyTypeField(const char* filter,                        const char* field_name,                        void* value) {   fflush(stdin);   printf("%s: ", field_name);   if (strcmp(filter, "%s") == 0) {     gets((char*)value);   } else {     scanf(filter, value);   }   fflush(stdin); }  void InputStringField(const char* field_name, char* value) {   InputAnyTypeField("%s", field_name, value); }  void InputIntegerField(const char* field_name, int* value) {   InputAnyTypeField("%d", field_name, value); }  void InputSingleStudent(Student* student) {   InputStringField("Name", student->name);   InputIntegerField("ID", &student->id);   InputIntegerField("Score of Math", &student->math);   InputIntegerField("Score of Chinese", &student->chi);   InputIntegerField("Score of English", &student->eng);   ReckonScores(student);   PrintSplit(); }  int InputAllStudent(Student* student, int max_allowed) {   ClearScreen();   int count = 0;    // Get the legal count.   for (; printf("How many strudents you want to input? "),          scanf("%d", &count),          count > max_allowed || count < 0;        printf("Cannot more than %d students or less than 0.\n", max_allowed));   int count_down = count;    // Input all students' information.   while (count_down--) {     InputSingleStudent(student++);   }   printf("DONE: %d students have been inputted.\n", count);   Pause();   return count; }  // Display all students' informations. void DisplayAllStudents(const Student* student, int count) {   ClearScreen();   printf("ID   | Name                | MAT | CH  | EN  | SUM | AVG\n");   while (count--) {     printf("%04d | %-19s | %3d | %3d | %3d | %3d | %3d\n",            student->id, student->name, student->math, student->chi,            student->eng, student->sum, student->avg);     student++;   }   PrintSplit();   printf("DONE: Display students's informatons.\n");   Pause();   return; }  // // 2 functions below are the comparing functions for sorting. // bool LessBySum(const Student* a, const Student* b) {   return a->sum < b->sum; }  bool LessByAvg(const Student* a, const Student* b) {   return a->avg < b->avg; }  int ShowSortingMenu() {   ClearScreen();   int selection = 0;   for (; printf("Sort by what? SUM(1) AVG(2) Go Back(0): "),          scanf("%d", &selection),          selection < 0 || selection > 2;        printf("Ilegal input!\n"));   return selection; }  void SortAndDisplayAllStudents(LessFunction less_function,                                Student* student,                                int count) {   for (int i = 0; i < count - 1; i++) {     for (int j = i + 1; j < count; j++) {       if ((*less_function)(student + i, student + j)) {         Student temp = student[i];         student[i] = student[j];         student[j] = temp;       }     }   }   DisplayAllStudents(student, count); }  void SortStudents(Student* student, int count) {   int selection = ShowSortingMenu();   if (!selection)     return;   LessFunction less_functions[] = {NULL, &LessBySum, &LessByAvg};   SortAndDisplayAllStudents(less_functions[selection], student, count); }  int ShowMainMenu() {   int selection = 0;   do {     if (selection) {       printf("Ilegal input!\n");       Pause();     }     ClearScreen();     printf("--- Welcome To Students Scores ---\n");     printf("1 - Input students' informations.\n");     printf("2 - Display students' informations.\n");     printf("3 - Sort students' informations.\n");     printf("0 - Exit.\n");     printf("Type your selection: ");     scanf("%d", &selection);   } while (selection < 0 || selection > 3);   return selection; }  int main() {   Student students[MAX_STUDENTS];   int count = 0;    int selection = 0;   while (selection = ShowMainMenu()) {     switch (selection) {       case 1:         count = InputAllStudent(students, MAX_STUDENTS);         break;       case 2:         DisplayAllStudents(students, count);         break;       case 3:         SortStudents(students, count);         break;       default:         break;     };   }    printf("Thank you, bye!\n");   return 0; }

user: user-0
content: 多谢大家的意见。 有个小问题，就是现在我是通过从menu()函数中输入选择，然后返回数值到主函数，然后再从主函数中调用具体的功能函数。 还有没有更好的方法呢？

user: user-3
content: 给你推荐个完美的菜单方式  int  select = 1; do { //输出 printf(); printf(); scanf("%d",&select); switch(select) { case 1: break; .... case n: break; default: //返回 select = 0; } }while(select);    然后就是你这种if else 用的 嵌套太深，影响效率

user: user-4
content: 多路选择尽量用switch

user: user-1
content: 可以把打印菜单语句独立出一个printMenu()函数。

user: user-1
content: 支持

user: user-5
content: 看到了一些小问题 1) menu 函数中打印菜单代码冗余 2) 功能函数和显示函数应该分离, 例如sort, 这个函数应只完成排序, 至于响应菜单3的排序, 应该用新的函数以免混乱