![]() |
#2
rjsp2017-12-29 08:37
听不懂,瞎猜猜
![]() #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; } |
#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;
}