您的位置:首页 > 其它

编写一个程序,已有若干学生的数据,包括学号,姓名,成绩,要求输出这些学生的数据并计算出学生人数和平均成绩

2015-06-30 09:48 1526 查看

#include<iostream> 

#include<string> 

using namespace std; 

class  student 



public: 

 void show() 



  cout<<"num="<<num<<endl; 

     cout<<"name="<<name<<endl; 

    cout<<"score="<<score<<endl; 

  } 

 static void show1() 

 { 

   cout<<"the numbers of students:"<<count<<endl; 

  cout<<"the aver score of students:"<<aver<<endl; 

 } 

 student(string num1,string name1,double score1) 

 { 

   num=num1; 

  name=name1; 

 score=score1; 

   count++; 

  sum+=score1; 

  aver=sum/count; 

    } 

private: 

 string num; 

 string name; 

 double score; 

  static double sum; 

 static int count; 

   static double aver; 

}; 

double student::sum=0.0; 

int student::count=0; 

double  student
4000
::aver=0.0; 

int main() 



   student stu1("14","小红",78);       

   stu1.show(); 

   student stu2("24","小蓝",90); 

       stu2.show(); 

    student stu3("25","小敏",85); 

       stu3.show(); 

   student::show1(); 

   return 0; 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: