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<[Link]();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<[Link]();i++)
cout<<borrowedbooks[i]->get_details()<<endl;
}
Book* findbook(string target_isbn)
{
for(int i=0;i<[Link]();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)
{
[Link]([Link]()+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<[Link]();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<[Link]())
{
[Link]([Link]()+index);
cout<<"Remove Successfully"<<endl;
}
else
cout<<"\a*invalid Selection*"<<endl;
}
Book* findbook(string target_isbn)
{
for(int i=0;i<[Link]();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;
[Link](new Fiction("Harry Potter Sorcerer's Stone", "J.K. Rowling", "180", "Fantasy"));
[Link](new Fiction("Harry Potter Prisoner of Azkaban", "J.K. Rowling", "358", "Fantasy"));
[Link](new Fiction("1984 ", "George Orwell", "935", "Dystopian Fiction"));
[Link](new Fiction("To Kill a Mockingbird ", "Harper Lee", "084", "Southern Gothic"));
[Link](new Fiction("The Great Gatsby ", "F. Scott ", "565", "Tragedy"));
[Link](new NonFiction("A Brief History of Humankind", "Yuval Harari", "097", "History"));
[Link](new NonFiction("Educated: A Memoir ", "Tara Westover", "504", "Memoir"));
[Link](new NonFiction("The Power of Habit ", "Charles Duhigg", "605", "Self-Help"));
[Link](new NonFiction("The Immortal Life ", "Rebecca Skloot", "189", "Biography"));
[Link](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=[Link](isbn);
m1.borrow_book(book);
}
else if(choice=="2")
{
string isbn;
m1.list_of_books();
cout<<"Select book by ISBN: ";
cin>>isbn;
Book *book=[Link](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);