Array of Structures in C++

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

Statement

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];
	//INPUT
	for(int i=0; i<=4; i++){
	cout<<"Enter ID for Book"<<i+1<<":";
	cin>>bk[i].id;
	cout<<"Enter Pages for Book"<<i+1<<":";
	cin>>bk[i].pages;
	cout<<"Enter Price for Book"<<i+1<<":";
	cin>>bk[i].price;	    cout<<"--------------------------------------------------n";
	}
	// OUTPUT
cout<<"IDttPAGESttPRICEn";
	for(int j=0; j<=4; j++)
        {	
	cout<<bk[j].id<<"tt"<<bk[j].pages<<"tt"<<bk[j].price<<"n";
	}   
	system("pause");
}

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

Let's Discuss