Skip to main content

Simple Program Book Entry using Structure Variable in C++ Programming

1 min read Updated June 30, 2026
Share:
On this page (5sections)

Simple Program Book Entry Using structure Variable

#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
=======================================================

How It Works

Here is a step-by-step walkthrough of how the C++ program for Simple Program Book Entry using Structure Variable in C++ Programming runs, line by line:

  1. struct books { — performs part of the program’s logic.
  2. char name[20], author[20]; — declares or assigns a value the program uses.
  3. } a[50]; — performs part of the program’s logic.
  4. int main() { — defines a function used by the program.
  5. int i, n; — declares or assigns a value the program uses.
  6. cout << "No Of Books[less than 50]:"; — writes a line of output shown in the sample output.
  7. cin>>n; — reads a value entered by the user.
  8. cout << "Enter the book details\n"; — writes a line of output shown in the sample output.

After running it, compare your console output with the Sample Output above. Try changing the values and re-running the program to see how the result changes — experimenting is the fastest way to understand the logic.

Learn the concept first, then study the code:

Frequently Asked Questions

What does this C++ program do?
It is a C++ example program that demonstrates Simple Program Book Entry using Structure Variable, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses loops to iterate over data, arrays and reading user input, illustrating a common pattern in C++ programming.

Related Tutorials

Search tutorials