In: Computer Science
C++ programming
Complete the code to input and store all the information in the structure Book: title, author, year and pages.
Complete the function print() with arguments and code to print a Book variable in the following format:
Book title: <title> Book author: <name> Published in <year> Number of pages: <pages>
#include <iostream>
using namespace std;
struct Book {
string title;
string author;
string year;
int pages;
};
void print(/*arguments*/)
{
//Complete function
}
int main() {
//Declare structure variable
//Get 4 inputs
//Call print function to generate output
}
Code:
#include<iostream>
using namespace std;
struct Book
   {
   string title;
   string author;
   string year;
   int pages; //structure declaration
   };
void print(struct Book input[]) //print function
   {
       int i;
       cout << "All Books
Details\n"; //printing all books details
       for (i=0;i<4;i++) //iterating
loop to print the books details
           {
           cout <<
input[i].title << endl << input[i].author << endl
<< input[i].year << endl << input[i].pages
<< endl;
           }
   }
int main()
{
   struct Book input[4]; //structure Book input array
taking 4 books details
   int i;
   char ch;
   for (i=0;i<4;i++) // taking 4 books details
       {
       cout << "Enter the Book Title
: ";
       getline(cin,input[i].title);
//taking book title from user
         
       cout << "Enter the Book
Author : ";
       getline(cin,input[i].author);
//taking author from user
      
       cout << "Enter the Year when
book was published : ";
       getline(cin,input[i].year);
//taking year from user
      
       cout << "Enter the no of
pages in Book : ";
       cin >> input[i].pages;
//taking pages from user
       cin.ignore(); //ignore the new
lines
       cout << endl;
       }
   print(input); //calling print() function
   return 0;
}
Code and Outputs Screenshots:



Note : if you have any queries please post a comment thanks a lot...always available to help you...