Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //amocana1
- /*
- class Book
- {
- protected:
- string author,name;
- int year;
- public:
- Book (){}
- Book (string author,int year,string name)
- {
- this->author=author;
- this->year=year;
- this->name=name;
- }
- ~Book (){ }
- void printBook ()
- {
- cout<<"Name: "<<name<<endl;
- cout<<"Year: "<<year<<endl;
- cout<<"Author: "<<author<<endl;
- }
- int get_year ()
- {
- return year;
- }
- };
- class Textbook : public Book
- {
- protected:
- int grade;
- public:
- Textbook (string author,int year,string name,int grade) : Book (author,year,name)
- {
- this->grade=grade;
- }
- void printText ()
- {
- cout<<"Name: "<<name<<endl;
- cout<<"Year: "<<year<<endl;
- cout<<"Author: "<<author<<endl;
- cout<<"Grade: "<<grade<<endl;
- }
- };
- bool sort_by_year (Book a, Book b)
- {
- return a.get_year() > b.get_year();
- }
- int main ()
- {
- string name,author;
- int grade,year;
- int n;
- cin>>n;
- vector<Book>Books;
- for (int i=0;i<n;i++)
- {
- cin>>author>>year>>name>>grade;
- Book b(author,year,name);
- Textbook t (author,year,name,grade);
- Book *b_ptr=&b;
- Textbook *t_ptr=&t;
- b_ptr=t_ptr;
- t_ptr=(Textbook*)&b;
- Books.push_back(*b_ptr);
- Books.push_back(*t_ptr);
- }
- sort (Books.begin(),Books.end(),sort_by_year);
- for (int i = 0; i < Books.size(); ++i)
- {
- Books.at(i).printBook();
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement