第四章实验4

来源:互联网 发布:逻辑 知乎 编辑:程序博客网 时间:2024/05/20 13:18
#include<iostream> using namespace std; class Student { public: float score; static float total_score; static double count; void account(float s) { score=s; ++count; total_score+=score; };  static float sum()  {  return total_score; };static float average() { return(total_score/count);};float Student::total_score=0.0; double Student::count=0;int main(){Student stu[4]; stu[1].account (80);stu[2].account (90);  stu[3].account (69);  stu[4].account (82);  cout<<"学生总成绩:"<<Student::sum()<<endl; cout<<"学生平均成绩:"<<Student::average()<<endl; return 0;}

0 0