class students:private person{
int roll;
string clas;
string address;
vector<string> borrowed_books; // book that student borrows wil get store in
thi vector
public:
void get(){
person::get(); // call get function of person class to get name and email
id
cout<<"Enter Roll No :"; cin>>roll; cin.ignore();
cout<<"Enter Class :"; getline(cin,clas);
cout<<"Enter Address :"; getline(cin,address);
}
void borrow_book(const string& book_name) { // function to add book that
studetnt requests
if (borrowed_books.size() >= 3) {
cout << "Borrow limit reached!\n";
return;
}
if( check_availability(book_name)){
cout<<"Book is out of stock in library\n";
return;
}
borrowed_books.push_back(book_name);
cout << "Book borrowed successfully!\n";
}
void show_borrowed_books() {
cout << "Borrowed Books:\n";
cout<<"-----------------------------------\n"
for (const auto& book : borrowed_books) {
cout<<left<<"| "book << " | "
}
cout << "\n-----------------------------------\n";
cout<<"Total borrowed books : "<<borrowed_books.size()<<endl;
}
void return_book(const string& book_name){
auto it = find(borrowed_books.begin(), borrowed_books.end(), book_name);
if (it != borrowed_books.end()) {
borrowed_books.erase(it);
book::increase_stock
cout << "Book returned successfully!\n";
} else {
cout << "Book not found in borrowed list.\n";
}
}
};
class book{
string name; string author; float price;
int pages; int isbn; string publication; int stock;
public:
book(string n="",string a="",float p=0,int pg=0,int i=0,string pub="",int
s=0):name(n),author(a),price(p),pages(pg),isbn(i),publication(pub),stock(s){}
friend class admin; // admin can access all data of book class
void show(const vector<book>& library) {
cout<<"--------------------------------------------------
LIBRARY-----------------------------------------------\n";
cout <<
"|---------------------------------------------------------------------------------
----------------------------|\n";
cout << left << setw(28) << "| BOOK NAME" << setw(25) << "AUTHOR NAME" <<
setw(15) << "PRICE" << setw(15) << "ISBN" << setw(15) << "PAGES" << setw(25)<<
"PUBLICATION " << "stock |" << endl;
cout <<
"|---------------------------------------------------------------------------------
----------------------------|\n";
for (int i = 0; i < library.size(); i++) { // index based loop
cout<<"| "<<left<<setw(25) << library[i].name << setw(25) <<
library[i].author << setw(15) << library[i].price << setw(15) << library[i].isbn <<
setw(15) << library[i].pages << setw(25) << library[i].publication <<
library[i].stock << endl;
}
cout << "\
n|---------------------------------------------------------------------------------
----------------------------|\n";
}
bool check_availability(const string& book_name, const vector<book>& library) {
// Check if the book is available in the library
// and if there are copies available for borrowing
for (const auto& book : library) {
if (book.name == book_name && book.stock > 0) {
return true;
}
}
return false;
}
book increase_stock
};
// A cas estudy how to interrelate classes