Skip to content

Latest commit

 

History

History
56 lines (45 loc) · 1.54 KB

14.8.md

File metadata and controls

56 lines (45 loc) · 1.54 KB

(a) Book

class Book {
  friend bool operator==(const Book &, const Book &);
  friend bool operator!=(const Book &, const Book &);
  friend std::ostream &operator<<(std::ostream &, const Book &);
  friend std::istream &operator>>(std::istream &, Book &);

public:
  Book() : isbn(""), name(""), author(),
      publish_year(0), publisher(""), version(0) {}
  Book(const std::string &i, const std::string &n,
       const std::vector<std::string> &au,
       unsigned y, const std::string &p = "", unsigned v = 1)
      : isbn(i), name(n), author(au),
        publish_year(y), publisher(p), version(v) {}
  Book(std::istream &is) {
    is >> isbn >> name;
    std::string s;
    is >> s;
    author.push_back(s);
    is >> publish_year >> publisher >> version;
  }

private:
  std::string isbn;
  std::string name;
  std::vector<std::string> author;
  unsigned publish_year;
  std::string publisher;
  unsigned version;
};

bool operator==(const Book &, const Book &);
bool operator!=(const Book &, const Book &);
std::ostream &operator<<(std::ostream &, const Book &);
std::istream &operator>>(std::istream &, Book &);

std::ostream &operator<<(std::ostream &os, const Book &rhs) {
  os << rhs.isbn << " " << rhs.name;
  for (const auto &a : rhs.author)
    os << " " << a;
  os << " " << rhs.publish_year << " " << rhs.version << " " << publisher;
  return os;
}

(b) Date

(c) Employee

(d) Vehicle

(e) Object

(f) Tree