外包工

学 JAVA 学 OO

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  21 随笔 :: 0 文章 :: 0 评论 :: 0 Trackbacks
問題敘述
   
本次段考過後,X老師希望你設計一個程式能幫他統計同學們的成績。
他希望的功能如下:
1.可以輸入全班的N筆學生資料(1<=N<=50),每位學生有三科分數(國、英、數)。
2.可以統計出每位同學的平均成績
3.可以統計出每科成績的全班平均
4.找出每科成績最好的同學
現在請程式功力高強的你幫忙X老師解決他的問題吧!

--------
條件限制

1.1<=N<=50
2.請提供選單說明供使用者操作
eg.
  ****** Menu ********
  1. Input score.
  2. Print each student's average.
  3. Print the subjects average of the whole class.
  4. Print the Top 1 of each subject.
  5. Exit
  ********************
  your choice=>

--------------
輸入格式

無檔案輸入,由鍵盤輸入資料。

--------------
輸出格式

無檔案輸出,由營幕輸出資料。

---------------
輸入範例

Please input how many students do you have(1<=N<=50):
3

Please input the score one by one(Chinese,English,Math):
50 60 40
60 70 80
90 80 70

----------
輸出範例

Print each student's average:
No. Chinese English Math Average
1 50 60 40 50
2 60 70 80 70
3 90 80 70 80

Print the subjects average of the whole class:
Chinese English Math Average
66.7 70 63.3 66.7

Print the Top 1 of each subject:
Top 1 of Chinese: No. 3,Score 90
Top 1 of English: No. 3,Score 80
Top 1 of Math: No. 2,Score 80


每個人的分數可用二維陣列 int score[50][3] 來儲存
平均成績可儲存在 float avg[50]
科目平均可儲存在 float subject_avg[3]

例:
//先將所有陣列初始值設為0,否則會有不可預期的後果
for(int i=0;i<50;i++)
    for(int j=0;j<3;j++)
       score[i][j]=0;

for(int k=0;k<50;k++)
    avg[k]=0;

for(int l=0;l<3;l++)
   subject_avg[l]=0;

//讀入n筆學生分數
for(int i=0 ; i < n ; i=i+1 )
scanf("%d%d%d", &score[i][0], &score[i][1], &score[i][2]);

//計算每個人的平均
for(int i=0 ; i < n ; i++ )
avg[i]=(score[i][0]+score[i][1]+score[i][2])/3;

//計算科目平均
for(int i=0 ; i < 3 ; i++ ){
   for(for int j=0 ; j< n ; j++)
      subject_avg[i]+=score[i][j];
   subject_avg[i]=subject_avg[i]/n;
}
posted on 2010-10-23 09:50 外包工 阅读(215) 评论(0)  编辑  收藏 所属分类: C语言程式设计

只有注册用户登录后才能发表评论。


网站导航: