rendered paste body#include<iostream>
#include<fstream>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
using namespace std;
class bookentery
{
int bookno;
char name[30];
char auth[20];
int price;
int quantity;
int no_issued;
public:
int booknoass();
void get();
void disp();
void wtf();
void rff();
int searchf();
friend void issue();
void ret();
void del (char n[30]);
void mod();
}book;
int bookentery::booknoass()
{
int no=0;
ifstream ifile1;
ifile1.open("book_list");
int a=ifile1.tellg();
a=a-sizeof(book);
ifile1.seekg(a,ios::end);
ifile1.read((char*)&book,sizeof(book));
no=bookno;
no++;
ifile1.close();
return no;
}
void bookentery :: get()
{
cout<<"\nBOOK NUMBER";
bookno=booknoass();
cout<<bookno<<endl;
cout<<"\nNAME OF THE BOOK";
cin>>name;
cout<<"\nNAME OF THE AUTHOR";
cin>>auth;
cout<<"\nPRICE OF THE BOOK\n";
cin>>price;
cout<<"\nNOI. OF COPIES ADDED";
cin>>quantity;
cout<<"\nNO OF COPIES ISSUED";
cout<<"\n"<<no_issued<<"\n";
}
void bookentery :: disp()
{
cout<<"\nBOOK NUMBER\n";
cout<<bookno;
cout<<"\nNAME OF THE BOOK\n";
cout<<name;
cout<<"\nNAME OF THE AUTHOR\n";
cout<<auth;
cout<<"\nPRICE OF THE BOOK\n";
cout<<price;
cout<<"\nNO. OF COPIES ADDED\n";
cout<<quantity;
cout<<"\nNO OF COPIES ISSUED\n";
cout<<no_issued;
cout<<endl<<endl<<endl;
}
void bookentery :: wtf()
{
ofstream ofile1;
ofile1.open("book_list",ios::app);
get();
ofile1.write((char*)&book,sizeof(book));
ofile1.close();
}
void bookentery :: rff()
{
ifstream ifile1;
ifile1.open("book_list");
ifile1.seekg(0,ios::beg);
ifile1.read((char*)&book,sizeof(book));
while(ifile1)
{
disp();
ifile1.read((char*)&book,sizeof(book));
}
ifile1.close();
}
int bookentery :: searchf()
{
char search[30];
int flag=0;
int ch;
ifstream ifile1;
ifile1.open("book_list");
ifile1.seekg(0,ios::beg);
cout<<"search by author -1 \n by name of book -2";
cin>>ch;
if(ch==1)
{cout<<"enter name of author";
cin>>search;
while(ifile1)
{
ifile1.read((char*)&book,sizeof(book));
if(strcmpi(auth,search)==0)
{
{
flag=1;
break;
}
}
}
if(flag)
{
cout<<"FOUND";
disp();
return 1;
}
else
{cout<<"not found";
return 0;}
}
else if(ch==2)
{cout<<"enter name of book";
cin>>search;
while(ifile1)
{
ifile1.read((char*)&book,sizeof(book));
if(strcmpi(name,search)==0)
{
{
flag=1;
break;
}
}
}
if(flag)
{
cout<<"FOUND";
disp();
return 1;
}
else
{
cout<<"not found";
return 0;
}
}
ifile1.close();
}
void bookentery :: del (char n[30])
{
ifstream ifile;
ifile.open("book_list");
ofstream ofile;
ofile.open("temp",ios::app);
ifile.seekg(0,ios::beg);
ifile.read((char*)&book,sizeof(book));
while(ifile)
{
if(strcmpi(n,name))
ofile.write((char*)&book,sizeof(book));
ifile.read((char*)&book,sizeof(book));
};
ifile.close();
ofile.close();
remove("book_list");
rename("temp","book_list");
}
void bookentery :: ret()
{
fstream f;
char n[20];
cout<<"name of the book to be returned";
cin>>n;
f.open("book_list",ios::in|ios::out);
f.seekg(0,ios::beg);
f.read((char*)&book,sizeof(book));
int a=f.tellg();
while(!f.eof())
{
if(strcmpi(n,name)==0)
{
no_issued--;
f.seekp(a-sizeof(book));
f.write((char*)&book,sizeof(book));
}
f.read((char*)&book,sizeof(book));
a=f.tellg();
}
f.close();
}
void bookentery::mod()
{
fstream f;
char n[20];
cout<<"name of the book to be modified";
cin>>n;
f.open("book_list",ios::in|ios::out);
f.seekg(0,ios::beg);
f.read((char*)&book,sizeof(book));
int a=f.tellg();
while(!f.eof())
{
if(strcmpi(n,name)==0)
{
get();
f.seekp(a-sizeof(book));
f.write((char*)&book,sizeof(book));
}
f.read((char*)&book,sizeof(book));
a=f.tellg();
}
f.close();
}
class student
{
char name[20];
char phno[20];
char add[50];
int admno;
int cardno;
char bookissued [3][50];
int noissued;
public:
void disp();
void get();
friend void issue();
void wtf();
void rff();
int searchf();
}stud;
void issue()
{
char search[30];
int flagb=0;
int ch;
ifstream ifile1;
ifile1.open("book_list");
ifile1.seekg(0,ios::beg);
cout<<"search by author -1 \n by name of book -2";
cin>>ch;
if(ch==1)
{cout<<"enter name of author";
cin>>search;
ifile1.read((char*)&book,sizeof(book));
while(ifile1)
{
if(strcmpi(book.auth,search)==0)
{
{
flagb=1;
break;
}
}
ifile1.read((char*)&book,sizeof(book));
}
if(flagb)
{
cout<<"FOUND";
}
else
{cout<<"not found";
// return 0;}
}
}
else if(ch==2)
{cout<<"enter name of book";
cin>>search;
ifile1.seekg(0,ios::beg);
while(ifile1)
{
ifile1.read((char*)&book,sizeof(book));
if(strcmpi(book.name,search)==0)
{
{
flagb=1;
break;
}
}
}
if(flagb)
{
cout<<"FOUND";
}
else
{
cout<<"not found";
}
}
int flags=0;
ifstream ifile2;
ifile2.open("student");
char namestud[20];
cout<<"enter name of student";
cin>>namestud;
ifile2.seekg(0,ios::beg);
while(ifile2)
{
ifile2.read((char*)&stud,sizeof(stud));
if(strcmpi(namestud,stud.name)==0)
{
{
flags=1;
break;
}
}
}
int b=ifile1.tellg();
int s=ifile2.tellg();
ifile1.close();
ifile2.close();
if(flags)
{
cout<<"FOUND";
}
else
{cout<<"not found";
}
if(stud.noissued>=3)
{
flags=0;
}
if(book.no_issued==book.quantity)
{
flagb=0;
}
fstream file1;
fstream file2;
cout<<flagb<<flags;
if((flagb==1)&&(flags==1))
{
file1.open("student",ios::out|ios::in);
file2.open("book_list",ios::out|ios::in);
file1.seekg(s-sizeof(stud),ios::beg);
file2.seekg(b-sizeof(book),ios::beg);
file1.read((char*)&stud,sizeof(stud));
file2.read((char*)&book,sizeof(book));
book.no_issued++;
stud.noissued++;
cout<<"issued";
strcpy(stud.bookissued[stud.noissued-1],search);
file1.seekp(s-sizeof(stud),ios::beg);
file2.seekp(b-sizeof(book),ios::beg);
file1.write((char*)&stud,sizeof(stud));
file2.write((char*)&book,sizeof(book));
}
file1.close();
file2.close();
}
void student :: disp()
{
cout<<"\nNAME";
cout<<name;
cout<<"\nPHNO";
cout<<phno;
cout<<"\nADDRESS";
cout<<add;
cout<<"\nCARD NO";
cout<<cardno;
cout<<"\nNo. of books issued";
cout<<noissued;
cout<<"\nBooks issued\n";
cout<<bookissued[0]<<endl<<bookissued[1];//<<endl<<bookissued[2]<<endl;
}
void student :: get()
{
cout<<"\nNAME";
cin>>name;
cout<<"\nPHNO";
cin>>phno;
cout<<"\nADDRESS";
cin>>add;
cout<<"\nCARD NO";
cin>>cardno;
noissued=0;
}
void student :: wtf()
{
ofstream ofile;
ofile.open("student",ios::app);
get();
ofile.write((char*)&stud,sizeof(stud));
ofile.close();
}
void student :: rff()
{
ifstream ifile;
ifile.open("student");
ifile.seekg(0,ios::beg);
ifile.read((char*)&stud,sizeof(stud));
while(ifile)
{
disp();
ifile.read((char*)&stud,sizeof(stud));
}
ifile.close();
}
int student :: searchf()
{
int flag=0;
ifstream ifile1;
char namestud[20];
cout<<"enter name of student";
cin>>namestud;
while(ifile1)
{
ifile1.read((char*)&stud,sizeof(stud));
if(strcmpi(namestud,name)==0)
{
{
flag=1;
break;
}
}
}
if(flag)
{
cout<<"FOUND";
disp();
return 1;
}
else
{cout<<"not found";
return 0;
}
}
int main()
{
char namebook[20];
int c;
a:
cout<<"\n************************MAIN MENU***************************";
cout<<"\n1.LIBRARIAN";
cout<<"\n2.STUDENT";
cout<<"\n3.DELETE ALL DATA";
cout<<"\n4.EXIT";
cout<<"\nEnter ur category\t";
cin>>c;
if(c==3)
{
int a;
cout<<"for student press 1\n";
cout<<"for books press 2\n";
cin>>a;
if(a==1)
{
ofstream ofile;
ofile.open("student",ios::trunc);
ofile.close();
}
else if(a==2)
{
ofstream ofile1;
ofile1.open("book_list",ios::trunc);
ofile1.close();
}
}
if((c!=1)&&(c!=2)&&(c!=3)&&(c!=4))
{
cout<<"wrong choice";
goto a;
}
int readwrite=0;
while (c==1)
{
cout<<"\nenter 1 to read records enter 2 to write,3 to search,4 to delete,5 to issue,6 to return,7 to mod";
cin>>readwrite;
if(readwrite==2)
book.wtf();
else if(readwrite==1)
book.rff();
else if(readwrite==3)
book.searchf();
else if(readwrite==4)
{cout<<"enter name of book to be deleted";
cin>>namebook;
book.del(namebook);}
else if(readwrite==5)
issue();
else if(readwrite==6)
book.ret();
else if(readwrite==7)
book.mod();
else
cout<<"wrong choice";
cout<<"enter 1 to continue as libranian";
cin>>c;
if(c!=1)
goto a;
}
while(c==2)
{
cout<<"\nenter 1 to read records enter 2 to write,3 to search";
cin>>readwrite;
if(readwrite==2)
stud.wtf();
else if(readwrite==1)
stud.rff();
else if(readwrite==3)
{stud.searchf();}
else
cout<<"wrong choice";
cout<<"enter 2 to continue as student";
cin>>c;
if(c!=2)
goto a;
}
return 0;
}