0% found this document useful (0 votes)
34 views15 pages

Group Task

This document provides details for a library management system, including classes for books, members, and a library. It defines classes for fiction and non-fiction books, with members able to borrow and return books from the library. The main function demonstrates adding books to the library and allows a member to borrow, return, and view borrowed books.

Uploaded by

talaltariq15437
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views15 pages

Group Task

This document provides details for a library management system, including classes for books, members, and a library. It defines classes for fiction and non-fiction books, with members able to borrow and return books from the library. The main function demonstrates adding books to the library and allows a member to borrow, return, and view borrowed books.

Uploaded by

talaltariq15437
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

AIR UNIVERSITY AEROSPACE AND AVIATION

CAMPUS KAMRA

SUBMITTED BY:
KHAWAJA MOIN UDDIN 235137
TALAL TARIQ 235154

SUBMITTED TO:
MUHAMMAD KAMRAN
Code:
#include<iostream>
#include<vector>
#include<ctime>
#include<windows.h>
#include<cstdlib>
#include<conio.h>
using namespace std;
void loading()
{
cout<<"Loading..."<<endl;
for(int i=0;i<15;i++)
{
cout<<"*";
Sleep(100);
}
cout<<endl;
}
class Book
{
protected:
string title;
string author;
string isbn;
bool isavailable;
public:
Book(string title=" ",string author=" ",string isbn=" ")
{
this->title=title;
this->author=author;
this->isbn;
isavailable=true;
}
virtual string get_details()
{
string s,available;
available=(this->isavailable)?"True":"False";
s="Title: "+title+"\t\tAuthor: "+author+"\tISBN: "+isbn+"\
tAvaliable: "+available;
return s;
}
bool getavailablity()
{
return isavailable;
}
string getISBN()
{
return isbn;
}
virtual void borrow_book()=0;
virtual void return_book()=0;
};

class Fiction : public Book


