重载输出运算符 求指教
程序代码:#include<iostream>
#include"student.h"
using namespace std;
CStudent::CStudent()
{
strName="General Student";
chinese=0;
math=0;
english=0;
}
CStudent::CStudent(std::string Name,double c,double m,double e)
{
strName=Name;
chinese=c;
math=m;
english=e;
}
CStudent CStudent::operator +(CStudent S)
{
CStudent temp;
temp.strName="Total Performance";
temp.chinese=this->chinese+S.chinese;
temp.math=this->math+S.english;
temp.english=this->english+S.english;
return temp;
}
ostream& operator <<(ostream& out,CStudent& S)
{
out<<S.strName<<"("<<S.chinese<<" , "<<S.math<<" , "<<S.english<<")"<<endl;
return out;
}
void CStudent::SetChinese(double a)
{
chinese=a;
}
void CStudent::SetMath(double a)
{
math=a;
}
void CStudent::SetEnglish(double a)
{
english=a;
}
double CStudent::returnChinese()
{
return chinese;
}
double CStudent::returnMath()
{
return math;
}
double CStudent::returnEnglish()
{
return english;
}
double CStudent::returnTotalPerformance()
{
return chinese+math+english;
}
double CStudent::returnAverage()
{
return (chinese+math+english)/3;
}
string CStudent::returnName()
{
return strName;
}
这里是类的实现 大家看下



