C++ Program to Display the Details of Library Using Structure

In this program, you'll learn to declare structure 'library' having member variables are acc_no, title, author, price and isIssued. Accept data for three library books and display it.



Source Code
#include<iostream>
using namespace std;

struct library
{
    int acc_no;
    char title[20];
    char author[20];
    float price;
    int isIssued;
};

int main()
{
    struct library book[3];
    int i;

    for(i=0; i<3; i++)
    {
        cout<<"\nEnter details of Book " << i+1;
        cout<<"\nEnter accession no: ";
        cin>> book[i].acc_no;
        cout<<"Enter book title: ";
        cin>> book[i].title;
        cout<<"Enter author: ";
        cin>> book[i].author;
        cout<<"Enter price: ";
        cin>> book[i].price;
        cout<<"Is book issued (0/1): ";
        cin>> book[i].isIssued;
    }

    cout<<"\nAcc no, Title, Author, Price, Is Book Issued?\n";
    cout<<"------------------------------------------------\n";
    for(i=0; i<3; i++)
    {
        cout<< "\n" << book[i].acc_no;
        cout<< "\t" << book[i].title;
        cout<< "\t" << book[i].author;
        cout<< "\t" << book[i].price;
        cout<< "\t" << book[i].isIssued;
    }
    return 0;
}
Output
Enter details of Book 1
Enter accession no: 1001
Enter book title: C-Programming
Enter author: Mana-Ghosh
Enter price: 400.00
Is book issued (0/1): 1

Enter details of Book 2
Enter accession no: 1003
Enter book title: Networking
Enter author: Tabenbam
Enter price: 500.50
Is book issued (0/1): 0

Enter details of Book 3
Enter accession no: 1004
Enter book title: JavaScript
Enter author: DavidFlanagan
Enter price: 760.00
Is book issued (0/1): 1
------------------------------------------------

1001    C-Programming   Mana-Ghosh      400.000000      1
1003    Networking      Tabenbam        500.500000      0
1004    JavaScript      DavidFlanagan   760.00          1