#include #include #include using std::cout; using std::endl; using std::string; //using namespace std; class Customer { private: string firstname; string lastname; int id; friend bool operator<(int i, Customer const& c); public: Customer(string first, string last, int ID);//constructor ~Customer(); //destructor string getName(); int getID() const{ return id; }; void SetName(string first, string second); bool operator<(Customer const& c) const; bool operator<(int i) const; }; bool operator<(int i, Customer const& c); Customer::Customer(string first, string last, int ID) { //cout << "Constructing the object with id " << ID << endl; firstname = first; lastname = last; id = ID; } Customer::~Customer() { //cout << "Destructing the object with id " << id << endl; } string Customer::getName() { return firstname + " " + lastname; } void Customer::SetName(string first, string last) { firstname = first; lastname = last; } bool Customer::operator<(Customer const& c) const { return id < c.getID(); } bool Customer::operator<(int i) const { return id < i; } bool operator<(int i, Customer const& c) { return i < c.id; } class Account : public Customer { private: string acctype; public: Account(string first, string last, int ID, string tp) : Customer(first, last, ID), acctype(tp) { cout << "Constructing Bank Account of type " << acctype << endl; } ~Account() { cout << "Distructing Bank Account of type " << acctype << endl; } }; template T max(T const& t1, T const& t2) { return t1 < t2 ? t2 : t1; } int main() { Customer c1("Kate", "Brown", 1); Customer c2("James", "Bond", 2); if (c1 < c2) { cout << "Customer " << c1.getName() << " arrived earlier" << endl; } else { cout << "Customer " << c2.getName() << " arrived earlier" << endl; } if (300 < c1) { cout << "Customer " << c1.getName() << " arrived later than 300th customer" << endl; } else { cout << "Customer " << c1.getName() << " arrived earlier than 300th customer" << endl; } cout << "Customer " << max(c1,c2).getName() << " arrived later" << endl; return 0; }