#ifndef BOOK_HPP #define BOOK_HPP #include #include /// @brief 表示一本图书的数据模型 class Book { public: /// @brief 默认构造函数 Book() = default; /// @brief 构造一本完整的图书 /// @param title 书名 /// @param author 作者 /// @param isbn ISBN 编号 /// @param borrowed 是否已借出,默认 false Book(std::string title, std::string author, std::string isbn, bool borrowed = false); /// @brief 获取书名 /// @return 书名常量引用 [[nodiscard]] const std::string& getTitle() const noexcept; /// @brief 获取作者 /// @return 作者常量引用 [[nodiscard]] const std::string& getAuthor() const noexcept; /// @brief 获取 ISBN /// @return ISBN 常量引用 [[nodiscard]] const std::string& getIsbn() const noexcept; /// @brief 判断是否已借出 /// @return true 表示已借出 [[nodiscard]] bool isBorrowed() const noexcept; /// @brief 设置借出状态 /// @param borrowed true 表示已借出 void setBorrowed(bool borrowed) noexcept; /// @brief 重载 ==,比较 ISBN 是否相同 /// @param rhs 另一本图书 /// @return true 当 ISBN 相同 bool operator==(const Book& rhs) const; /// @brief 输出图书信息到流 /// @param os 输出流 /// @param b 图书对象 /// @return 输出流引用 friend std::ostream& operator<<(std::ostream& os, const Book& b); private: std::string title_; std::string author_; std::string isbn_; bool borrowed_ = false; }; #endif // BOOK_HPP