#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int n;
class Inventory
{
char author[20],publisher[20],title[20];
int book_no,price,stock;
public:
void accept();
friend void sale(Inventory *,int,int);
friend void purchase(Inventory *,int,int)
void display();
};
void Inventory :: accept()
{
cout<<"\n Book Number    : ";cin>>book_no;
cout<<"\n Book Author    : ";cin>>author;
cout<<"\n Book Title     : ";cin>>title;
cout<<"\n Book Price     : ";cin>>price;
cout<<"\n Book Publisher : ";cin>>publisher;
cout<<"\n Stock of Book  : ";cin>>stock;
}
void Inventory :: display()
{
cout<<"\n\n Book Number    : "<<book_no;
cout<<"\n Book Author    : "<<author;
cout<<"\n Book Title     : "<<title;
cout<<"\n Book Price     : "<<price;
cout<<"\n Book Publisher : "<<publisher;
cout<<"\n Stock of Book  : "<<stock;
}
void sale(Inventory *I,int b_no,int Qty)
{
int f=0,f1=0;
for(int i=0;i<n;i++)
if(I[i].book_no==b_no)
{
f1=1;
if(I[i].stock>=Qty)
{
I[i].stock=I[i].stock-Qty;
I[i].display();
f=1;
}
}
if(f1==0)
{
cout<<"\n\nBook is not available check book number";
}
else
if(f==0)
cout<<"\n\nStock is not available please purchase book";
}
void purchase(Inventory *I,int b_no,int Qty)
{
int f=0;
for(int i=0;i<n;i++)
if(I[i].book_no==b_no)
{
I[i].stock=I[i].stock+Qty;
cout<<"\n\nStock is updated";
I[i].display();
f=1;
}
if(f==0)
cout<<"\n\nBook is not present check book number";

}


int main()
{
Inventory I[20];
clrscr();
int ch,b_no,Qty;
cout<<"\n\nEnter how many books detail you want to enter : ";
cin>>n;
do
{
cout<<"\n Main menu ";
cout<<"\n 1.Accept book details ";
cout<<"\n 2.Display book details ";
cout<<"\n 3.Sale book";
cout<<"\n 4.Purchase book ";
cout<<"\n 5.Exit ";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1: for(int i=0;i<n;i++)
I[i].accept();
break;
case 2: for(i=0;i<n;i++)
I[i].display();
break;
case 3: cout<<"\n\nEnter book number which you want to sale : ";
cin>>b_no;
cout<<"\n\nEnter book quantity :";
cin>>Qty;
sale(I,b_no,Qty);
break;
case 4:
cout<<"\n\nEnter book number which you want to purchase : ";
cin>>b_no;
cout<<"\nEnter book quantity :";
cin>>Qty;
purchase(I,b_no,Qty);
break;
case 5: exit(0);
}
}
while(ch!=5);
getch();
return(0);
}

Post a Comment

Previous Post Next Post