Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication9.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <iterator>
- #include <algorithm>
- using namespace std;
- class Book {
- private:
- string name;
- string description;
- public:
- /*! Constructors */
- Book() : name(string()), description(string()) {};
- Book(string name, string description) : name(name), description(description) {};
- /*! Destructor */
- virtual ~Book() {};
- /*! Get */
- auto getName() {
- return this->name;
- }
- auto getDescription() {
- return this->description;
- }
- /*! Set */
- auto setName(string name) {
- this->name = name;
- }
- auto setDescription(string description) {
- this->description = description;
- }
- /*! Operators */
- friend istream& operator>>(istream& input, Book& obj) {
- input >> obj.name >> obj.description;
- return input;
- }
- friend ostream& operator<<(ostream& output, const Book& obj) {
- output << "Name: " << obj.name << endl;
- output << "Description: " << obj.description << endl << endl;
- return output;
- }
- };
- class Library {
- private:
- string title;
- vector<Book> books;
- public:
- /*! Constructors */
- Library() : books(vector<Book>()) {};
- Library(const string path) {
- fstream file(path);
- file >> this->title;
- copy(istream_iterator<Book>(file), istream_iterator<Book>(), back_inserter(this->books));
- }
- Library(const Library& obj) : title(obj.title), books(obj.books) {};
- /*! Destructor */
- virtual ~Library() {};
- /*! Get */
- auto getBooks() {
- return this->books;
- }
- auto getTitle() {
- return this->title;
- }
- /*! Operators */
- friend istream& operator>>(istream& input, Library& obj) {
- input >> obj.title;
- copy(istream_iterator<Book>(input), istream_iterator<Book>(), back_inserter(obj.books));
- return input;
- }
- friend ostream& operator<<(ostream& output, const Library& obj) {
- output << "Title: " << obj.title << endl << endl;
- for (auto book : obj.books) {
- output << book;
- }
- return output;
- }
- };
- /*! Program Entry Point */
- int main()
- {
- /*!
- *
- * File contents
- *
- * Example
- * Book1 Description
- * Book2 Test
- *
- */
- Library test("test.txt");
- cout << test;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement