C語言成績分析系統,可以實現七個功能。(使用的編譯器是 code::blocks)

  1. 主要實現對於學生信息的輸入
  2. 顯示輸入學生的信息
  3. 根據期末成績來進行排名。
  4. 查找某個學生的信息
  5. 刪除某個學生的信息
  6. 修改某個學生的信息
  7. 退出程序

七個不同的功能均用自定義函數來進行完成。對於函數的命名要起好對應的名字。以免造成混亂,分不清楚自己寫的函數應該放在哪個位置。

在主函數使用 switch-case語句來實現函數的調用功能。

一些遇到的問題

1、 在codeblocks IDE中中文会出现乱码的情况 

(1) 是字体库不匹配的原因,重新选择字体库可以解决输入中文

(2) 对IDE编辑器进行环境调试。

              点击Other compiler options,在空白处填写:

              -finput-charset=UTF-8

              -fexec-charset=GBK

2、 在进行学号输入时对int和char类型的选择

(1)考虑到学号的长短不一,对于用户而言,选择相对于自由,可以选则无符号整形(学号没有负数的可能),或者时字符型数组来进行存储,则可以解决较长的学号。

(2)在选择方面,在程序中我使用了无符号的整形来储存较长的学号,注意在使用打印printf函数时要用%lld,但是相比较而言,选择字符型数组更好。(可以设置字符型数组char num[50])。 

3、 在需要不同功能的函数块可以使用新的的结构体数组来进行快速的设定,这样可以方便以后的查改。

