The code defines a structure Books that contains information about books such as title, author, subject, and book ID. In the main function, two instances of the Books structure (Book1 and Book2) are created and their members are initialized using strcpy and direct assignment.
Then, the function printBook is called twice to print out the information of the two books. The function takes a pointer to a Books structure as an argument and uses the -> operator to access its members. Overall, the code demonstrates the use of structures and pointers in C++ to store and manipulate data about books.
#include<iostream> #include<cstring> using namespace std; void printBook(struct Books *book); struct Books { char title[50]; char author[50]; char subject[100]; int book_id; }; int main() { struct Books Book1; struct Books Book2; strcpy(Book1.title,"Mathematics for IITJEE"); strcpy(Book1.author,"RD Sharma"); strcpy(Book1.subject,"JEE Mathematics"); Book1.book_id = 6495407; strcpy( Book2.title,"Physics"); strcpy( Book2.author,"IE Irodov"); strcpy( Book2.subject,"JEE Mechanical Physics"); Book2.book_id=6495700; printBook( &Book1 ); printBook( &Book2 ); return 0; } void printBook(struct Books *book) { cout<<"Book title : "<<book->title <<endl; cout<<"Book author : "<<book->author <<endl; cout<<"Book subject : "<<book->subject <<endl; cout<<"Book id : "<<book->book_id <<endl; }To download raw file Click Here
Enter feet: 30 Enter inch: 12 Displaying information. Distance = 30 feet 12 inches
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions