fork download
  1. #include<iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Book
  7. {
  8. private:
  9. int year;
  10. string author;
  11. string bookName;
  12.  
  13. public:
  14.  
  15. Book(int year, const char* author, const char* bookName)
  16. :year(year),author(author),bookName(bookName){}
  17.  
  18. string getStr()
  19. {
  20. return std::to_string(year)+" | "+author+" | "+bookName;
  21. }
  22.  
  23. int getYear(){return year;}
  24. };
  25.  
  26.  
  27. int main()
  28. {
  29. Book b[] = {
  30. Book(2016,"Me","Options..."),
  31. Book(2018,"Me","Options VAK...")
  32. };
  33.  
  34. for(int i(0);i<2;i++)
  35. std::cout<<b[i].getStr()<<"\n";
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
2016 | Me | Options...
2018 | Me | Options VAK...