06/03/2023

C++ Program For Book Details Using Structure | Source Code

C++ Program For Book Details Using Structure. Write a c++ program to declare a structured book with members as book IDs and names. accept and display data from five books using an array of structures. Write a c program to read and print information from a book using a structure. write a C++ program to read and print information of a book using structure.

C++ Program For Book Details Using Structure

Note: This is a Requested Problem from Ethiopia. You can also request Programming Problems. So Don't Forgot To Share Thanks, Tomas Umer (Ethiopia)Writing For Us. Write a C++ program to read the title, author and price of 5 books using an array of structures.

"Question: C++ program using a structure which accepts information from five books. The information includes titles, publication year, and status. what the status will do is if the book is published before 1990 it says "outdated" if the book is published between 1991-2000 the status will be "medium" but it's after 2000 the status will be "late" please help me thank u "


Book Details Using Structure

Here we are storing Book Details Using Structure like Title, and Publication. here in the structure block book title and publication define a string and year and status is an integers. see the below block for a better understanding.

Book Structure Block


struct books
{
	char title[25];
	char pub[25];
	int year;
	int status;
};

After the defined structure put the value in the structure by putting the value taken from a user with the help of ' For Loop '. First, enter the book title after that book publication then after a year and at the last status of the book. C++ Program For Book Details Using Structure. See the Example of how to Store the info in the structure.


for (i = 0; i < n; i++)
{
	cout << "Title: ";
	cin >> a[i].title;

	cout << "Publication : ";
	cin >> a[i].pub;

	cout << "Year: ";
	cin >> a[i].year;

	cout << "Status: ";
	cin >> a[i].status;
	cout << "----------------------\n";

}

And at the end display or print, the Book Details structure Stored Information in the console.


for (i = 0; i < n; i++)
{
	cout << "\n" << a[i].title << "\t\t|" << a[i].pub << "\t\t|" << a[i].year << "\t\t|";
	if (a[i].status <= 1990)
	{
		cout << "Outdated";
	}
	else if (a[i].status >= 1991 && a[i].status <= 2000)
	{
		cout << "Medium";
	}
	else
	{
		cout << "Lates";
	}
}

Read: C++ Program For Employee Information Using Nested Structure

C++ Program For Book Details Using Structure


#include <bits/stdc++.h>
using namespace std;

/*c++ program to maintain book record using file handling*/

struct books
{
	char title[25];
	char pub[25];
	int year;
	int status;
};

int main()
{
	int i, n;

	cout << "Enter Number Of Books : ";
	cin >> n;

	struct books a[n];

	cout << "Enter The Book Details : \n";
	cout << "-------------------------\n";

	for (i = 0; i < n; i++)
	{
		cout << "Title : ";
		cin >> a[i].title;

		cout << "Publication : ";
		cin >> a[i].pub;

		cout << "Year : ";
		cin >> a[i].year;

		cout << "Status : ";
		cin >> a[i].status;
		cout << "----------------------\n";
	}

	cout << "=====================================================\n";
	cout << "Book Title \t|Publication \t|Year \t\t|Status\n";
	cout << "=====================================================\n";

	for (i = 0; i < n; i++)
	{
		cout << "\n" << a[i].title << "\t\t|" << a[i].pub << "\t\t|" << a[i].year << "\t\t|";
		if (a[i].status <= 1990)
		{
			cout << "Outdated";
		}
		else if (a[i].status >= 1991 && a[i].status <= 2000)
		{
			cout << "Medium";
		}
		else
		{
			cout << "Lates";
		}
	}

	cout << "\n\n=================================================";

	return 0;

}

What Is Structure


The structure is a user-defined data type in C++. The structure is used to represent a record. Suppose you want to store a record of a Book which consists of the Book Name, Book Publication, Book Years and Book Status. You can define a structure to hold this information.

Defining a Structure

struct keyword is used to define a structure. struct define a new data type which is a collection of different type of data. Book details using structure in C++.

Syntax of Structure

struct structure_name
{
//Statements
};


C++ Program For Book Details Using Structure Output


C++ Program For Book Details Using Structure Output

Similar to Book Details Using Structure


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: