作业4.21

来源:互联网 发布:长春java培训哪家好 编辑:程序博客网 时间:2024/05/16 17:00
编写一个程序,已有若干学生数据,包括学号,姓名,成绩,要求输出这些学生的数据并计算出学生人数和平均成绩。
#include<iostream>#include<string>using namespace std;class  student{public:student(int num1,string name1,double score1){num=num1;name=name1;score=score1;        count++;sum+=score1;aver=sum/count;}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;}private:int 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::aver=0.0;int main(){student stu1(01,"wubeiren",98);stu1.show();student stu2(02,"lianjingxing",100);stu2.show();student stu3(03,"lvyingchuang",88);stu3.show();student::show1();return 0;}

0 0
原创粉丝点击