fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <string>
  5.  
  6. // Define a struct to hold book information
  7. struct Book {
  8. std::string title;
  9. std::string author;
  10. std::string isbn;
  11. };
  12.  
  13. // Function to print the books in a tabular format
  14. void printBooks(const std::vector<Book>& books) {
  15. // Print the header
  16. std::cout << std::left << std::setw(30) << "Title"
  17. << std::setw(30) << "Author"
  18. << std::setw(20) << "ISBN" << std::endl;
  19. std::cout << std::string(80, '-') << std::endl;
  20.  
  21. // Print each book's details
  22. for (const auto& book : books) {
  23. std::cout << std::left << std::setw(30) << book.title
  24. << std::setw(30) << book.author
  25. << std::setw(20) << book.isbn << std::endl;
  26. }
  27. }
  28.  
  29. int main() {
  30. // Create a vector of books
  31. std::vector<Book> books = {
  32. {"The Great Gatsby", "F. Scott Fitzgerald", "9780743273565"},
  33. {"1984", "George Orwell", "9780451524935"},
  34. {"To Kill a Mockingbird", "Harper Lee", "9780060935467"}
  35. };
  36.  
  37. // Print the books
  38. printBooks(books);
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5244KB
stdin
Standard input is empty
stdout
Title                         Author                        ISBN                
--------------------------------------------------------------------------------
The Great Gatsby              F. Scott Fitzgerald           9780743273565       
1984                          George Orwell                 9780451524935       
To Kill a Mockingbird         Harper Lee                    9780060935467