听不懂,瞎猜猜
程序代码:
#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;
}