日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[YTU]_2641 9 填空题:静态成员---计算学生个数)

發布時間:2025/4/16 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [YTU]_2641 9 填空题:静态成员---计算学生个数) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目描述

學生類聲明已經給出,在主程序中根據輸入信息輸出實際建立的學生對象個數,以及所有學生對象的成績總和。

?

在下面的程序段基礎上完成設計,只提交beginend部分的代碼

#include <iostream>

#include <string>

using namespace std;

?

class student

{?

private:

??????stringname; ?//學生姓名

??????intage; ? ? ?//學生年齡

??????intscore; ? ?//學生成績

? ? ? ?static intcount; //記錄學生對象個數

??????staticint sum; ?//記錄所有學生的總成績

public:

??????student(stringn,int a,int s); ?//構造函數

??????staticint get_count(); ?//靜態成員函數,獲取count的值

??????staticint get_sum(); ? //靜態成員函數,獲取sum的值

};

?

?

?

?

//將程序需要的成份寫下來,只提交beginend部分的代碼

//******************** begin********************

int student::count=0;

_____(1)_______;

?

________(2)___________

{

? ? ?name=n;

???????age=a;

???????score=s;

???????count++;

???????sum+=s;

}

?

int student::get_count()

{

? ? ______(3)_______;

}

?

int student::get_sum()

{

? ? ______(4)______;

}

?

?

?

//********************* end********************

?

?

int ?main( )

{

? string name;

? int age;

? int score;

? int n;

? cin>>n; ?//輸入學生對象個數

? while(n--)

? {

? ? ? ??cin>>name>>age>>score;

???????new student(name,age,score);

? }

? cout<<"the count ofstudent objects=";

?cout<<student::get_count()<<endl;

? cout<<"the sum of allstudents score=";

?cout<<student::get_sum()<<endl;

? return 0;

}

?

?

輸入

學生個數

對應學生個數的學生信息(姓名 ? ?年齡 ? ?成績)

?

輸出

學生個數

所有學生的成績之和

?

樣例輸入

3

guo?34?98

zhang???56?60

li??23??87

樣例輸出

the count of student objects=3

the sum of all students score=245

提示

?

只提交beginend部分的代碼

#include <iostream> #include <string> using namespace std;class student { private:string name; //學生姓名int age; //學生年齡int score; //學生成績static int count; //記錄學生對象個數static int sum; //記錄所有學生的總成績 public:student(string n,int a,int s); //構造函數static int get_count(); //靜態成員函數,獲取count的值static int get_sum(); //靜態成員函數,獲取sum的值 };int student::count=0; int student::sum=0; student::student(string n,int a,int s) {name=n;age=a;score=s;count++;sum+=s; } int student::get_count() {return count; } int student::get_sum() {return sum; } int main() {string name;int age;int score;int n;cin>>n; //輸入學生對象個數while(n--){cin>>name>>age>>score;new student(name,age,score);}cout<<"the count of student objects=";cout<<student::get_count()<<endl;cout<<"the sum of all students score=";cout<<student::get_sum()<<endl;return 0; }

總結

以上是生活随笔為你收集整理的[YTU]_2641 9 填空题:静态成员---计算学生个数)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。