In: Computer Science
Create initializer/constructor functions for book. Declare and implement functions like insert book(insert at End, InsertAtFirst), retrieve book, update book information book using ISBN number in Library. Declare another function named Search to find a specific book from catalogue.
#include<iostream.h> #include<conio.h> struct book{ char name[50]; int ISBN; char authorname[50]; char publishername[50]; int issuedate; int issuemonth; int issueyear; int retdate; int retmonth; int retyear; struct book *next=NULL; } void insert(struct book *head){ if *head.next==NULL{ struct book node; cout<<"enter the name of book"; gets(node.name) cout<<"enter the author name of book"; gets(node.authorname) cout<<"enter the publisher name of book"; gets(node.publishername) cout<<"enter isbn no."; cin>>node.ISBN; cout<<"enter the issue date month and year"; cin>>node.issuedate; cin>>node.issuemonth; cin>>node.issueyear; cout<<"enter the return date month and year"; cin>>node.retdate; cin>>node.retmonth; cin>>node.retyear; *head.next=&node; } else{ insert(*head.next); } } void main(){ //the pile of the books will be stored in a linked list where ISBN no. can be a searching key struct book library;//first book in library insert(library);//inserting a book in library insert(library);//inserting a book in library getch(); }
Create initializer/constructor functions for book. Declare and
implement functions like insert book(insert at End,
InsertAtFirst),
retrieve book, update book information book using ISBN number in
Library. Declare another function named Search to find a specific
book from catalogue.
#include<iostream.h>
#include<conio.h>
struct book
{
book()
{
int i=0;
}
char name[50];
int ISBN;
char authorname[50];
char publishername[50];
int issuedate;
int issuemonth;
int issueyear;
int retdate;
int retmonth;
int retyear;
struct book *next=NULL;
};
struct book *Library;
int count;
void InsertAtFirst (struct book B)
{
struct book *node;
if(count==0)
{
Library=(struct book
*)(malloc(sizeof(struct book)));
node=Library;
}
else
{
node=(struct book
*)(malloc(sizeof(book)));
}
cout<<"enter the name of book";
gets(node->name)
cout<<"enter the author name of
book";
gets(node->authorname)
cout<<"enter the publisher name of
book";
gets(node->publishername)
cout<<"enter isbn no.";
cin>>node->ISBN;
cout<<"enter the issue date month and
year";
cin>>node->issuedate;
cin>>node->issuemonth;
cin>>node->issueyear;
cout<<"enter the return date month and
year";
cin>>node->retdate;
cin>>node->retmonth;
cin>>node->retyear;
if(count==0)
{
count+=1;
Library->next=NULL;
}
else
{
node->next=Library;
count+=1;
Library=node;
}
}
void InsertAtEnd(struct book B)
{
struct book *node,*ptr;
ptr=Library;
while(ptr->next!=NULL)
{
ptr=ptr->next;
}
node=(struct book *)malloc(sizeof(struct
book));
cout<<"enter the name of book";
gets(node->name);
cout<<"enter the author name of
book";
gets(node->authorname);
cout<<"enter the publisher name of
book";
gets(node->publishername);
cout<<"enter isbn no.";
cin>>node->ISBN;
cout<<"enter the issue date month and
year";
cin>>node->issuedate;
cin>>node->issuemonth;
cin>>node->issueyear;
cout<<"enter the return date month and
year";
cin>>node->retdate;
cin>>node->retmonth;
cin>>node->retyear;
node->next=NULL;
ptr->next=node;
count+=1;
}
void searchbook(int num)
{
struct book *ptr;
ptr=Library;
while(ptr!=NULL)
{
if(ptr->ISBN==num)
{
cout<<"Name "<<ptr-name<<endl;
cout<<"Author name
"<<ptr->authorname<<endl;
cout<<"Issue date
"<<ptr->issuedate<<"/"<<ptr->issuemonth<<"/"<<ptr->issueyear<<endl;
cout<<"Rent date
"<<ptr->retdate<<"/"<<ptr->retmonth<<"/"<<ptr->retyear<<endl;
return ;
}
ptr=ptr->next;
}
cout<<"Not found in
Library"<<endl;
}
void retrievebook(int num)
{
struct book *ptr;
ptr=Library;
while(ptr!=NULL)
{
if(ptr->ISBN==num)
{
cout<<"Name "<<ptr-name<<endl;
cout<<"Author name
"<<ptr->authorname<<endl;
cout<<"Issue date
"<<ptr->issuedate<<"/"<<ptr->issuemonth<<"/"<<ptr->issueyear<<endl;
cout<<"Rent date
"<<ptr->retdate<<"/"<<ptr->retmonth<<"/"<<ptr->retyear<<endl;
return ;
}
ptr=ptr->next;
}
}
void updatebook(int num)
{
struct book *ptr;
ptr=Library;
while(ptr!=NULL)
{
if(ptr->ISBN==num)
{
cout<<"Enter number to update info "<<endl;
cout<<"Enter 1 for update book name '\n' 2 for update ISBN
'\n' 3 for update author name '\n' 4 for updating issue date '\n' 5
for ret date"<<endl;
switch(a)
{
case 1:
char str[50];
cout<<"Enter new book name"<<endl;
cin>>str;
ptr->name=str;
case 2:
cout<<"enter new ISBN number"<<endl;
int isbn;
cin>>isbn;
ptr->ISBN=isbn;
case 3:
char s[50];
cout<<"Enter new Author name"<<endl;
cin>>s;
ptr->authorname=s;
case 4:
cout<<"enter new issue date"<<endl;
int a,b,c;
cin>>a;
cin>>b;
cin>>c;
ptr->issuedate=a;
ptr->issuemonth=b;
ptr->issueyear=c;
case 5:
cout<<"enter new return date"<<endl;
int a,b,c;
cin>>a;
cin>>b;
cin>>c;
ptr->retdate=a;
ptr->retmonth=b;
ptr->retyear=c;
}
return;
}
ptr=ptr->next;
}
}
void main()
{
count=0;
//the pile of the books will be stored in a
linked list where ISBN no. can be a searching key
struct book library; //first
book in library
InsertAtFirst(library); //inserting
a book in library
InsertAtEnd(library);
//inserting a book in library
getch();
}