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