LIBRARY MANAGEMENT SYSTEM USING SINGLY LINK LIST

#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;
string BookName,StdName;
int countBook=0,countissuebook=0;
//structure of book
struct Book
{
string name;
Book*next= NULL;
}*head=NULL;
//structure of issuing  book
struct issuebook{
string stdname;
    string bookname;
    string issuedate;
    string duedate;
    int no_of_book_issued_to_student;
    issuebook *next; 
}*head1=NULL;
//insert a book
bool insertbook(string Name,char* time)
{
bool flag=false;
ofstream myfile("books.txt",ofstream::out | ofstream::app);
Book *newBook= new Book;
Book *temp;
countBook++;
newBook->name =Name;
newBook->next=NULL;
if(head==NULL)
{
head=newBook;
flag=true;
}
else
{
temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=newBook;
flag=true;


}
myfile<<newBook->name<<" Date and time "<<time<<endl;
myfile.close();
return flag;
}
//Search Book
bool Search(string bname)
{

bool flag=false;
ifstream myfile2("books.txt");
while(!myfile2.eof())
{
myfile2>>StdName;
if(StdName==bname)
{
flag=true;
break;
}
}
myfile2.close();
return flag;
}
// search student
bool Searchstd(string name)
{bool flag=false;
string Snme;
ifstream myfile("students.txt");

while(!myfile.eof()){
myfile>>Snme;
if(Snme==name)
{
flag=true;
break;
}

}
myfile.close();
return flag;
}
//search issue book
issuebook *SearchissueBook(string input)
{
bool flag=false;
issuebook *temp=head1;
for(int i=1;i<=countissuebook;i++)
{
if(temp->stdname==input)
{
flag=true;
break;
}
temp=temp->next;
}

if(flag==true)
{
return temp;
}
else
return NULL;
}
//time
char* current_time()   /// current time()
{
time_t now = time(0);
   time_t r=time(0);
   char* dt = ctime(&now);
   char* rt=ctime(&r);
   tm *gmtm = gmtime(&now);
   return dt;
}
//Issue Book to student
void IssueBook(string sname,string bname)
{
ofstream myfile1("issuebooks.txt",ofstream::out | ofstream::app);

bool flag=false;
issuebook *temp;
issuebook *Ibook=new issuebook;
issuebook *temp2;
// issuebook * Ibook= new issuebook;
temp2= SearchissueBook(sname);
if(Searchstd(sname) && Search(bname) && temp2==NULL)
{
cout<<" Student Found /n Book FOund "<<endl;

Ibook->no_of_book_issued_to_student=1;
Ibook->bookname=bname;
Ibook->stdname=sname;
Ibook->issuedate=current_time();
Ibook->next=NULL;
countissuebook++;
cout<<"Enter Due date: ";
cin>>Ibook->duedate;
if(head1==NULL)
{
head1=Ibook;
}
else
{
temp=head1;
while(temp->next!=NULL)
{
temp=temp->next;

}temp->next=Ibook;

}
Ibook->no_of_book_issued_to_student=1;
cout<<"Sucessfully ISsued!/n";
flag=true;


}



if(flag==true)
{
cout<<"Sucessfully issued \n";
myfile1<<"Student NAme: "<<Ibook->stdname<<" Book name: "<<Ibook->bookname<<" Issuedate: "<<current_time()<<endl;

}
else
cout<<"you have already issued a book \n";
myfile1.close();


}
//return Book
void ReturnBook(string name)
{
int DaysBookKept;
issuebook *temp=head1;
issuebook* temp2=NULL;
bool flag=false;
for(int i=0;i<countissuebook;i++)
{

if(temp->stdname==name)
{
cout<<"************************************************** \n";

cout<<temp->issuedate<<" was his issued dATE "<<endl;
cout<<"Due DAte of your book is "<<temp->duedate<<endl;
cout<<"************************************************** \n";
cout<<" Enter No of days kept"<<endl;
cin>>DaysBookKept;
temp2=temp;
if(DaysBookKept<=7 && DaysBookKept>=1)
{
countissuebook--;
flag=true;

}
else
{
cout<<" You have to pay fine \n";
cout<<(DaysBookKept-7)*100<<"  rupees"<<endl;
temp->no_of_book_issued_to_student=0;
flag=true;
countissuebook--;
return;

}
break;
}
temp=temp->next;
}

if(flag==true)
{
cout<<" Return sucessfuly \n";

}
else
{
cout<<"Invalid student name \n";
}
if(head1==NULL)
{
cout<<"No book issue \n";
}
else
{

temp2->next=temp->next;

delete temp;
cout<<"Book is also del from the list \n";
}
}
void display()
{
issuebook *temp1=NULL;
if(head1==NULL)
{
cout<<"NO book issued \n";
}
else
{temp1=head1;
while(temp1->next!=NULL)
{
cout<<temp1->bookname<<endl;
temp1=temp1->next;
}
cout<<temp1->bookname<<endl;
}
}
int main()
{
int choice;

    do
    {
    cout<<"*********************** \n";
    cout<<"  Library System \n";
    cout<<"*********************** \n";
    cout<<"1: Add Book \n";
    cout<<"2: Search Book \n";
    cout<<"3: Issue Book \n";
    cout<<"4: Return  Book \n";
        cout<<"5: display issue book \n";
    cout<<"6: Exit \n";
    cout<<"*********************** \n";
    cout<<"Enter Yur Choice: ";
    cin>>choice;
    switch(choice)
   
    {
    case 1:{

cout<<"Enter BOOK NAme:  ";
    cin>>BookName;
    if(insertbook(BookName,current_time()) )
    {
        cout<<"SuCeSsFullY ADDeD"<<endl;
}

    else
    {
    cout<<"Not added"<<endl;
}

   
    break;}
    case 2:
    {
    cout<<"EnTeR BooK NaMe:";
       cin>>BookName;
if(Search(BookName))
cout<<"BoOk found!\n";
else
cout<<"Not found!,InvaLiD BooK NaMe\n";
break;
}
case 3:
{
cout<<"Enter StUdEnT NaME :";
  cin>>StdName;
   cout<<"EnTeR BooK NaMe:";
    cin>>BookName;
  IssueBook(StdName,BookName);
  break;
}
case 4:
{cout<<"Enter StUdEnT NaME :";
   cin>>StdName;
   ReturnBook(StdName);
 
break;
}

case 5:{
display();
break;
}
case 6:
{
break;
}

default:
{
cout<<"Invalid Output! /n";
break;

}
}
}while(choice!=6);
return 0;
}

Comments

Popular posts from this blog

Computer Programming Lab 5

Computer Programming lab 11

Computer Programming Lab 4