#include<fstream.h>
#include<stdio.h>
#include<conio.h>
class book
{
int bookno;
char bookname[20];
char author[20];
char publisher[20];
float price;
int noofcopies;
int noofcopiesissued;
public:
int retbookno(){return bookno;}
void getdata();
void issue();
void returnbook();
void putdata();
};
void book::getdata()
{
cout<<"Enter Book Number";
cin>>bookno;
cout<<"Book Name";
gets(bookname);
cout<<"Publisher Name";
gets(publisher);
cout<<"Author Name";
gets(author);
cout<<"Price";
cin>>price;
cout<<"No of copies";
cin>>noofcopies;
noofcopiesissued=0;
}
void book::issue()
{
if(noofcopies>noofcopiesissued)
noofcopiesissued++;
else
cout<<"Sorry all copies are issued";
}
void book::returnbook()
{
noofcopiesissued--;
}
void book:
utdata()
{
cout<<"Book Number:\t"<<bookno<<endl;
cout<<"Book Name\t"<<bookname<<endl;
cout<<"Publisher\t"<<publisher<<endl;
cout<<"Author\t"<<author<<endl;
cout<<"No of copies issued"<<noofcopiesissued<<endl;
cout<<"No of copies"<<noofcopies<<endl;
}
void main()
{
clrscr();
book obj;
int ch;
char ans;
fstream finout;
do
{
cout<<"\t\t\tMENU\n";
cout<<"\tchoice\tfunction\n";
cout<<"1.\tAdd Books\n";
cout<<"2.\tIssue Book\n";
cout<<"3.\tReturn Book\n";
cout<<"4.\tDisplay Books\n";
cout<<"5.\tExit\n";
cout<<"Enter your choice";
cin>>ch;
switch(ch)
{
case 1:
fstream fout("Library1.dat",ios::app);
do
{
obj.getdata();
fout.write((char*)&obj,sizeof(obj));
cout<<"do u wanna cntinue";
cin>>ans;
}while(ans=='y'||ans=='Y');
fout.close();
break;
case 2:
int c=0;
int bno;
cout<<"Enter Book Number";
cin>>bno;
finout.open("Library1.dat",ios::in|ios:
ut);
while(finout.read((char*)&obj,sizeof(obj)))
{
c++;
if(obj.retbookno()==bno)
{
obj.issue();
finout.seekp((c-1)*sizeof(obj));
finout.write((char*)&obj,sizeof(obj));
break;
}
}
finout.close();
break;
case 3:
c=0;
bno;
cout<<"Enter Book Number";
cin>>bno;
finout.open("Library1.dat",ios::in|ios:
ut);
while(finout.read((char*)&obj,sizeof(obj)))
{
c++;
if(obj.retbookno()==bno)
{
obj.returnbook();
finout.seekp((c-1)*sizeof(obj));
finout.write((char*)&obj,sizeof(obj));
break;
}
}
finout.close();
break;
case 4:
finout.open("Library1.dat",ios::in);
while(finout.read((char*)&obj,sizeof(obj)))
obj.putdata();
finout.close();
break;
}
}while(ch!=5);
}