Array of Structures in C++

Some time we need to make Array of Structures in C++. We may face problem statement as below.


Write a program that declares a structure to store id, pages and price of a book. It defines an array of structures to store the records of five books.
It inputs the record of five books and displays the record of five books

Code Array of Structures in C++

Following program is written in Microsoft visual C++.

#include <iostream>
using namespace std;
struct book{
	int id;
	int	pages;
	int price;
void main()
	book bk[5];
	for(int i=0; i<=4; i++){
	cout<<"Enter ID for Book"<<i+1<<":";
	cout<<"Enter Pages for Book"<<i+1<<":";
	cout<<"Enter Price for Book"<<i+1<<":";
	cin>>bk[i].price;	    cout<<"--------------------------------------------------n";
	for(int j=0; j<=4; j++)

If you are getting any issue or need any help you may ask by commenting below.

Let's Discuss