Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class HighScoreEntry {
- std::string name;
- int score;
- public:
- HighScoreEntry();
- HighScoreEntry( std::string n, int s);
- int getScore();
- std::string getName();
- virtual ~HighScoreEntry();
- bool operator<(const HighScoreEntry& other) const
- {
- // code that determines ordering goes here
- return score < other.score;
- }
- /* std::ostream& operator<<(std::ostream& os, const HighScoreEntry& obj)
- {
- os << obj.score;
- return os;
- }*/
- std::ostream& operator<< ( std::ostream& stm, const HighScoreEntry& stu )
- {
- stm << stu.name << '\n' // name on line 1
- << stu.score<< '\n' ; // line 2
- /*
- stm << stu.scores.size() << '\n' ; // #scores on line 3
- for( double s : stu.scores ) stm << s << ' ' ; // scores on line 4
- stm << '\n' ;
- stm << stu.assignments.size() << '\n' ; // #assignments on the next lime
- for( const std::string& s : stu.assignments ) stm << s << '\n' ; // one assignment per line
- */
- return stm ;
- }
- // read student object from a stream
- std::istream& operator>> ( std::istream& stm, HighScoreEntry& stu )
- {
- // skip leading empty lines, read name from non-empty line 1
- while( std::getline( stm, stu.name ) && stu.name.empty() ) ;
- stm >> stu.score ; // line 2
- if( !stm ) stu = {} ; // input failed; clear everything
- return stm ;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement