第一次用循环来录入对象stu的数据,感觉很好玩!
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
class Student{
public:
Student(string a,float b)
{
name=a;
score=b;
}
Student()
{}
void account()
{
cout<<"请输入学生的姓名:";
cin>>name;
cout<<"请输入学生的成绩:";
cin>>score;
system("cls");
cout<<"输入的学生:"<<name<<endl;
cout<<" 他的成绩:"<<score<<endl;
++count;
total_score=total_score+score;
}
static float sum()
{
return (total_score);
}
static void average()
{
ave=total_score/count;
cout<<"_____________________________________"<<endl;
cout<<"总人数:"<<count<<endl;
cout<<"总成绩:"<<total_score<<endl;
cout<<"平均成绩:"<<ave<<endl;
cout<<"-------------------------------------"<<endl;
}
private:
string name;
float score;
static float total_score;
static int count;
static float ave;
};
float Student::total_score=0;
int Student::count=0;
float Student::ave=0;
int main()
{
Student stu[10];
for(int i=0;i<10;i++)
{
stu[i].account();
stu[i].average();
}
system("pause");
return 0;
}