Savishree

Honorable
Apr 1, 2012
1
0
10,510
#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
//using namespace std;


//books in library linked list

typedef struct node
{
int book_no;
char title[20];
char author[20];
struct node *link;
};

class list
{
public:
node *addBooks(node *head,int ele,char title[20],char author[20]);
node *deleteBooks(node * head,int ele);
void display(node *head);
int check(node *head,int ele);
};

//add the books in book store

int list::check(node *head,int ele)
{
node *temp;
int numb;
for(temp=head;temp!=NULL;temp=temp->link)
{
if(temp->book_no==ele)
{
numb=1;
}else{
numb=0;
}
}
return numb;
}
node *list::addBooks(node *head,int ele,char title[20],char author[20])
{
node *New,*temp;
New=(node*)malloc(sizeof(node));
New->book_no=ele;
strcpy(New->title,title);
strcpy(New->author,author);
New->link=NULL;

int flag=0;

if(head==NULL)
{
head=New;
cout<<"The Book is successfully added\n\n\n";

}else{

for(temp=head;temp!=NULL;temp=temp->link)
{
if(temp->book_no==ele)
{
flag=1;
}
}
if(flag==1)
{
cout<<"Book already exists\n\n\n";

}else{
temp=head;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=New;
cout<<"The Book is successfully added\n\n\n";

}
}

return head;
}

//Delete tyhe books in book store
node *list::deleteBooks(node *head, int ele)
{
node *temp,*temp1;
int flag=0;

if(head==NULL)
{
cout<<"No books are there in library\n\n\n";

}else if(head->book_no==ele)
{
flag=1;
cout<<"The book deleted is\t"<<head->title<<"\n\n\n";
temp=head;
head=head->link;
temp->link=NULL;
free(temp);

}
for(temp=head;temp!=NULL;temp=temp->link)
{
temp1=temp->link;
if(temp1->book_no==ele)
{
flag=1;
cout<<"The book deleted is\t"<<temp1->title<<"\n\n\n";

temp->link=temp1->link;
temp1->link=NULL;
free(temp1);

}
}

if (flag==0)
{
cout<<"The book number does not exists \n\n\n";

}
return head;
}

//display the books in the book store

void list::display(node *head)
{
node *temp;
if(head==NULL)
{
cout<<"List is empty \n\n\n";

}else{
cout<<"Book Number \t Book title \t Book author \n\n\n";
for(temp=head;temp!=NULL;temp=temp->link)
{
cout<<temp->book_no<<"\t\t\t";
cout<<temp->title<<"\t\t\t";
cout<<temp->author<<"\n\n";
}
}
}

//ordered book linked list

typedef struct node1
{
int book_no;
int regno;
char title[20];
char author[20];
char stud_name[30];
struct node1 *link;
};
class Order_list
{
public:
node1 *addOrder(node1 *head,int ele, char title[20],char author[20],int regno ,char stud_name[30]);
node1 *deleteOrder(node1 *head,int ele,int regno);
void display(node1 *head);
};

//add the student orders
node1 *Order_list::addOrder(node1 *head,int ele,char title[20],char author[20],int regno,char stud_name[20])
{
node1 *New,*temp;

New=(node1*)malloc(sizeof(node1));
New->book_no=ele;
strcpy(New->title,title);
strcpy(New->author,author);
New->regno=regno;
strcpy(New->stud_name,stud_name);
New->link=NULL;

int flag=0;

if(head==NULL)
{
head=New;
cout<<"The Book is successfully added\n";
}else{
for(temp=head;temp!=NULL;temp=temp->link)
{
if(temp->book_no==ele && temp->regno==regno)
{
flag=1;
}
}
if(flag==1)
{
cout<<"The order already exists \n\n\n";

}else{
temp=head;
while(temp->link!=NULL)
{
temp=temp->link;
}
temp->link=New;
cout<<"The order is successfully added\n\n\n";
}

}


return head;
}

//Delete the order on return of the book.

