Sri Sathya Sai Vidya Vihar Akansha Gupta Xii - B Computer Science
Sri Sathya Sai Vidya Vihar Akansha Gupta Xii - B Computer Science
Vihar
Akansha Gupta
XII B
Computer Science
Book
Manageme
nt
System
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<process.h>
#include<dos.h>
#include<string.h>
void mainmenu();
class book
{
int bno;
char bname[30];
char aname[30];
char type[10];
int nocopy;
char yredit[5];
float cost;
public:
book()
{
bno=0;
nocopy=0;
cost=0;
}
void accept()
{
clrscr();
int count=0;
fstream f1;
f1.open("book.dat",ios::in|ios::binary);
while(f1.read((char*)this,sizeof(book)))
count++;
if(count==0)
bno=1;
else
bno++;
f1.close();
cout<<"\n Enter the book number:- ";
fflush(stdin);
cin >> bno;
cout<<"\n Enter the book title:- ";
fflush(stdin);
gets(bname);
cout<<"\n Enter the author's name:- ";
gets(aname);
cout<<"\n Enter the type of the book:- ";
gets(type);
cout<<"\n Enter the no. of copies:- ";
cin>>nocopy;
cout<<"\n Enter the year of edition:- ";
cin>>yredit;
cout<<"\n Enter the cost of book:- ";
cin>>cost;
}
void accept1()
{
cout<<"\n Enter the book title:- ";
fflush(stdin);
gets(bname);
cout<<"\n Enter the author's name:- ";
gets(aname);
cout<<"\n Enter the type of the book:- ";
gets(type);
cout<<"\n Enter the no. of copies:- ";
cin>>nocopy;
cout<<"\n Enter the year of edition:- ";
cin>>yredit;
cout<<"\n Enter the cost of the book:- ";
cin>>cost;
}
void read();
void search();
};
void write()
{
fstream f1("book.dat",ios::app|ios::binary);
book e;
e.accept();
f1.write((char*)&e,sizeof(e));
cout<<"\n RECORD ADDED
SUCCESSFULLY!!!!!!!!!!! \n";
f1.close();
}
void book::read()
{
clrscr();
fstream file;
file.open("book.dat",ios::in|ios::binary);
file.seekg(0);
int row=5, found=0, pageno=1;
gotoxy(18,1);
cout<<"\n LIST OF BOOKS";
gotoxy(1,3);
cout<<"\n BOOK NO. BOOK NAME AUTHOR'S
NAME TYPE EDITION SALE COST \n\n";
int count = 1;
while(file.read((char*)this,sizeof(book)))
{
count++;
delay(50);
found=1;
gotoxy(2,row);
cout<<bno;
gotoxy(14,row);
cout<<bname;
gotoxy(27,row);
cout<<aname;
gotoxy(42,row);
cout<<type;
gotoxy(55,row);
cout<<yredit;
gotoxy(66,row);
cout<<nocopy;
gotoxy(74,row);
cout<<cost;
if (row==23)
{
row=5;
gotoxy(66,1);
cout<<"Page no.: "<<pageno;
pageno++;
gotoxy(1,25);
cout<<"\n Press any key to continue...";
getch();
clrscr();
cout<<"\n LIST OF BOOKS";
gotoxy(1,5);
cout<<"\n BOOK NO. BOOK NAME
AUTHOR'S NAME TYPE EDITION SALE COST \n\n";
}
else{
row++;
}
}
if(!found)
{
gotoxy(1,5);
cout<<"\n Records not found";
}
gotoxy(66,1);
cout<<"\n Page no.: "<<pageno;
gotoxy(1,25);
cout<<"\n Press any key to continue...";
getch();
file.close();
}
void del2(int n)
{
clrscr();
fstream f1,f2;
f1.open("book.dat",ios::in|ios::binary);
f2.open("temp.dat",ios::out|ios::binary);
book e;
while(f1.read((char*)&e,sizeof(e)))
{
if(e.rbno()!=n)
f2.write((char*)&e,sizeof(e));
}
f1.close();
f2.close();
remove("book.dat");
rename("temp.dat","book.dat");
}
void update()
{
clrscr();
fstream f1("book.dat",ios::in|ios::out|ios::binary);
book e;
int n,flag=0,record=0;
cout<<"\n Enter book no. to be modified \n";
cin>>n;
while(f1.read((char*)&e,sizeof(e)))
{
if(e.rbno()==n)
{
flag=1;
break;
}
}
f1.close();
if(flag==0)
cout<<"\n Record not found!!!!!!!\n";
else{
del2(n);
fstream f2("book.dat",ios::app|ios::binary);
e.accept1();
f2.seekp(0);
f2.write((char*)&e,sizeof(e));
cout<<"\n\n\n\n Record modified successfully
\n\n\n";
f2.close();
}
}
void del()
{
clrscr();
fstream f1,f2;
f1.open("book.dat",ios::in|ios::binary);
f2.open("temp.dat",ios::out|ios::binary);
book e;
int n,flag=0;
cout<<"\n Enter book number to be deleted \n";
cin>>n;
while(f1.read((char*)&e,sizeof(e)))
{
if(e.rbno()!=n)
f2.write((char*)&e,sizeof(e));
else
flag=1;
}
if(flag)
cout<<"\n Record deleted!!!!!!!\n";
else
cout<<"\n Record not found!!!!!!\n";
f1.close();
f2.close();
remove("book.dat");
rename("temp.dat","book.dat");
}
void book::search()
{
clrscr();
fstream file;
file.open("book.dat",ios::in|ios::binary);
file.seekg(0);
int n;
cout<<"\n\n Enter the book number to be
searched \n";
cin>>n;
clrscr();
int row=5, found=0, pageno=1;
gotoxy(18,1);
cout<<"\n LIST OF BOOKS";
gotoxy(1,3);
cout<<"\n Book No. Book Name Author's Name
Type Edition Sale Cost \n\n";
while(file.read((char*)this,sizeof(book)))
{
if(bno==n)
{
delay(50);
found=1;
gotoxy(2,row);
cout<<bno;
gotoxy(14,row);
cout<<bname;
gotoxy(27,row);
cout<<aname;
gotoxy(42,row);
cout<<type;
gotoxy(55,row);
cout<<yredit;
gotoxy(66,row);
cout<<nocopy;
gotoxy(74,row);
cout<<cost;
if(row==23)
{
row=5;
gotoxy(66,1);
cout<<"Page no.:"<<pageno;
pageno++;
gotoxy(1,25);
cout<<"\n Press any key to continue...";
getch();
clrscr();
cout<<"\n LIST OF BOOKS";
gotoxy(1,5);
cout<<"\n Book No. Book Name Author's Name
Type Edition Sale Cost \n\n";
}
else
row++;
}
}
if(!found)
{
gotoxy(1,5);
cout<<"\n Records not found";
}
gotoxy(66,1);
cout<<"Page no.:"<<pageno;
gotoxy(1,25);
cout<<"\n Press any key to continue...";
getch();
file.close();
}
void mainmenu()
{
int ch;
char ch1;
book b;
do
{
clrscr();
cout<<"\n\t\t**************************************\n";
cout<<"\n\n\n\t\t MADE BY :";
delay(200);
cout<<" A ";
delay(100);
cout<<" k ";
delay(100);
cout<<" a ";
delay(100);
cout<<" n ";
delay(100);
cout<<" s ";
delay(100);
cout<<" h ";
delay(100);
cout<<" a ";
delay(100);
cout<<" ";
delay(100);
cout<<" G ";
delay(100);
cout<<" u ";
delay(100);
cout<<" p ";
delay(100);
cout<<" t ";
delay(100);
cout<<" a ";
delay(100);
cout<<" \n\n\t\t\t\t\t ";
delay(100);
cout<<"\n\t\t MAIN MENU \n";
cout<<"\n\t\t**************************************\n";
cout<<"\n\t\t 1. Add a record \n";
cout<<"\n\t\t 2. Display all the records \n";
cout<<"\n\t\t 3. Modify a record \n";
cout<<"\n\t\t 4. Search a record \n";
cout<<"\n\t\t 5. Delete a record \n";
cout<<"\n\t\t 6. Exit \n";
cout<<"\n\t\t**************************************\n";
cout<<"\n\t\t Enter your choice : \n";
cin>>ch;
switch(ch)
{
case 1:write();
break;
case 2:b.read();
break;
case 3:update();
break;
case 4:b.search();
break;
case 5:del();
break;
case 6:
clrscr();
gotoxy(7,10);
delay(200);
cout<<" T ";
delay(100);
cout<<" h ";
delay(100);
cout<<" a ";
delay(100);
cout<<" n ";
delay(100);
cout<<" k ";
delay(100);
cout<<" ";
delay(100);
cout<<" Y ";
delay(50);
cout<<" o ";
delay(100);
cout<<" u ";
delay(100);
cout<<" ";
delay(100);
cout<<" F ";
delay(100);
cout<<" o ";
delay(100);
cout<<" r ";
delay(100);
cout<<" ";
delay(100);
gotoxy(7,12);
cout<<" V ";
delay(100);
cout<<" i ";
delay(100);
cout<<" s ";
delay(100);
cout<<" i ";
delay(100);
cout<<" t ";
delay(100);
cout<<" i ";
delay(100);
cout<<" n ";
delay(100);
cout<<" g ";
delay(100);
cout<<" ";
delay(100);
cout<<" M ";
delay(100);
cout<<" y ";
delay(100);
cout<<" ";
delay(100);
cout<<" P ";
delay(100);
cout<<" r ";
delay(100);
cout<<" o ";
delay(100);
cout<<" j ";
delay(100);
cout<<" e ";
delay(100);
cout<<" c ";
delay(100);
cout<<" t ";
getch();
exit(0);
default:
cout<<"\n\n\n INVALID CHOICE \n\n\n";
}
cout<<"\n\n\n\n Do you wish to continue ? \n";
cin>>ch1;
}
while(ch1!='n');
}
int main()
{
clrscr();
cout<<"\n\n\n\n\n\n\n\t\t\t WELCOME TO MY
PROJECT ";
cout<<"\n\n\n\t\t\t BOOK MANAGEMENT SYSTEM ";
fflush(stdin);
getch();
return 0;
}