C++ Programs‎ > ‎

Simple Program Book Entry Using structure Variable in C++ Programming


Example Program

#include<iostream.h>
#include<stdio.h>

struct books
{
    char name[20],author[20];
}a[50];
int main()
{
    
    int i,n;
    cout<<"No Of Books[less than 50]:";
    cin>>n;
cout<<"Enter the book details\n";
cout<<"----------------------\n";
    
    for(i=0;i<n;i++)
    {
 cout<<"Details of Book No "<<i+1<<"\n";
 cout<<"Book Name :";
 cin>>a[i].name;
 cout<<"Book Author :";
 cin>>a[i].author;
 cout<<"----------------------\n";
    }
    cout<<"================================================\n";
    cout<<" S.No\t| Book Name\t|author\n";
    cout<<"=====================================================";
    for(i=0;i<n;i++)
    {
 cout<<"\n  "<<i+1<<"\t|"<<a[i].name<<"\t| "<<a[i].author;
    }
    cout<<"\n=================================================";
    
    return 0;
}

Sample Output

No Of Books[less than 50]:2
Enter the book details
----------------------
Details of Book No 1
Book Name :Programming
Book Author :Dromy
Details of Book No 2
Book Name :C
Book Author :Byron
=======================================================
 S.No | Book Name |author
=======================================================
  1 |Programming | Dromy
  2 |C | Byron
=======================================================