Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #include <iostream>
 - #include <list>
 - #include <vector>
 - #include <string>
 - #include <random>
 - #include <ctime>
 - using namespace std;
 - using _ptr = bool(*)(const char&);
 - class Book
 - {
 - private:
 - string first_name_a;
 - string second_name_a;
 - string titel;
 - string publisher;
 - int count;
 - int year;
 - int paper;
 - int electronic;
 - int audio;
 - string names [5] = {"Alice", "Bob", "Carla", "David", "Eva" };
 - string surnames[5] = { "Smith", "Johnson", "Brown", "Davis", "Wilson" };
 - string publishers[5] = { "Penguin Random House", "HarperCollins", "Simon & Schuster", "Macmillan Publishers", "Hachette Livre" };
 - string books[5] = { "To Kill a Mockingbird", "1984", "The Great Gatsby", "Pride and Prejudice", "The Catcher in the Rye" };
 - public:
 - Book(string const& f = " ", string const& s = " ", string const& t = " ",
 - string const& p = " ", int c = 0, int y = 0, int ta = 0, int tp = 0, int te = 0)
 - {
 - first_name_a = f;
 - second_name_a = s;
 - titel = t;
 - publisher = p;
 - count = c;
 - year = y;
 - paper = ta;
 - electronic = tp;
 - audio = te;
 - }
 - bool operator < (const Book & B) const
 - {
 - if (count != B.count)
 - return (count < B.count);
 - else if (year != B.year)
 - return (year < B.year);
 - else return (titel < B.titel);
 - }
 - int count_() { return count;}
 - int year_() { return year; }
 - string titel_() { return titel; }
 - void fill()
 - {
 - srand(time(NULL));
 - int i1 = rand() % 5, i2 = rand() % 5, i3 = rand() % 5, i4 = rand() % 5,
 - i5 = rand() % 5000, i6 = rand() % 2023, i7 = rand() % 1000, i8 = rand() % 1000, i9 = rand() % 1000;
 - first_name_a = names[i1];
 - second_name_a = surnames[i2];
 - titel = books[i3];
 - publisher = publishers[i4];
 - count = i5;
 - year = i6;
 - paper = i7;
 - electronic = i8;
 - audio = i9;
 - }
 - void print() const
 - {
 - cout << "\nName authot: " << first_name_a << "\nSurname author: " << second_name_a <<
 - "\nTitel of book: " << titel << "\nCount books: " << count << "\nPublisher: " << publisher <<
 - "\nYear of publication: " << year << "\nNumber of paper books: " << paper << "\nNumber of electronic books:" <<
 - electronic << "\nNumber of audio books:" << audio << '\n';
 - }
 - };
 - Book pop(list<Book>& l, list<Book>::iterator it)
 - {
 - l.erase(it);
 - return l.back();
 - }
 - bool vowels(char const& c)
 - {
 - return (c == 'A' || c == 'a' ||
 - c == 'E' || c == 'e' ||
 - c == 'I' || c == 'i' ||
 - c == 'O' || c == 'o' ||
 - c == 'U' || c == 'u' ||
 - c == 'Y' || c == 'y');
 - }
 - template<class T>
 - list<T> filter(list<T>& lst, _ptr comp)
 - {
 - list<T> ans;
 - for (auto it = lst.begin(); it != lst.end(); ++it)
 - {
 - if (comp(*it))
 - ans.push_back(*it);
 - }
 - return ans;
 - }
 - template<class T>
 - void push(list<T>& lst, const T& element)
 - {
 - auto i = lst.begin();
 - for (; i != lst.end(); ++i)
 - if (element < *i)
 - break;
 - lst.insert(i, element);
 - }
 - template<class T>
 - void print(list<T>& const lst)
 - {
 - for (auto i = lst.begin(); i != lst.end(); ++i)
 - cout << *i << " ";
 - cout << '\n';
 - }
 - int main()
 - {
 - /*list<char> lst;
 - _ptr ptr = &vowels;
 - for (char i = 'A'; i < 'Z'; ++i)
 - lst.push_back(i);
 - print(lst);
 - cout << '\n';
 - list<char> lst2 = filter(lst, ptr);
 - print(lst2); cout << '\n';
 - insertF(lst2, 'A'); print(lst2);*/
 - list<Book> lst;
 - for (int i = 0; i < 5; ++i)
 - {
 - Book A;
 - A.fill();
 - push(lst, A);
 - }
 - auto iter = lst.begin();
 - advance(iter, 2);
 - Book B = pop(lst, iter);
 - B.print();
 - return 0;
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment