fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Passenger
  6. {
  7. public:
  8. Passenger(string, string, string);
  9. ~Passenger() {}
  10. bool operator==(const Passenger&) const;
  11. bool operator<(const Passenger&) const;
  12. /* void read_from_file(list<Passenger>&, string);
  13.   void insert(list<Passenger>&, string, string, string);
  14.   void remove(list<Passenger>&, string, string, string);
  15.   bool check_reservation(list<Passenger>&, string, string);
  16.   void display_list(list<Passenger>&);
  17.   void save_to_file(list<Passenger>&, string, string, string);
  18. */
  19. private:
  20. string fname;
  21. string lname;
  22. string destination;
  23. };
  24.  
  25. Passenger::Passenger(string first, string last, string dest)
  26. {
  27. fname = first;
  28. lname = last;
  29. destination = dest;
  30. }
  31.  
  32. bool Passenger::operator==(const Passenger& p) const
  33. {
  34. return fname==p.fname && lname==p.lname;
  35. }
  36.  
  37. bool Passenger::operator<(const Passenger& p) const
  38. {
  39. return fname<p.fname || (fname==p.fname && lname<p.lname);
  40. }
  41.  
  42. int main() {
  43. Passenger p1("Laure","Martin","Stockholm"),
  44. p2("Laure","Martin","New York"),
  45. p3("Laure","Schmidt","Copenhagen"),
  46. p4("Christine","Dufour","Paris");
  47.  
  48. if (p1==p2) cout <<"Equal works when equal"<<endl;
  49. else cout <<"Problem with equality 1"<<endl;
  50.  
  51. if (p1==p3) cout <<"Problem with equlity 2"<<endl;
  52. else cout <<"Equal works when partially different"<<endl;
  53.  
  54. if (p1==p4) cout <<"Problem with equlity 4"<<endl;
  55. else cout <<"Equal works when different"<<endl;
  56.  
  57. if (p1<p3) cout <<"LowerThan works when partially lower than"<<endl;
  58. else cout <<"Problem with lower than 1"<<endl;
  59.  
  60. if (p3<p1) cout <<"Problem with lower than 1b"<<endl;
  61. else cout <<"LowerThan works when partially bigger"<<endl;
  62.  
  63. if (p1<p2) cout <<"Problem with lower than 2"<<endl;
  64. else cout <<"LowerTHan works when equal"<<endl;
  65.  
  66. if (p1<p4) cout <<"Problem with lower than 3"<<endl;
  67. else cout <<"LowerTHan works when bigger"<<endl;
  68.  
  69. if (p4<p1) cout <<"LowerTHan works when lower"<<endl;
  70. else cout <<"Problem with lower than 4"<<endl;
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Equal works when equal
Equal works when partially different
Equal works when different
LowerThan works when partially lower than
LowerThan works when partially bigger
LowerTHan works when equal
LowerTHan works when bigger
LowerTHan works when lower