node1 *Order_list::deleteOrder(node1 *head, int ele,int regno)
{
node1 *temp,*temp1;
int flag=0;

if(head==NULL)
{
cout<<"No orders taken\n\n\n";

}else if(head->book_no==ele && head->regno==regno)
{
flag=1;
cout<<"The order deleted is\t"<<head->title<<"and was taken by\t"<<head->stud_name<<"\n\n\n";
temp=head;
head=head->link;
temp->link=NULL;
free(temp);

}
for(temp=head;temp!=NULL;temp=temp->link)
{
temp1=temp->link;
if(temp1->book_no==ele && temp1->regno==regno)
{
flag=1;
cout<<"The order deleted is\t"<<temp1->title<<"and was taken by\t"<<temp1->stud_name<<"\n\n\n";
temp->link=temp1->link;
temp1->link=NULL;
free(temp1);

}
}
if(flag==0)
{
cout<<"The entered order doesnot exist \n\n\n";

}

return head;
}

//Display the books in the book store


void Order_list::display(node1 *head)
{
node1 *temp;
if(head==NULL)
{
cout<<"List is Empty\n";
}else{
cout<<"Book Number\tBook Title\t BookAuthor\t Regno\t Student Name\n\n\n";
for(temp=head;temp!=NULL;temp=temp->link)
{
cout<<temp->book_no<<"\t\t\t";
cout<<temp->title<<"\t\t\t";
cout<<temp->author<<"\t\t\t";
cout<<temp->regno<<"\t\t\t";
cout<<temp->stud_name<<"\n\n\n";
}
}
}

//main class

int main()
{
clrscr();
node *head=NULL;
node1 *head1=NULL;
list ls;
Order_list ol;
int ch,ch1,ch2,book_no,regno,ele;
char title[20],author[20],author1[20],stud_name[20];


do
{ cout<<" *****Library Management System*****\n\n\n";
cout<<"1.Admin\n";
cout<<"2.Student\n";
cout<<"3.Exit\n";
cout<<"Enter your choice\n";
cin>>ch;
switch(ch)
{
case 1: do
{
cout<<"1.Add new Book in library\n";
cout<<"2.Delete a Book from the library\n";
cout<<"3.Display all the books in the library\n";
cout<<"4.View the orders of the student\n";
cout<<"5.Exit\n";
cout<<"Enter your choice\n";
cin>>ch1;
switch(ch1)
{
case 1:cout<<"Enter the book number\n";
cin>>ele;
cout<<"Enter the book title\n";
cin>>title;
cout<<"Enter the author name\n";
cin>>author1;
head=ls.addBooks(head,ele,title,author1);
break;
case 2:cout<<"Enter the book number to delete the book\n";
cin>>ele;
head=ls.deleteBooks(head,ele);
break;
case 3:ls.display(head);
break;
case 4:eek:l.display(head1);
break;
case 5:
break;
default:cout<<"Invalid choice\n";
break;
}
}while(ch1!=5);
break;
case 2:do
{
cout<<"1.Rent the book\n";
cout<<"2.Return the book\n";
cout<<"3.display all the books in the library\n";
cout<<"4.View the Orders of the student\n";
cout<<"5.Exit\n";
cout<<"Enter your choice\n";
cin>>ch2;
switch(ch2)
{
case 1:cout<<"Enter the book number\n";
cin>>ele;
cout<<"Enter the book title\n";
cin>>title;
cout<<"Enter the book author\n";
cin>>author;
cout<<"Enter the Register number\n";
cin>>regno;
cout<<"Enter the student Name\n";
cin>>stud_name;
int numb=ls.check(head,ele);
if(numb==0)
{
cout<<"Specified Book doesnot exists in the library\n\n\n";
}else{
head1=ol.addOrder(head1,ele,title,author,regno,stud_name);
}

break;
case 2:
cout<<"Enter the book number to delete the book\n";
cin>>ele;
cout<<"Enter the Regno\n";
cin>>regno;
head1=ol.deleteOrder(head1,ele,regno);
break;
case 3:ls.display(head);
break;
case 4:eek:l.display(head1);
break;
case 5:
break;
default:cout<<"Invlaid Choice\n";
break;

}
}while(ch2!=5);
break;
case 3:exit(0);
break;
default:cout<<"Invlaid choice\n";
break;
}
}while(ch!=3);

return 0;
}