C++ Programming Blog

 
 
 

Image

//Library Database
#include <iostream.h>
#include <string.h>
#include <iomanip.h>
#include <conio.h>

class books
{
char **author,**title,**publisher;
int *price;
static int count;
public:

 books(void);   //constructor
 void getdata(void);
 void display_stock(void);
 void search(void);
};

int books :: count=0;

books :: books(void)
{
  author=new char*[15];
  title=new char*[15];
  publisher=new char*[15];
  price=new int[15];
     for(int i=0;i<15;i++)
       {
         author[i]=new char;
         title[i]=new char;
         publisher[i]=new char;
       }
 }

void books :: getdata(void)
{
  cout<<\"\\n\\n\\nEnter Book name:-\";
  cin>>title[count];
  cout<<\"Enter Author name:-\";
  cin>>author[count];
  cout<<\"Enter Publisher of book:-\";
  cin>>publisher[count];
  cout<<\"Enter Price of book:-\";
  cin>>price[count];
  count++;
}

void books :: display_stock(void)
{
clrscr();
cout<<\"\\n\\n\\n\";
cout<<setw(15)<<\"Book Name\"<<setw(20)<<\"Author Name\"<<setw(20)<<\"Publisher\"<<setw(10)<<\"Price\"<<endl<<endl;
for(int i=0;i<count;i++)
{
cout<<setw(15)<<title[i]<<setw(20)<<author[i]<<setw(20)<<publisher[i]<<setw(10)<<price[i]<<endl;
}
cout<<\"\\n\\nTotal Number of Books are \"<<count;
}

void books :: search(void)
{
clrscr();
 char  name[20],writer[20];
 cout<<\"\\n\\n\\nEnter Book name:-\";
 cin>>name;
 cout<<\"Enter Author of Book:-\";
 cin>>writer;
 for(int i=0;i<count;i++)
 {
   if((strcmp(title[i],name)==0) && (strcmp(author[i],writer)==0))
     {
     cout<<\"\\n\\nEntered Information Book Available\\n\";
     cout<<\"Price of that book is \"<<price[i];
     goto skip;
     }
 }
 cout<<\"\\n\\nBook is not Available in stock\\n\";
skip:
}

void main()
{
clrscr();
books o1;
int choice;
while(1)
{
cout<<\"\\n\\nChoose your choice\\n\";
cout<<\"1) Entering Information for book\\n\";
cout<<\"2) To See Actual stock\\n\";
cout<<\"3) To Search for a Particular book\\n\";
cout<<\"4) Exit\\n\";
cout<<\"Enter your choice:-\";
cin>>choice;
 switch(choice)
 {
   case 1 : o1.getdata();
             break;
   case 2 : o1.display_stock();
             break;
   case 3 : o1.search();
             break;
   case 4 : goto out;
   default: cout<<\"\\n\\nEnter choice is invalid\\nTry again\\n\";
 }
}
out:
}

 
 
Didn't find what you were looking for? Find more on Library System