{
private:
string genre;
public:
Fiction(string title=" ",string author=" ",string isbn=" ",string genre="
")
{
this->title=title;
this->author=author;
this->isbn=isbn;
this->genre=genre;
}
string get_details()
{
string s;
s= Book::get_details()+" Genre: "+genre;
return s;
}
void borrow_book() override
{
isavailable=false;
cout<<"Book is Borrowed successfully"<<endl;
}
void return_book() override
{
isavailable=true;
cout<<"Book is Returned Succcessfully"<<endl;
}
};

class NonFiction : public Book


{
private:
string category;
public:
NonFiction(string title=" ",string author=" ",string isbn=" ",string
category=" ")
{
this->title=title;
this->author=author;
this->isbn=isbn;
this->category=category;
}
string get_details()
{
string s;
s= Book::get_details()+" Category: "+category;
return s;
}
void borrow_book() override
{
isavailable=false;
cout<<"Book is Borrowed successfully"<<endl;
}
void return_book() override
{
isavailable=true;
cout<<"Book is Returned Succcessfully"<<endl;
}

};
class Member
{
private:
string name;
string id;
vector<Book*> borrowedbooks;

int find_book(Book *book)


{
for(int i=0;i<borrowedbooks.size();i++)
{
if(book == borrowedbooks[i])
{
cout<<"Found at index "<<i+1<<endl;
return i;
}
}
cout<<"Not Avaliable"<<endl;
return -1;
}
public:
Member(string name=" ",string id=" ")
{
this->name=name;
this->id=id;
}
void set_values()
{
cout<<"Enter Your Name = ";
getline(cin,name);
srand(time(0));
int id=rand()%1000;
this->id=to_string(id);
cout<<"Your Member id = "<<id<<endl;
}
string get_details()
{
string s;
s="Name: "+name+" Member ID: "+id;
return s;
}
void list_of_books()
{
for(int i=0;i<borrowedbooks.size();i++)
cout<<borrowedbooks[i]->get_details()<<endl;
}
Book* findbook(string target_isbn)
{
for(int i=0;i<borrowedbooks.size();i++)
{
if(target_isbn == borrowedbooks[i]->getISBN())
{
cout<<"Found at index "<<i+1<<endl;
return borrowedbooks[i];
}
}
return nullptr;
}
void borrow_book(Book* book)
{
if(book->getavailablity())
{
borrowedbooks.push_back(book);
book->borrow_book();
}
}
void return_book(Book *book)
{
int index=find_book(book);
if(index!=-1)
{
borrowedbooks.erase(borrowedbooks.begin()+index);
book->return_book();
}
else
cout<<"Not Available"<<endl;
}
};
class Library
{
public:
vector<Book*> book;
vector<Member*> mem;
Library(){};
void list_of_available_books()
{
cout<<"\a***List of Books***"<<endl;
for(int i=0;i<122;i++)
cout<<"-";
cout<<endl;
for(int i=0;i<book.size();i++)
// if(book[i]->getavailablity())
// {
cout<<book[i]->get_details()<<endl;
// }
for(int i=0;i<122;i++)
cout<<"-";
cout<<endl;
}
void addbook(Book *b)
{
this->book.push_back(b);
}
void removebook(int index)
{
if(index<book.size())
{
book.erase(book.begin()+index);
cout<<"Remove Successfully"<<endl;
}
else
cout<<"\a*invalid Selection*"<<endl;
}
Book* findbook(string target_isbn)
{
for(int i=0;i<book.size();i++)
{
if(target_isbn == book[i]->getISBN())
{
cout<<"Found at index "<<i<<endl;
return book[i];
}
}
cout<<"Not Avaliable"<<endl;
return nullptr;
}
void issueBook(Member* member,Book* book)
{
member->borrow_book(book);
}
void return_book(Member *member,Book *book)
{
member->return_book(book);
}
};
int main()
{
Library l;
l.addbook(new Fiction("Harry Potter Sorcerer's Stone", "J.K. Rowling", "180", "Fantasy"));

l.addbook(new Fiction("Harry Potter Prisoner of Azkaban", "J.K. Rowling", "358", "Fantasy"));


l.addbook(new Fiction("1984 ", "George Orwell", "935", "Dystopian Fiction"));

l.addbook(new Fiction("To Kill a Mockingbird ", "Harper Lee", "084", "Southern Gothic"));

l.addbook(new Fiction("The Great Gatsby ", "F. Scott ", "565", "Tragedy"));

l.addbook(new NonFiction("A Brief History of Humankind", "Yuval Harari", "097", "History"));

l.addbook(new NonFiction("Educated: A Memoir ", "Tara Westover", "504", "Memoir"));

l.addbook(new NonFiction("The Power of Habit ", "Charles Duhigg", "605", "Self-Help"));

l.addbook(new NonFiction("The Immortal Life ", "Rebecca Skloot", "189", "Biography"));

l.addbook(new NonFiction("Becoming ", "Michelle Obama", "138", "Memoir"));

// l.list_of_available_books();

cout<<"***Welcome to your literary haven!***"<<endl;


Member m1;
m1.set_values();
string choice;

while(true)
{
loading();
system("cls");
cout<<m1.get_details()<<endl;
cout<<"1. Borrow Book"<<endl;
cout<<"2. Return Book"<<endl;
cout<<"3. Show borrowed Books"<<endl;
cout<<"4. Exit"<<endl;
cout<<"Enter Choice: ";
cin>>choice;
if(choice=="1")
{
string isbn;
l.list_of_available_books();
cout<<"Select book by ISBN: ";
cin>>isbn;
Book *book=l.findbook(isbn);
m1.borrow_book(book);
}
else if(choice=="2")
{
string isbn;
m1.list_of_books();
cout<<"Select book by ISBN: ";
cin>>isbn;
Book *book=l.findbook(isbn);
m1.return_book(book);
}
else if(choice =="3")
{
m1.list_of_books();
char key=_getch(); // wait until any key is pressed
}
else
exit(0);

You might also like