Code/ Input:-
Include<fstream>
#include<conio.h>
#include<string.h>
#include<iomanip>
#include<iostream>
Using namespace std;
Class book
Char book_number[30];
Char book_name[50];
Char author_name[20];
Int num_copies;
Public:
Void get_book_details()
Cout<<”\nENTER DETAILS ABOUT BOOK U WANT TO
PURCHASE\n”;
Cout<<”\nEnter The Book Number: “;
Cin>>book_number;
Cout<<”\nEnter The Name of The Book: “;
Cin.ignore();
Cin.getline(book_name,50);
Cout<<”\nEnter The Author’s Name: “;
Cin.ignore();
Cin.getline(author_name,50);
Fflush(stdin);
Cout<<”\nEnter No. Of Copies : “;
Cin>>num_copies;
Void show_book()
Cout<<”\nBook Number: “<<book_number;
Cout<<”\nBook Name: “<<book_name;
Cout<<”\nAuthor’s Name: “<<author_name;
Cout<<”\nCOPIES : “<<num_copies;
Void modify_book()
Cout<<”\nBook number : “<<book_number;
Cout<<”\nModify Book Name : “;
Cin.ignore();
Cin.getline(book_name,50);
Cout<<”\nModify Author’s Name: “;
Cin.ignore();
Cin.getline(author_name,50);
Fflush(stdin);
Cout<<”\nEnter No. Of Copies : “;
Cin>>num_copies;
}
Char* getbooknumber()
Return book_number;
Void report()
{cout<<book_number<<setw(30)<<book_name<<setw(30)<<author_nam
e<<setw(30)<<num_copies<<endl;}
};
Fstream fp;
Book bk;
Void write_book()
System(“cls”);
Int more_or_main;
Fp.open(“book.dat”,ios::out|ios::app);
Do
Bk.get_book_details();
Fp.write((char*)&bk,sizeof(book));
Cout<<”\nPress 1 to add more books.”;
Cout<<”\nPress 2 to return to main menu.\n”;
Cout<<”Enter: “;
Cin>>more_or_main;
}while(more_or_main == 1);
Fp.close();
Void display_a_book(char n[])
System(“cls”);
Cout<<”\nBOOK DETAILS\n”;
Int check=0;
Fp.open(“book.dat”,ios::in);
While(fp.read((char*)&bk,sizeof(book)))
If(strcmpi(bk.getbooknumber(),n)==0)
Bk.show_book();
Check=1;
Fp.close();
If(check==0)
Cout<<”\n\nBook does not exist”;
Getch();
Void modify_book()
{
System(“cls”);
Char n[20];
Int found=0;
Cout<<”\n\n\tMODIFY BOOK”;
Cout<<”\n\n\tEnter The book number: “;
Cin>>n;
Fp.open(“book.dat”,ios::in|ios::out);
While(fp.read((char*)&bk,sizeof(book)) && found==0)
If(strcmpi(bk.getbooknumber(),n)==0)
Bk.show_book();
Cout<<”\nEnter The New Details of book”<<endl;
Bk.modify_book();
Int pos=-1*sizeof(bk);
Fp.seekp(pos,ios::cur);
Fp.write((char*)&bk,sizeof(book));
Cout<<”\n\n\t Record Updated Successfully…”;
Found=1;
Fp.close();
If(found==0)
Cout<<”\n\n Record Not Found “;
Getch();
}
Void delete_book()
System(“cls”);
Char n[20];
Int flag=0;
Cout<<”\n\n\n\tDELETE BOOK”;
Cout<<”\n\nEnter The Book’s number You Want To Delete: “;
Cin>>n;
Fp.open(“book.dat”,ios::in|ios::out);
Fstream fp2;
Fp2.open(“Temp.dat”,ios::out);
Fp.seekg(0,ios::beg);
While(fp.read((char*)&bk,sizeof(book)))
If(strcmpi(bk.getbooknumber(),n)!=0)
Fp2.write((char*)&bk,sizeof(book));
Else
Flag=1;
Fp2.close();
Fp.close();
Remove(“book.dat”);
Rename(“Temp.dat”,”book.dat”);
If(flag==1)
Cout<<”\n\n\tRecord Deleted ..”;
Else
Cout<<”\n\nRecord not found”;
Getch();
Void display_allb()
System(“cls”);
Fp.open(“book.dat”,ios::in);
If(!fp)
Cout<<”ERROR!!! FILE COULD NOT BE OPEN “;
Getch();
Return;
Cout<<”\n\n\t\tBook LIST\n\n”;
Cout<<”=========================================
==============================================
=====\n”;
Cout<<”Book Number”<<setw(20)<<”Book
Name”<<setw(25)<<”Author”<<setw(25)<<”Copies”<<endl;
Cout<<”=========================================
==============================================
=====\n”;
While(fp.read((char*)&bk,sizeof(book)))
Bk.report();
}
Fp.close();
Getch();
Void intro()
System(“color 06”);
System(“cls”);
Cout<<”\t\t\t\t*\t*”;
Cout<<”\t\t\t\t**\t**”;
Cout<<”\t\t\t\t***\t***”;
Cout<<”\t\t\t\t****\t****”;
Cout<<”\t\t\t\t*****\t*****”;
Cout<<”\t\t\t\t******\t******”;
Cout<<”\t\t\t\t*******\t*******”;
Cout<<”\t\t\t\t*******\t*******”;
Cout<<”\t\t\t\t******\t******”;
Cout<<”\t\t\t\t*****\t*****”;
Cout<<”\t\t\t\t****\t****”;
Cout<<”\t\t\t\t***\t***”;
Cout<<”\t\t\t\t**\t**”;
Cout<<”\t\t\t\t*\t*”;
Int main()
{
Int option = 0;
For(;;)
Intro();
Cout<<”\t\
t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@”;
Cout<<”\n\t\tPress 1 to TO BUY”;
Cout<<”\n\t\tPress 2 to SHOW ALL BOOKS”;
Cout<<”\n\t\tPress 3 to CHECK AVAILABILITY”;
Cout<<”\n\t\tPress 4 to MODIFY BOOKS”;
Cout<<”\n\t\tPress 5 to DELETE BOOKS”;
Cout<<”\n\t\tPress 6 to Exit”;
Cout<<”\n\t\
t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@\n”;
Cout<<”\n\t\tOption: “;
Cin>>option;
Switch(option)
Case 1: system(“cls”);
Write_book();
Break;
Case 2: display_allb();
Break;
Case 3:
Char num[20];
System(“cls”);
Cout<<”\n\n\tPlease Enter The book No. “;
Cin>>num;
Display_a_book(num);
Break;
Case 4: modify_book();break;
Case 5: delete_book();break;
Case 6: exit(0);
Break;
Default:cout<<”\a”;
Output:-