fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Movie {
  6. public:
  7. Movie(string movieTitle);
  8. void SetVotes(int numUpVotes, int numDownVotes) {
  9. upVotes = numUpVotes;
  10. downVotes = numDownVotes;
  11. }
  12. string GetTitle() const { return title; }
  13. int GetVoteDifference() const { return upVotes - downVotes; }
  14.  
  15. private:
  16. string title;
  17. int upVotes;
  18. int downVotes;
  19. };
  20.  
  21. Movie::Movie(string movieTitle) {
  22. title = movieTitle;
  23. upVotes = 0;
  24. downVotes = 0;
  25. }
  26.  
  27. bool operator<(const Movie& movie1, const Movie& movie2) {
  28. return movie1.GetVoteDifference() < movie2.GetVoteDifference();
  29. }
  30.  
  31. int main() {
  32. Movie movie1("Frozen");
  33. Movie movie2("Drive");
  34.  
  35. movie1.SetVotes(9, 6);
  36. movie2.SetVotes(13, 5);
  37.  
  38. if (movie1 < movie2) {
  39. cout << movie1.GetTitle() << " is worse." << endl;
  40. }
  41. else if (movie2 < movie1) {
  42. cout << movie2.GetTitle() << " is worse." << endl;
  43. }
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Frozen is worse.