标题:重载输出运算符 求指教
取消只看楼主
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
结帖率:100%
已结贴  问题点数:10 回复次数:2 
重载输出运算符 求指教
程序代码:
#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;
}

这里是类的实现 大家看下
搜索更多相关主题的帖子: english 
2011-09-15 16:38
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
得分:0 
那我 衰了 咋回事?
2011-09-16 16:44
烟雾中的迷茫
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:621
专家分:1069
注 册:2011-2-9
得分:0 

为什么出现这个?
2011-09-16 17:27



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-349983-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.293368 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved