Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <conio.h>
- using namespace std;
- class Book
- {
- private:
- string b_name;
- int b_sheets;
- public:
- Book()
- {
- b_name = "";
- b_sheets = 0;
- }
- Book(string a, int b)
- {
- b_name = a;
- b_sheets = b;
- }
- string getbname()
- {
- return b_name;
- }
- int getsheets()
- {
- return b_sheets;
- }
- bool operator<(Book &a)
- {
- return b_name < a.b_name;
- }
- bool operator==(Book &a)
- {
- return b_name == a.b_name;
- }
- inline Book operator+(Book &a)
- {
- this->b_sheets += a.b_sheets;
- return *this;
- }
- friend istream& operator>>(istream& in, Book &a)
- {
- in >> a.b_name >> a.b_sheets;
- return in;
- }
- friend ostream& operator<<(ostream& out, Book &a)
- {
- out << a.b_name << " " << a.b_sheets << endl;
- return out;
- }
- };
- class Library
- {
- private:
- string l_name;
- vector<Book>l_v;
- public:
- Library(string f)
- {
- ifstream ifile(f, ios::in);
- if (ifile.is_open())
- {
- ifile >> l_name;
- copy(l_v.begin(), !ifile.eof());
- ifile.close();
- }
- else
- {
- cout << "File couldn't be opened!";
- exit(1);
- }
- }
- Library()
- {
- l_v.resize(NULL);
- }
- string getlname()
- {
- return l_name;
- }
- void setl_name(string a)
- {
- l_name = a;
- }
- vector<Book> get(vector<Book>v)
- {
- vector<Book>temp;
- unique_copy(v.begin(), v.end(), temp.begin());
- return temp;
- }
- int sum(vector<Book>v)
- {
- int broi(0);
- for (auto x : v)
- {
- x++;
- broi++;
- }
- return broi;
- }
- friend istream& operator>>(istream& in, Library &a)
- {
- in >> a.l_name >> a.l_v;
- return in;
- }
- friend ostream& operator<<(ostream& out, Library &a)
- {
- out << a.l_name << endl;
- copy(a.l_v.begin(), a.l_v.end());
- return out;
- }
- };
- int main()
- {
- Library a("neshtosi");
- cout << a;
- cout << a.get(a.l_v);
- cout << a.sum(a.l_v);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement