Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C++ function to display the following books information: (it should search for a specfic book just use a random one to test) -book

Write a C++ function to display the following books information: (it should search for a specfic book just use a random one to test)

-book title

-book borrowed or not

-author name

-author email

Here is the code we are given for this question

//Book.h

#ifndef BOOK_H #define BOOK_H #include #include"AUTHOR.H" class Book { private: string title; bool borrowed; vector authors; public: Book(string,vector); string get_title(); bool is_borrowed(); void set_title(string); void set_authors(vector); void set_borrowed(bool); }; #endif //Book.cpp #include"Book.h" Book::Book(string title, vector authors) { this->title=title; this->authors=authors; } string Book::get_title() { return title; } bool Book::is_borrowed() { return borrowed; } void Book::set_title(string title) { this->title=title; return; } void Book::set_authors(vector authors) { this->authors=authors; return; } void Book::set_borrowed(bool borrowed) { this->borrowed=borrowed; return; } //Author.h #ifndef AUTHOR_H #define AUTHOR_H #include using namespace std; class Author { private: string name,email; public: Author(string,string); string get_name(); void set_name(string); void set_email(string); }; #endif //Author.cpp #include"Author.h" Author::Author(string name, string email):name(name), email(email) {} string Author::get_name() { return name; } void Author::set_name(string name) { this->name=name; return; } void Author::set_email(string email) { this->email=email; return; } //main.cpp #include"Book.h" #include //gv //Function declaration void add_new_book(vector&); void borrow_book(vector&,string); int main() { vector books; string book_title; add_new_book(books); cout<<"Enter book title to borrow:"; getline(cin,book_title); borrow_book(books,book_title); system("pause"); return 0; } //function definition void borrow_book(vector &b_list,string b_title) { //local var bool flag=false; //code for(int i=0;i { if(b_title==b_list.at(i).get_title()) { flag=true; if(b_list.at(i).is_borrowed()) { cout<<"The book is available but is already BORROWED"< break; }//if else { cout<<"You borrowed the book"< b_list.at(i).set_borrowed(true); break; }//else }//if }//for if(flag==false) cout<<"This book is NOT available"< return; } void add_new_book(vector&b_list) { //local var string book_title,author_name, author_email; vector authors; char answer; //code cout<<"Enter Book's Title: "; getline(cin,book_title); addauthor: cout<<"Enter Author's Name: "; getline(cin,author_name); cout<<"Enter Author's Email: "; getline(cin,author_email); Author author(author_name,author_email); authors.push_back(author); cout<<"Add another author? (yes:y no: n) "; cin>>answer; cin.ignore(); if(answer=='y' || answer=='Y') goto addauthor; Book book(book_title,authors); book.set_borrowed(false); b_list.push_back(book); return; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions