-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.cpp
More file actions
45 lines (40 loc) · 1.76 KB
/
book.cpp
File metadata and controls
45 lines (40 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "book.h"
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
// Constructor correctly initializes private members
Book::Book(int id, string title, string author, string publisher, string isbn, int year, string status, int borrowerId)
: id(id), title(title), author(author), publisher(publisher), isbn(isbn), year(year), status(status), borrowerId(borrowerId) {}
// Getters for accessing private members
int Book::getId() const { return id; }
string Book::getTitle() const { return title; }
string Book::getAuthor() const { return author; }
string Book::getPublisher() const { return publisher; }
string Book::getISBN() const { return isbn; }
int Book::getYear() const { return year; }
string Book::getStatus() const { return status; }
int Book::getBorrowerId() const { return borrowerId; }
// Setters for controlled modifications
void Book::setStatus(const string &newStatus) { status = newStatus; }
void Book::setBorrowerId(int newBorrowerId) { borrowerId = newBorrowerId; }
void Book ::setTitle(const string &newTitle) { title = newTitle; }
void Book ::setAuthor(const string &newAuthor) { author = newAuthor; }
void Book ::setPublisher(const string &newPublisher) { publisher = newPublisher; }
void Book ::setISBN(const string &newISBN) { isbn = newISBN; }
void Book ::setYear(const int &newYear) { year = newYear; }
// ✅ Display function
void Book::display() const
{
cout << "ID: " << id << ", Title: " << title << ", Author: " << author
<< ", Publisher: " << publisher << ", ISBN: " << isbn
<< ", Year: " << year << ", Status: " << status
<< ", Borrower ID: " << borrowerId << endl;
}
// ✅ isAvailable function
bool Book::isAvailable() const
{
return status == "Available";
}