4、 在定义数组的元素个数时,可以使用宏来定义,方便程序的维护。

  1 /*程序中默认期末成绩=平时分的百分之40+实验成绩的百分之60*/
  2 #include<stdio.h>
  3 #include<stdlib.h>
  4 #include <string.h>
  5 #include<stdbool.h>
  6 #define NUM 100
  7 struct Stu                    //定义学生结构体
  8 {
  9     char name[30];            //姓名
 10     char gender[20];          //性别
 11     long long number;         //学号
 12     double Uscore;            //平时分数
 13     double Escore;            //实验成绩
 14     double Fscore;            //期末成绩
 15 };
 16 
 17 struct Stu Student[100];           //一共可以储存100个学生的信息
 18 
 19 int n;                             //全局变量
 20 int allfuction;
 21 
 22 void Exit()                        //显示退出程序函数(结束)
 23 {
 24     system("cls");
 25     printf("\n\n\n");
 26     printf("\t\t\t****************************************************************\n");
 27     printf("\t\t\t||                                                            ||\n");
 28     printf("\t\t\t||                     Thank you to                           ||\n");
 29     printf("\t\t\t||                   use this programme !                     ||\n");
 30     printf("\t\t\t||                                                            ||\n");
 31     printf("\t\t\t||                                                            ||\n");
 32     printf("\t\t\t****************************************************************\n");
 33 }
 34 
 35 void Menu()                       //菜单
 36 {
 37 
 38     printf("                    *************************Student achievement management system************************\n");
 39     printf("                                        Please select the operation to be performed\n                                        \n");
 40     printf("                                     1 : Enter the information of students you want.\n");
 41     printf("                                     2 : Show all students information.\n");
 42     printf("                                     3 : Sort students information.\n");
 43     printf("                                     4 : Find students information.\n");
 44     printf("                                     5 : Delete students information.\n");
 45     printf("                                     6 : Modify students information\n");
 46     printf("                                     7 : Exit this system.\n");
 47     printf("Please enter your options: \n");
 48     scanf("%d",&allfuction);
 49 }
 50 
 51 int InputStudent()              //学生基本信息输入int组
 52 {
 53     int again;
 54     int i=1;
 55     while(i)
 56     {
 57         system("cls");
 58         printf("--------------Please enter students\' information--------------\n\n\n");     //人机交互
 59         printf("Please enter the score of the number %d student:\n",i);                      //提示用户输入
 60         printf("Please enter student\'s ID:");
 61         scanf("%lld",&Student[i].number);                                                    //结构体的数据输入number
 62         printf("Please enter student\'s name:");
 63         scanf("%s",Student[i].name);                                                         //结构体的数据输入name
 64         printf("Please enter student\'s gender:");
 65         scanf("%s",&Student[i].gender);                                                      //结构体的数据输入gender
 66         printf("Please enter student\'s Semester work:");
 67         scanf("%lf",&Student[i].Uscore);                                                     //结构体的数据输入Uscore
 68         printf("Please enter student\'s Experimental results:");
 69         scanf("%lf",&Student[i].Escore);                                                     //结构体的数据输入Escore
 70         i++;                                                                                 //计数器
 71         n++;
 72         printf("Success!\n");
 73         printf("Continue to decide whether to enter information ? 1.Continue 2.Exit\n");
 74         scanf("%d",&again);                                                                  //让用户决定是否继续输入
 75         if(again == 2)
 76         {
 77             system("cls");                                                                   //清屏结束此次操作
 78             break;
 79         }
 80 
 81     }
 82 }
 83 
 84 void DisplayStudent()                          //显示学生信息
 85 {
 86     int i = 0;                                 //初始化i计数器
 87     int pass = 0;
 88     int n_pass = 0;
 89     double percent=0.0;
 90     double percent1=0.0;
 91         system("cls");                       //清屏实现后续操作
 92     printf("--------------Display students\' information--------------\n\n\n");
 93     printf("ID====name====semester work====Experimental results====Final Examination====\n\n\n");
 94 
 95     for(i = 1;i <= n; i++)
 96     {
 97         Student[i].Fscore = (0.4*Student[i].Uscore) + (0.6*Student[i].Escore);      //期末成绩的计算
 98         printf("Student ID:%lld\nStudent name:%s\nSemester work:%.3lf\nExperimental results:%.3lf\nFinal examination:%.3lf\n\n",
 99                Student[i].number,Student[i].name,Student[i].Uscore,Student[i].Escore,Student[i].Fscore);  //输出学生的成绩信息
100     }
101     if(Student[i].Fscore < 60)
102     {
103         ++n_pass;
104     }
105     else
106     {
107         ++pass;
108     }
109     percent=(double)pass/(double)n;
110     percent1=(double)n_pass/(double)n;
111     printf("%d students pass the assessment. %.3lf%% of the total number of students\n",pass,percent);
112     printf("%d students not pass the assessment. %.3lf%% of the total number of students\n",n_pass,percent1);
113 }
114 
115 void mysort()                       //根据成绩排序名次
116 {
117     struct Stu t;                   //新的结构体
118             system("cls");
119     printf("--------------Ranked according to final examination--------------\n\n\n");
120     for(int i = 1; i < n; i++)
121         for(int j = 1; j < n; j++)
122             if(Student[j].Fscore > Student[j-1].Fscore)       //互换
123             {
124                 t = Student[j];
125                 Student[j] = Student[j-1];
126                 Student[j-1] = t;
127             }
128     for(int i = 1; i <= n; i++)                              //按照成绩的大小来输出具体的信息
129     {
130         Student[i].Fscore = (0.4*Student[i].Uscore) + (0.6*Student[i].Escore);
131         printf("Student ID: %d\n",Student[i].number);
132         printf("Student name: %s\n",Student[i].name);
133         printf("Gender: %s\n",Student[i].gender);
134         printf("Semester work: %.3lf\n",Student[i].Uscore);
135         printf("Experimental results: %.3lf\n",Student[i].Escore);
136         printf("Final examination: %.3lf\n\n",Student[i].Fscore);
137     }
138     printf("\n");
139 }
140 
141 void FindStudent()                           //根据学号查找录入学生的信息
142 {
143     int i=0;                                 //计数器
144     long long ID;                            //定位学号的一个标记
145     system("cls");
146     printf("--------------Search by student\'s ID--------------\n\n\n");
147     printf("Please enter the student\'s ID: ");
148     scanf("%lld",&ID);
149     for(i=1;i<=n;i++)
150     {
151         if(ID==Student[i].number)      //如果输入的学号和存入学生信息的学号相等,进入下面的程序
152         {
153             Student[i].Fscore = (0.4*Student[i].Uscore) + (0.6*Student[i].Escore);
154             printf("Student ID: %lld\n",Student[i].number);
155             printf("Student name: %s\n",Student[i].name);
156             printf("Gender: %s\n",Student[i].gender);
157             printf("Semester work: %.3lf\n",Student[i].Uscore);
158             printf("Experimental results: %.3lf\n",Student[i].Escore);
159             printf("Final examination: %.3lf\n",Student[i].Fscore);
160         }
161     }
162 }
163 
164 void DeleteStudent()              //删除一个学生的信息
165 {
166         long long nums;                 //定义一个学号的标记
167         int i=0;
168         int j=0;
169         int decide;
170         system("cls");
171         printf("\n============Delete information by student\' ID===========\n");
172         printf("Enter the student ID of the student you want to delete: ");
173         scanf("%lld",&nums);
174 
175         for(i=1;i<=n;i++)
176         {
177             if(nums==Student[i].number)            //输入的学号与存入的学号相等进行删除工作
178             {
179              Student[i].Fscore = (0.4*Student[i].Uscore) + (0.6*Student[i].Escore);
180              printf("ID\tname\tSemester work\tExperimental results\tFinal examination\t\n");
181              printf("%lld\t%s\t%.3lf\t%.3lf\t%.3lf\t\n",
182                     Student[i].number,Student[i].name,Student[i].Uscore,Student[i].Escore,Student[i].Fscore);
183 
184              printf("Confirm the deletion !(1.Yes 2.No)\n");
185              scanf("%d",&decide);
186             if(decide==1)                         //输入1则进行删除工作
187             {
188                     for(j=i;j<=n;j++)
189                     {
190                         Student[j].number=Student[j+1].number;
191                         strcpy(Student[j].name,Student[j+1].name);
192                         Student[i].Uscore=Student[i].Uscore;
193                         Student[i].Escore=Student[i].Escore;
194                         Student[i].Fscore=Student[i].Fscore;
195                     }
196                     n--;
197             }
198             if(decide==2)                        //输入2则取消删除工作
199             {
200                 printf("Cancel deletion.");
201             }
202         }
203     }
204 }
205 
206 void ModifyStudent()                             //修改学生的信息
207 {
208     int i=0;
209     long long IDs;
210     system("cls");
211     printf("--------------Please enter the student\'s ID you want to modify--------------\n\n\n");
212     printf("Please enter the student\'s ID you want to modify:");
213     scanf("%lld",&IDs);
214     for(i = 1; i <= n; i++)
215     {
216         if(IDs==Student[i].number)
217         {
218             printf("Please re-enter the student's information.\n");
219             printf("ID: \n");
220             scanf("%lld",&Student[i].number);
221             printf("name: \n");
222             scanf("%s",Student[i].name);
223             printf("Semester work: \n");
224             scanf("%lf",&Student[i].Uscore);
225             printf("Experimental results: \n");
226             scanf("%lf",&Student[i].Escore);
227             printf("Final examination: \n");
228             scanf("%lf",&Student[i].Fscore);
229             printf("Successful modification !\n\n");
230         }
231     }
232 }
233 
234 int main()
235 {
236     while(true)
237     {
238         Menu();                         //显示菜单
239 
240     switch(allfuction)                  //选择swtich来进行菜单的选择
241     {
242         case 1:
243         InputStudent(Student,NUM);        //输入学生信息
244         break;
245 
246         case 2:
247         DisplayStudent(Student,NUM);      //显示学生信息
248         break;
249 
250         case 3:
251         mysort(Student,NUM);              //根据期末成绩排序,并展示及格和不及格的人数
252         break;
253 
254         case 4:
255         FindStudent(Student,NUM);         //查找某个学生的信息
256         break;
257 
258         case 5:
259         DeleteStudent(Student,NUM);       //删除某个学生的信息
260         break;
261 
262         case 6:
263         ModifyStudent(Student,NUM);      //修改某个学生的信息
264         break;
265 
266         case 7:                          //退出整个程序
267         Exit();
268         return 0;
269      }
270     }
271 }

代碼運行結果以及功能展示

  1. 菜單

     

  2. 錄入信息

     

  3. 顯示信息

      

  4. 根據期末成績排名

      

  5. 查找某個學生的信息

      

  6. 刪除某個學生的信息

     

  7. 修改某個學生的信息

      

  8. 退出程序