[YTU]_2626( B 统计程序设计基础课程学生的平均成绩)
題目描述
程序設計基礎課程的學生成績出來了,老師需要統計出學生個數和平均成績。學生信息的輸入如下:
?????????????? 學號(num)???????????????????? 學生姓名(name)??????????? 成績(score)
?????????????? 101???????????????????????????????????????????張三???????????????????????????100
?????????????? 102???????????????????????????????????????????李四?????????????????????????? 89
? ? ? ? ? ? ?? 103???????????????????????????????????????????王五?????????????????????????? 59
在下面的程序段基礎上完成整個設計,統計學生個數和計算學生的平均成績。
注意:
(1)程序中與成績相關的數據都用整型數據,得到的平均成績也用整數表示????
(2)要求用靜態數據成員和靜態成員函數
(3)只提交begin到end部分的代碼
#include <iostream>
using namespace std;
class student
{
? private:
????? int num;??//學號
?? ?? char name[20];???//姓名
????? int score;??//成績
???? static int count;? //記錄對象個數
???? static int sum;??? //記錄總成績
? public:
??? ?student();?//構造函數
??? ?void input() //學生信息輸入
???? {
????? ? cin>>num>>name>>score;
??? ?}
?? int getsum();? //計算總成績
?? static int average(); //獲取成績平均值
?? static int getcount();? //獲取對象個數?
};
//將程序需要的其他成份寫在下面,只提交begin到end部分的代碼
//******************** begin ********************
//********************* end ********************
int main()
{
?? int n;
?? cin>>n;
?? student *p=new student[n];
?? while(n--)
?? {?
????? p->input();
????? p->getsum();
???? ?p++;
?? }???
?? cout<<"student count="<<student::getcount()<<endl;
?? cout<<"average score="<<student::average()<<endl;
?? return 0;
}
輸入
學生個數和學生的信息
輸出
學生個數和平均成績
樣例輸入
3 101 張三 100 102 李四 89 103 王五 59樣例輸出
student count=3 average score=82提示
(1)程序中與成績相關的數據都用整型數據,得到的平均成績也用整數表示????
(2)要求用靜態數據成員和靜態成員函數
(3)只提交begin到end部分的代碼
總結
以上是生活随笔為你收集整理的[YTU]_2626( B 统计程序设计基础课程学生的平均成绩)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [YTU]_2619 (B 友元类-计算
- 下一篇: [YTU]_2639 ( 改错题:类中私