Thursday, 17 March 2016

C++ Program For Store Book Details Using Structure

Problem:- Write A C++ Program For Store Book Details Using Structure or c++ program for book details using structure or c++ program for book inventory or student record program using structure in c++ or c++ program using structure for student database or c++ program for student details using class or c++ program for student details using array of objects or student mark list program in c++ using files.

Note:- Please See This is A Requested Problem From Ethiopia. You Can Also Request Any Problem Regarding Programming. So Don't Forgot To Share Thanks, Tomas Umer (Ethiopia)Writing For Us.

"Question:- a c++ program using a structure which accepts information on 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 "lates" please help me thank u "


C++ Program For Store Book Details Using Structure

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;
};

After the defined structure put the value in the structure by putting the value taking from a user with the help of ' For Loop '. first enter book title after that book publication then after a year and at the last status of the book. See the Example how Store the info in 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 structure Stored Information to 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";
}

    }

Tip:- See The Below Problem For Handling a Nested Structure and If you have any query or suggestion feel free to share with me, I will help you.

Try This C++ Program For Employee Information Using Nested Structure


Solution:-

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


C++ Program For Store Book Details Using Structure



You May Like This:-

1. Hacker Rank Solution for 30 Days of Code

2. Hacker Rank solution for Attribute Parser

3. Java Program For Find The Gross Salary Of An Employee

4. C++ Program For School Management System ( SMS Project ) With Source Code

5. Hacker Rank Solution For Mini-Max Sum

6. Hacker Rank Solution For Birthday Cake Candles

7. C++ Program For Store Employee Information And Display Using Structure

8. C Program For Find A Grade Of Given Marks Using Switch Case

9. C Program For HEAP Sort In Ascending Order Also Show Complexity

10. C++ Program For Selection Sort Using Function

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

1 comment:

  1. Thanks Sir,

    for providing this solution with explanation, I really like your website once again thanks for provind hacker rank solution.

    ReplyDelete