0% found this document useful (0 votes)
4 views1 page

C++ Book Struct Example Code

The document is a C++ program that defines a structure for books, including attributes like title, author, subject, and book ID. It creates two book instances with specific details and prints their information using a function. The program demonstrates basic structure usage and string manipulation in C++.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

C++ Book Struct Example Code

The document is a C++ program that defines a structure for books, including attributes like title, author, subject, and book ID. It creates two book instances with specific details and prints their information using a function. The program demonstrates basic structure usage and string manipulation in C++.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#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; // Declare Book1 of type Book
struct Books Book2; // Declare Book2 of type Book

// book 1 specification
strcpy( [Link], "Learn C++ Programming");
strcpy( [Link], "Chand Miyan");
strcpy( [Link], "C++ Programming");
Book1.book_id = 6495407;

// book 2 specification
strcpy( [Link], "Telecom Billing");
strcpy( [Link], "Yakit Singha");
strcpy( [Link], "Telecom");
Book2.book_id = 6495700;

// Print Book1 info


printBook( Book1 );

// Print Book2 info


printBook( Book2 );

return 0;
}
void printBook( struct Books book ) {
cout << "Book title : " << [Link] <<endl;
cout << "Book author : " << [Link] <<endl;
cout << "Book subject : " << [Link] <<endl;
cout << "Book id : " << book.book_id <<endl;
}

You might also like