#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(){num=0;name=”NULL”;Chinese=0;English=0;maths=0;}
Student(int n,string na,double c,double e,double m){num=n;name=na;Chinese=c;English=e;maths=0;}
int get_num()const{return num;}
string get_name()const{return name;}
double get_Chinese()const{return Chinese;}
double get_English()const{return English;}
double get_maths()const{return maths;}
void set_num(int n){num=n;}
void set_name(string na){name=na;}
void set_Chinese(double c){Chinese=c;}
void set_English(double e){English=e;}
void set_maths(double m){maths=m;}
friend ostream& operator <<(ostream &output,Student &s);
friend istream& operator >>(istream &input,Student &s);
private:
int num;
string name;
double Chinese;
double English;
double maths;
};
ostream& operator<<(ostream &output,Student &s)
{
output<<s.get_num()<<”,”<<s.get_name()<<”,”<<s.get_Chinese()<<”,”<<s.get_English()<<”,”<<s.get_maths()<<endl;;
return output;
}
istream& operator>>(istream &input,Student &s)
{
int n;
string na;
double c,e,m;
cin>>n>>na>>c>>e>>m;
s.set_num(n);
s.set_name(na);
s.set_Chinese(c);
s.set_English(e);
s.set_maths(m);
return input;
}
int main()
{
Student s[100];
cout<<”请输入你需要新建多少个学生:”<>n;
for(int i=0;i>s[i];
}
for(int i=0;i<n;i++)
{
cout<<”第一个学生的学号、姓名、语文成绩、英语成绩、数学成绩分别为:”<<endl;
cout<<s[i];
}
system(“pause”);
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/44be00d2f264a5d3701df0af9b98081d.png)