#ifndef FILEREADER_H #define FILEREADER_H #include #include #include class FileReader { public: // Default constructor (doesn't do anything special) FileReader() {} //---------------------------------------------------------------------------------- // You implement these two // This version simply creates a set with all words in the file - it doesn't // select only the top N and doesn't use an exclusion list. (It's used to // read in the exclusion list.) FileReader(const std::string & filename); // This version creates a set with the top_num most frequently occcuring words // from the file, ignoring all words in the excluded FileReader's set FileReader(unsigned int top_num, const std::string filename, const FileReader &excluded); //---------------------------------------------------------------------------------- // These are implemented already bool contains(const std::string &word) const { return word_set.find(word) != word_set.end(); } // set difference FileReader operator-(const FileReader & other) const { FileReader result; std::set_difference(word_set.begin(), word_set.end(), other.word_set.begin(), other.word_set.end(), std::insert_iterator>(result.word_set, result.word_set.begin())); return result; } // set intersection FileReader operator^(const FileReader & other) const { FileReader result; std::set_intersection(word_set.begin(), word_set.end(), other.word_set.begin(), other.word_set.end(), std::insert_iterator>(result.word_set, result.word_set.begin())); return result; } const std::set& set() { return word_set; } private: std::set word_set; }; #endif // FILEREADER_H