| 网站首页 | 业界新闻 | 群组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 编程论坛
 大量收QQ微信精准粉/交友粉，非诚勿扰 千里之行 始于足下

已结贴   问题点数：20  回复次数：6

#include<iostream>
using namespace std;
class teacher
{
public:
teacher(char s[10],int a,int b,int c,int d);
private:
char name[10];
int wage;
int fwage;
int bonus;
int total;

};
teacher::teacher(char s[10],int a,int b,int c,int d)
{
strcpy(name,s);
wage=a;
fwage=b;
bonus=c;
d=a+b+c;
total=d;
}
void main()
{

teacher teach[5]={teacher("贾宇",2300,1980,2000,0),teacher("张莹",1908,2000,1000,0),teacher("李蒙",2490,1080,980,0),
teacher("王同辽",980,1200,680,0),teacher("叶库伦",1290,1800,390,0)};
teacher*q=teach;

}
得分:10

#include <iostream>
#include <string>

class teacher
{
public:
teacher( const std::string& name, int wage, int fwage, int bonus );
private:
std::string name_;
int wage_;
int fwage_;
int bonus_;
int total_;

friend bool operator<( const teacher& lhs, const teacher& rhs ) noexcept;
friend std::ostream& operator<<( std::ostream& os, const teacher& t );
};

teacher::teacher( const std::string& name, int wage, int fwage, int bonus )
: name_(name), wage_(wage), fwage_(fwage), bonus_(bonus), total_(wage+fwage+bonus)
{
}

bool operator<( const teacher& lhs, const teacher& rhs ) noexcept
{
return lhs.total_ < rhs.total_;
}

std::ostream& operator<<( std::ostream& os, const teacher& t )
{
return os << '(' << t.name_ << ',' << t.wage_ << ',' << t.fwage_ << ',' << t.bonus_ << ',' << t.total_ << ')';
}

#include <algorithm>
//#include <iterator>
using namespace std;

int main( void )
{
teacher teach[] = { teacher("贾宇",  2300,1980,2000)
, teacher("张莹",  1908,2000,1000)
, teacher("李蒙",  2490,1080, 980)
, teacher("王同辽", 980,1200, 680)
, teacher("叶库伦",1290,1800, 390) };

//copy( begin(teach), end(teach), std::ostream_iterator<teacher>(cout,"\n") );

auto itor = max_element( begin(teach), end(teach) );
cout << *itor << endl;
}

得分:0

friend bool operator<( const teacher& lhs, const teacher& rhs ) noexcept;
friend std::ostream& operator<<( std::ostream& os, const teacher& t );这些是什么函数？望指教

得分:0

bool operator<( const teacher& lhs, const teacher& rhs )

a < b 即调用 operator<(a,b)

std::ostream& operator<<( std::ostream& os, const teacher& t );

得分:10

得分:0

得分:0

• 7
• 1/1页
• 1