Advertisement
Guest User

Untitled

a guest
Jan 25th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. class HighScoreEntry {
  2. std::string name;
  3. int score;
  4.  
  5. public:
  6. HighScoreEntry();
  7. HighScoreEntry( std::string n, int s);
  8. int getScore();
  9. std::string getName();
  10. virtual ~HighScoreEntry();
  11. bool operator<(const HighScoreEntry& other) const
  12. {
  13. // code that determines ordering goes here
  14. return score < other.score;
  15. }
  16. /* std::ostream& operator<<(std::ostream& os, const HighScoreEntry& obj)
  17. {
  18. os << obj.score;
  19. return os;
  20. }*/
  21. std::ostream& operator<< ( std::ostream& stm, const HighScoreEntry& stu )
  22. {
  23. stm << stu.name << '\n' // name on line 1
  24. << stu.score<< '\n' ; // line 2
  25. /*
  26. stm << stu.scores.size() << '\n' ; // #scores on line 3
  27. for( double s : stu.scores ) stm << s << ' ' ; // scores on line 4
  28. stm << '\n' ;
  29.  
  30. stm << stu.assignments.size() << '\n' ; // #assignments on the next lime
  31. for( const std::string& s : stu.assignments ) stm << s << '\n' ; // one assignment per line
  32. */
  33. return stm ;
  34. }
  35.  
  36. // read student object from a stream
  37. std::istream& operator>> ( std::istream& stm, HighScoreEntry& stu )
  38. {
  39. // skip leading empty lines, read name from non-empty line 1
  40. while( std::getline( stm, stu.name ) && stu.name.empty() ) ;
  41. stm >> stu.score ; // line 2
  42.  
  43. if( !stm ) stu = {} ; // input failed; clear everything
  44.  
  45. return stm ;
  46. }
  47.  
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement