Computer scienceProgramming languagesC++Types and data structures

Structures

Theory

Bookshelf

Report a typo

Write a C++ program that defines a structure called Book with the following members: title (string), author (string), and year (int). Create an array of three Book objects and initialize their members.

Title Author Year
Dune Frank Herbert 1965
1984 George Orwell 1949
Brave New World Aldous Huxley 1932

Print the details of all the books like this (table format)

Sample Input 1:

Sample Output 1:

| Title                | Author           | Year |
|----------------------|------------------|------|
| Dune                 | Frank Herbert    | 1965 |
| 1984                 | George Orwell    | 1949 |
| Brave New World      | Aldous Huxley    | 1932 |
Write a program in C++
int main{


//Your code is here

std::cout << "| Title | Author | Year |" << std::endl;
std::cout << "|----------------------|------------------|------|" << std::endl;
std::cout << "| " << book1.title <<" | ";
std::cout << book1.author <<" | ";
std::cout << book1.year << " |" << std::endl;
std::cout << "| " << book2.title <<" | ";
std::cout << book2.author <<" | ";
std::cout << book2.year << " |" << std::endl;
std::cout << "| " << book3.title <<" | ";
std::cout << book3.author <<" | ";
std::cout << book3.year << " |" << std::endl;

return 0;
}

Create a free account to access the full topic