Skip to content

library #4432

@NESRAINJH

Description

@NESRAINJH

#include
using namespace std;
#include
#include
class Book
{
private:
int id;
string titel;
string author;
long year;
bool isAvailable ;
public:
Book(long i, string t, string a, long y, bool av)
{
id = i;
titel = t;
author = a;
year = y;
isAvailable = av;
}
void borowBook()
{
if (isAvailable = false)
{
cout<<"The book is borrowed"<<endl;
}

}
void returnBook()
{
    if (isAvailable = true)
    {
        cout<<"The book is returned"<<endl;
    }
}
bool getIsAvailable()
{
    return isAvailable;
}
void display()
{
    cout<<"ID: "<<id<<endl;
    cout<<"Title: "<<titel<<endl;
    cout<<"Author: "<<author<<endl;
    cout<<"Year: "<<year<<endl;
    cout<<"Availability: "<<(isAvailable?"Available":"Not Available")<<endl;
}
int getId()
{
    return id;
}

};
class member
{
private:
int id;
string name;
string address;
public:
member(int i, string n, string a)
{
id = i;
name = n;
address = a;
}
void displayRemember()
{
cout<<"ID: "<<Id<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Address: "<<address<<endl;
}
int getMemberId()
{
return Id;
}
};
class library
{
private:
vector books;
vector members;
public:
void addBook(Book& book)
{
books.push_back(book);
}
void addMember(member& member)
{
members.push_back(member);
}
void displayAllBooks()
{
cout<<"All Books:"<<endl;
for(auto & book: books)
{
book.display();
}
}
void displayAllMembers()
{
cout<<"All Members:"<<endl;
for(auto & member: members)
{
member.displayRemember();
}
}
void borrowBook( int bookId)
{
for(auto &book : books)
{
if(book.getId() == bookId)
{
if(book.getIsAvailable())
{
b.borowBook();
cout<<"Book borrowed successfully"<<endl;
}
else
{
cout<<"Book is not available"<<endl;
return;
}

             }
             else
             {
                 cout<<"Book  not found \n "<<endl;
             }
         }

     }
     
     
        void returnBook( int bookId)
        {
            for(auto & book : books)
            {
                if(book.getId() == bookId)
                {
                  
                            book.returnBook();
                            cout<<"Book returned successfully"<<endl;
                            return;
                        
                    
                }
            }
            cout<<"Book  not found.....\n"<<endl;
        }

};
int main()

{
library l;
l.addBook(Book(1, "C++", "Author1", 2000, true));
l.addBook(Book(2, "Java", "Author2", 2010, true));
l.addMember(Member(1, "John", "Address1"));
l.addMember(Member(2, "Jane", "Address2"));
cout<<"Library Management System"<<endl;
l.displayAllBooks();
l.displayAllMembers();
l.borowBook(1, 1);
cout<<"-------BOROWING A BOOK------------"<<endl;
l.borowBook(2, 2);
l.returnBook(1, 1);
l.returnBook(2, 2);
cout<<"-------RETURNED A BOOK------------"<<endl;
l.displayAllBooks();
l.displayAllMembers();

return 0;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions