定義一個(gè)類并main()中new一個(gè)對(duì)象測(cè)試實(shí)現(xiàn)之,。
定義一個(gè)類并main()中new一個(gè)對(duì)象測(cè)試實(shí)現(xiàn)之,。
一個(gè)簡(jiǎn)單的學(xué)生成績(jī)管理,就包含你要的內(nèi)容,,供參考:
#include<iostream>#include<string>using namespace std;class Student{public:Student(string id="NULL",double score=0){};static double sum();static double average();string getid();double getscore();void setid(string s);void setscore(double s);void printfstudentinto();private:string id;double score;static double total_score;static double count;};string Student::getid(){return id;}double Student::getscore(){return score;}void Student::printfstudentinto(){cout<<"學(xué)生信息: ";cout<<"id: "<<getid()<<" score: "<<getscore()<<endl;}void Student::setid(string s){id=s;}void Student::setscore(double s){score=s;++count;total_score=total_score+score;}double Student::sum(){return total_score;}double Student::average(){double average=0.0;average=total_score/count;return average;}double Student::total_score=0.0;double Student::count=0.0;int main(){Student stu[10];int n;double s;string id;cout<<"請(qǐng)輸入學(xué)生的·人數(shù)(1~10):";cin>>n;for(int i=0; i<n; i++){cout<<"請(qǐng)輸入第 "<<i+1<<" 位學(xué)生的id,、score: ";cin>>id;cin>>s;stu[i].setid(id);stu[i].setscore(s);}for(int i=0; i<n; i++)stu[i].printfstudentinto( );cout<<"total_score:"<<Student::sum()<<endl;cout<<"average:"<<Student::average()<<endl;return 0;}
相關(guān)推薦
- 美白產(chǎn)品的副作用
- 總感覺(jué)自己是傻子,,辦個(gè)事也辦不明白,,身邊的朋友大多數(shù)都覺(jué)得我腦殘,嘴也笨什么事心里明白嘴說(shuō)不出來(lái),。
- 華為手機(jī)麥芒5戴耳機(jī)怎么還有聲音
- 酸奶蜂蜜面膜的危害
- 一個(gè)朋友在我出丑或者很難堪的時(shí)候叫其他人來(lái)取笑我,我該怎么辦,。
- 紅梅牌120老照相機(jī)還有用嗎?還有用嗎還有用嗎
- 酸奶敷臉多長(zhǎng)時(shí)間洗掉
- 我為什么輕輕被動(dòng)一下就心情不好,,,,,
- 索尼(SONY)FDR-AX40攝影機(jī)怎樣用NFC連接到華為智能手機(jī)上
- 莎芙泰柏是什么牌子