Q:

C++ Program For Store Book Details Using Structure

belongs to collection: Examples of Structure C++ Programming

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 Student which consists of student name, address, roll number and age. 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.


Syntax:-
struct structure_name
{
//Statements
};

Logic:-

 Here we are storing a book's information like Title, Publication. here in the structure block book title and publication define a string and year and status is an integer. see the below block for better understanding.

Structure Block

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

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;

}

 

Output:

Enter Number Of Books :3

-------------------------

Enter The Book Details : 

Title  java 

Publication gorgea

Year 2013

Status  outdated

-------------------------

Enter The Book Details : 

Title  python

Publication nasifk

Year 2017

Status  medium

-------------------------

Enter The Book Details : 

Title  programming

Publication boundy

Year 2011

Status  lates

-------------------------

=====================================================

Book Title |Publication |Year |Status

java                    gorgea           2013                outdated

python              nasifk              2017               medium

programming   boundy           2011                lates

=====================================================

=================================================

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

<< C++ Program For Employee Information Using Nested ...