Question: Subject: C++ I am creating a class called Book located in a file called Book.h: #ifndef Book_H #define Book_H #include using namespace std; class Book

Subject: C++

I am creating a class called Book located in a file called Book.h:

#ifndef Book_H #define Book_H #include using namespace std; class Book { public: string name; double price; int qtyInStock; Book(string name, Author::Author, double price, int qtyInStock); string getName(); string getAuthor(); double getPrice(); void setPrice(double price); int getQtyInStock(); void setQtyInStock(int qtyInStock); void print(); string getAuthorName();

}; #endif

I also created another header called Author.h located here:

#ifndef Author_H #define Author_H #include using namespace std; class Author { public: string author; string email; char gender; };

#endif

I need to create two files; one called Book.cpp that defines the functions and one called MainBook.cpp that has a main() function in it.

Heres what I have so far in Book.cpp:

ook::Book(string name, Author::Author, double price, int qtyInStock) {

}

string Book::getName() { return name; }

string Book::getAuthor() { return author; }

double Book::getPrice() { return price; }

void Book::setPrice(double price) { double price = 0; }

int Book::getQtyInStock() { return 0; }

void Book::setQtyInStock(int qtyInStock) { }

void Book::print() { cout << name << " by " << Author::author << " " << Author::gender << " @ " << Author::email << endl; }

string Book::getAuthorName() { return string(); }

Here is what is needed:

Assume that a book is written by one and only one author.

print() function prints "'book-name' by author-name (gender) @ email".

getAuthorName() returns the name of the author of this Book instance.

Inside the main function:

  1. Declare and construct an instance of Author
  2. Declare and construct an instance of Book
  3. Call the print function of the Book
  4. Call the getAuthorName function of the Book

I would appreciate some help!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!