fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. struct author{
  7. string name;
  8. string surname;
  9. author(const string& name, const string& surname):name(name),surname(surname){}
  10. };
  11.  
  12. struct book{
  13. author auth;
  14. string title;
  15. int releaseYear;
  16. int releaseNo;
  17. book(const string& authorName, const string& authorSurname, const string& title, int year, int no)
  18. :auth(author(authorName, authorSurname)),title(title),releaseYear(year),releaseNo(no){}
  19. };
  20.  
  21. class library{
  22. private:
  23. vector<book> books;
  24.  
  25. public:
  26. void add(const book& book){ this->books.push_back(book); }
  27. void print(){
  28. for(unsigned i=0;i<this->books.size();++i){
  29. cout << i + 1 << ". " << this->books[i].title << endl
  30. << "Author: " << this->books[i].auth.name << " " << this->books[i].auth.surname << endl
  31. << "Release date: " << this->books[i].releaseYear << endl
  32. << "Release no: " << this->books[i].releaseNo << endl << endl;
  33. }
  34. }
  35. };
  36.  
  37. int main()
  38. {
  39. library lib;
  40. lib.add(book("Adam", "Mickiewicz", "Pan Tadeusz", 1834, 12));
  41. lib.add(book("Boleslaw", "Prus", "Lalka", 1887, 3));
  42. lib.print();
  43. return 0;
  44. }
Success #stdin #stdout 0s 3420KB
stdin
Standard input is empty
stdout
1. Pan Tadeusz
Author: Adam Mickiewicz
Release date: 1834
Release no: 12

2. Lalka
Author: Boleslaw Prus
Release date: 1887
Release no: 3