Thursday, 17 March 2016

C++ Program For Store Book Details Using Structure

Problem :- Write A C++ Program For Store Book Details Using Structure .

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

"question here: a c++ program using 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 its after 2000 the status will be "lates" please help me thank u "

C++ Program For Store Book Details Using Structure

What Is Structure 

Structure is a user-defined data type in C . Structure is used to represent a record. Suppose you want to store 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 books information like Title , Publication ,Year And Status using for loop So just define a structure like Below.

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

Then Store the information in structure 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 Then Displaying the Stored Information .

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

    }

See The Below Problem For Handling a Nested Structure .

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

No comments:
Write comments

Recommended Posts × +