Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include class Book { private: std::string title; std::string author; int id; bool isAvailable; public: Book ( std::string t , std::string a ,
#include
#include
#include
#include
class Book
private:
std::string title;
std::string author;
int id;
bool isAvailable;
public:
Bookstd::string t std::string a int i : titlet authora idi isAvailabletrue
void borrowBook
ifisAvailable
isAvailable false;
else
std::cout "Book already borrowed." std::endl;
void returnBook
isAvailable true;
void displayInfo
std::cout "Book: title Author: author ID: id
Available: isAvailable "Yes" : No std::endl;
;
class Library
private:
std::vector books;
public:
void addBookBook book
books.pushbackbook;
void displayAllBooks
forint i ; i books.size; i
booksidisplayInfo;
Book findBookByIdint id
forint i ; i books.size; i
ifbooksigetId id
return &booksi;
return NULL;
;
void saveLibraryDataLibrary &lib
std::ofstream filelibrarytxt;
lib.displayAllBooks;
file.close;
int main
Library myLibrary;
Book book "George Orwell", ;
Book bookTo Kill a Mockingbird", "Harper Lee", ;
Book bookThe Great Gatsby", F Scott Fitzgerald", ;
myLibrary.addBookbook;
myLibrary.addBookbook;
myLibrary.addBookbook;
myLibrary.displayAllBooks;
Book book myLibrary.findBookById;
ifbook NULL
bookborrowBook;
myLibrary.displayAllBooks;
saveLibraryDatamyLibrary;
return ;
This program aims to represent a simple library management system but contains several intentional errors, bad practices, and areas for improvement. It's a great exercise to review this code, identify the errors, and think about how you would correct them.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started