簡單的成績錄入系統程序及分析以及思考

      網友投稿 756 2025-04-02

      這是一年前寫的筆記,那個時候還沒有用博客記錄學習的點滴,然后就用word寫了這個文檔。為了防止丟失,以及自己回憶下,就貼出來吧。

      本程序是在教材的基礎之上找到的疑惑部分,程序是基礎教材的思想自己編寫的,關于使用函數模塊來使程序更加的簡潔且便于維護都是自己的對知識的運用實踐,本程序更能體現對指針的理解,對于二維數組指針的使用是一個很好的練習。

      本程序的功能是對以一個班,3個學生,4門課為例進行 實現一系列的基本操作,例如錄入所有學生各科成績、求所有學生總成績的平均值、輸出指定學生的所有科目成績、輸出成績不及格學生的各科成績等,分別運用函數模塊實現,使得程序清晰,利于理解。

      第一種是成績錄入的程序在main主函數中直接完成,第二種是將成績錄入部分用一個函數inputscore來完成,之后在主函數main當中調用此函數。

      第一種程序:

      #include

      int main()

      {

      /* function declaration? */

      void average(float *p,int n);???????????? //n represents the sum of the numble of all subjects

      void search(float (*p)[4],int n);???????? //n represents No.n student

      void search_fail(float (*p)[4],int n);??? //n represents the numble of students

      float score[3][4];

      /* input the scores */

      float (*point)[4]=score;

      int i,j;

      printf("Please input each student's scores\n");

      for(i=0;i<3;i++)

      {

      printf("Please input No.%d student's scores:",i+1);

      for(j=0;j<4;j++)

      {

      scanf("%f",*(point+i)+j);

      }

      printf("\n");

      }

      /* function call part */

      average(*score,12);?????????????????????? //average(score[0],12);

      search(score,2);? ????????????????????????//output the scores of No.2 student

      search_fail(score,3);???????????????????? //output the scores of students who fail to pass the examination

      return 0;

      }

      /* function defenition */

      void average(float *p,int n)

      {

      float *(p_end)=p+n,sum=0,aver;

      for(;p

      sum+=*p;

      aver=sum/n;

      printf("Average=%5.2f\n",aver);

      }

      void search(float (*p)[4],int n)

      {

      int i;

      printf("The scores of No.%d student:\n",n);

      for(i=0;i<4;i++)

      printf("%5.2f ",*(*(p+n-1)+i));

      printf("\n");

      }

      void search_fail(float (*p)[4],int n)

      {

      int i,j,flag;

      for(i=0;i<3;i++)

      {

      flag=0;

      for(j=0;j<4;j++)

      {

      if(*(*(p+i)+j)<60) flag=1;

      }

      if(flag==1)

      {

      printf("No.%d students fails, her/his scores are \n",i+1);

      for(j=0;j<4;j++)

      printf("%5.2f ",*(*(p+i)+j));

      }

      printf("\n");

      }

      }

      第二種程序:

      #include

      int main()

      {

      /* function declaration? */

      void inputscore(float (*p)[4],int n);???? //n represents the numble of students

      void average(float *p,int n);???????????? //n represents the sum of the numble of all subjects

      void search(float (*p)[4],int n);???????? //n represents No.n student

      void search_fail(float (*p)[4],int n);??? //n represents the numble of students

      float score[3][4];

      /* input the scores */

      /* function call part */

      inputscore(score,3);????????????????????? //input the scores of all students

      average(*score,12);?????????????????????? //average(score[0],12);

      search(score,2);????????????????????????? //output the scores of No.2 student

      search_fail(score,3);???????????????????? //output the scores of students who fail to pass the examination

      return 0;

      }

      /* function defenition */

      void inputscore(float (*point)[4],int n)

      {

      int i,j;

      printf("Please input each student's scores\n");

      for(i=0;i

      {

      printf("Please input No.%d student's scores:",i+1);

      for(j=0;j<4;j++)

      {

      scanf("%f",*(point+i)+j);

      }

      簡單的成績錄入系統程序及分析以及思考

      printf("\n");

      }

      }

      void average(float *p,int n)

      {

      float *(p_end)=p+n,sum=0,aver;

      for(;p

      sum+=*p;

      aver=sum/n;

      printf("Average=%5.2f\n",aver);

      }

      void search(float (*p)[4],int n)

      {

      int i;

      printf("The scores of No.%d student:\n",n);

      for(i=0;i<4;i++)

      printf("%5.2f ",*(*(p+n-1)+i));

      printf("\n");

      }

      void search_fail(float (*p)[4],int n)

      {

      int i,j,flag;

      for(i=0;i<3;i++)

      {

      flag=0;

      for(j=0;j<4;j++)

      {

      if(*(*(p+i)+j)<60) flag=1;

      }

      if(flag==1)

      {

      printf("No.%d students fails, her/his scores are \n",i+1);

      for(j=0;j<4;j++)

      printf("%5.2f ",*(*(p+i)+j));

      }

      printf("\n");

      }

      }

      紅色字體部分為有點疑問的地方,為什么紅色部分上下兩條語句不能調換,這個不經意的問題花費了我不少時間,原來的程序是printf在前,int i,j;在后,但程序總是編譯出錯,費了好大功能才改成現在的程序那樣,正常編譯,鏈接,執行。

      其次,定義行指針時,最好是在定義時候就賦值,例如:float? (*p)[4]=score;就是將二維數組的序號為0的行賦值給行指針變量p;當然也可以先定義,等所有定義完成后,在賦值。注意是所有定義部分完成后在賦值,不能定義一條,接著下個語句賦值,其次在定義其他部分,這樣會出現錯誤。例如,下面程序是會在編譯時出現錯誤的:

      #include

      int main()

      {

      /********************************************************************************************************************************

      The aim of the program is to get the average of all stuents'grades, and to output the grades of all subjects of a student, and

      finally to output the grades of the students whoes some grades below 60,that is he or she fails to pass the examination.

      ********************************************************************************************************************************/

      void average(float *p,int n);????????????????? //function declaration, and n represents the numble of all subjects of all students

      void search(float (*p)[4],int n);????????????? //function declaration; output the No.n student's grades, and n represents NO.n

      void search_fail(float (*p)[4],int n);???????? //function declaration; output the student's grades who fails to pass the exam

      float score[3][4];???????????????????????????? //3 students and 4 subjects

      float (*point)[4];

      point=score;

      int i,j;

      printf("please input the student's scores:\n");

      for(i=0;i<3;i++)

      {

      printf("the No.%d student's scores: ",i+1);

      for(j=0;j<4;j++)

      scanf("%f",*(point+i)+j);

      printf("\n");

      }

      average(*score,12);?? ?????????????????????????//function call

      search(score,3);?????????????????????????????? //function call; output the third student's scores of each subject

      search_fail(score,4);????????????????????????? //function call

      return 0;

      }

      void average(float *p,int n)?????????????????????? //function definitation

      {

      float sum=0,aver,*p_end=p+n;

      for(;p

      sum+=*p;

      aver=sum/n;

      printf("average=%5.2f\n",aver);

      }

      void search(float (*p)[4],int n)

      {

      int i;

      printf("the scores of No.%d are\n",n);

      for(i=0;i<4;i++)

      printf("%5.2f ",*(*(p+n-1)+i));

      printf("\n");

      }

      void search_fail(float (*p)[4],int n)

      {

      int i,j,flag;

      for(i=0;i<3;i++)

      {

      flag=0;

      for(j=0;j<4;j++)

      if(*(*(p+i)+j)<60)

      flag=1;

      if(flag==1)

      {

      printf("No.%d fails, his or her scores are\n",i+1);

      for(j=0;j<4;j++)

      printf("%5.2f ",*(*(p+i)+j));

      printf("\n");

      }

      }

      }

      編譯:

      E:\Visual c++\exercise_1\eg-10_input system\workspace_majorization9\project_majorization9\majorization9.c(14) : error C2143: syntax error : missing ';' before 'type'

      錯誤之處就在紅色部分。下面給出正確程序:

      #include

      int main()

      {

      /********************************************************************************************************************************

      The aim of the program is to get the average of all stuents'grades, and to output the grades of all subjects of a student, and

      finally to output the grades of the students whoes some grades below 60,that is he or she fails to pass the examination.

      ********************************************************************************************************************************/

      void average(float *p,int n);????????????????? //function declaration, and n represents the numble of all subjects of all students

      void search(float (*p)[4],int n);????????????? //function declaration; output the No.n student's grades, and n represents NO.n

      void search_fail(float (*p)[4],int n);???????? //function declaration; output the student's grades who fails to pass the exam

      float score[3][4];?????????? ??????????????????//3 students and 4 subjects

      float (*point)[4];

      int i,j;

      point=score;

      printf("please input the student's scores:\n");

      for(i=0;i<3;i++)

      {

      printf("the No.%d student's scores: ",i+1);

      for(j=0;j<4;j++)

      scanf("%f",*(point+i)+j);

      printf("\n");

      }

      average(*score,12);??????????????????????????? //function call

      search(score,3);?????????????????????????????? //function call; output the third student's scores of each subject

      search_fail(score,4);????????????????????????? //function call

      return 0;

      }

      void average(float *p,int n)?????????????????????? //function definitation

      {

      float sum=0,aver,*p_end=p+n;

      for(;p

      sum+=*p;

      aver=sum/n;

      printf("average=%5.2f\n",aver);

      }

      void search(float (*p)[4],int n)

      {

      int i;

      printf("the scores of No.%d are\n",n);

      for(i=0;i<4;i++)

      printf("%5.2f ",*(*(p+n-1)+i));

      printf("\n");

      }

      void search_fail(float (*p)[4],int n)

      {

      int i,j,flag;

      for(i=0;i<3;i++)

      {

      flag=0;

      for(j=0;j<4;j++)

      if(*(*(p+i)+j)<60)

      flag=1;

      if(flag==1)

      {

      printf("No.%d fails, his or her scores are\n",i+1);

      for(j=0;j<4;j++)

      printf("%5.2f ",*(*(p+i)+j));

      printf("\n");

      }

      }

      }

      除此之外,我們可以很容易的發現,第二個程序是第一個的優化,使用函數來完成主函數需要的每一個功能,很整潔,便于閱讀與維護。

      總結:使用文檔以及筆記記錄自己對于程序的理解以及疑惑,并且不斷實踐演練,這是一個不錯的習慣,個人一定會堅持下去。為了下一個目標積蓄力量。目標:編寫一個應用程序以及各行業的管理系統軟件。優化是使其更加的人性化,實用性強。

      數據結構

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:word 如何套用模板(word文檔打字時會消掉后面字)
      下一篇:WPS表格辦公—正確運用模糊查找與精確查找(wps表格模糊篩選)
      相關文章
      亚洲日韩国产精品第一页一区| 亚洲天堂免费在线视频| 国产精一品亚洲二区在线播放| 亚洲电影日韩精品| 在线观看亚洲精品专区| 亚洲AV电影天堂男人的天堂| 亚洲精品日韩一区二区小说| 亚洲精品无码专区在线| 亚洲乱妇熟女爽到高潮的片| 亚洲日韩精品A∨片无码加勒比| 一区二区亚洲精品精华液| 在线观看亚洲AV日韩A∨| 亚洲欧美自偷自拍另类视| 亚洲欧美国产国产一区二区三区| 亚洲中文字幕久久精品蜜桃| 亚洲欧美日韩中文无线码| 亚洲国产高清国产拍精品| 亚洲?v女人的天堂在线观看| 亚洲国产成人久久综合碰| 久久精品亚洲福利| 亚洲AV中文无码乱人伦下载| 亚洲一区二区影院| 亚洲精品在线免费观看视频| 亚洲最大黄色网址| 亚洲无mate20pro麻豆| 亚洲va中文字幕| 亚洲va中文字幕无码| 亚洲色成人网站WWW永久| 亚洲AV无码国产丝袜在线观看 | 亚洲国产精品线在线观看| 97久久精品亚洲中文字幕无码| 亚洲激情黄色小说| 亚洲人成7777| 久久人午夜亚洲精品无码区| 亚洲国产一区二区视频网站| 亚洲午夜未满十八勿入网站2| 亚洲AV午夜成人片| 亚洲国产精品成人久久久| 在线观看亚洲AV日韩AV| 亚洲成AⅤ人影院在线观看| 国产亚洲精品精品国产亚洲综合|