#include <iostream>
#include <string>
using namespace std;
// class Book
// with four private data fields: book title, author, copyright, and price
// four public methods to retrieve fields (called "getters")
// and one public non-default constructor
class Book {
public:
// member function prototypes
void assign (string, string, int, float); // this is your constructor
string getTitle(); // these are getter functions
string getAuthor();
int getCopyRightYear();
float getPrice();
private:
// data members
string title;
string author;
int copyRightYear;
float price;
};
// these are the actual member functions
// this member function is a "constructor" that will create a new book
void Book::assign (string bookTitle, string bookAuthor, int bookDate, float bookPrice) {
title = bookTitle;
author = bookAuthor;
copyRightYear = bookDate;
price = bookPrice;
}
// this member function is a "getter" that will retrieve that book title value
string Book::getTitle() {
return title;
}
// this member function is a "getter" that will retrieve the primary book author value
string Book::getAuthor() {
return author;
}
// this member function is a "getter" that will retrieve the year the book was copyrighted
int Book::getCopyRightYear() {
return copyRightYear;
}
// this member function is a "getter" that will retrieve the list price of the book
float Book::getPrice() {
return price;
}
int main()
{
cout << "Here are some of my favorite books ...\n" << endl;
// Set up space to create 5 instances of the class Book
Book b1, b2, b3, b4, b5;
// Step 1) assign and print book 1
b1.assign("The Pragmatic Programmer", "Andrew Hunt and David Thomas", 1999, 42.35);
cout << b1.getTitle() << " authored by " << b1.getAuthor() << " in the year " << b1.getCopyRightYear() << endl;
cout << "The price of this book is: $" << b1.getPrice() << endl << endl;
// Step 2) assign and print book 2
b2.assign("Clean Code", "Robert C. Martin", 2008, 37.50);
cout << b2.getTitle() << " authored by " << b2.getAuthor() << " in the year " << b2.getCopyRightYear() << endl;
cout << "The price of this book is: $" << b2.getPrice() << endl << endl;
// Step 3) assign and print book 3
b3.assign("Introduction to Algorithms", "Thomas H. Cormen", 2009, 89.99);
cout << b3.getTitle() << " authored by " << b3.getAuthor() << " in the year " << b3.getCopyRightYear() << endl;
cout << "The price of this book is: $" << b3.getPrice() << endl << endl;
// Step 4) assign and print book 4
b4.assign("Effective Modern C++", "Scott Meyers", 2014, 45.00);
cout << b4.getTitle() << " authored by " << b4.getAuthor() << " in the year " << b4.getCopyRightYear() << endl;
cout << "The price of this book is: $" << b4.getPrice() << endl << endl;
// Step 5) assign and print book 5
b5.assign("Design Patterns: Elements of Reusable Object-Oriented Software", "Erich Gamma et al.", 1994, 54.95);
cout << b5.getTitle() << " authored by " << b5.getAuthor() << " in the year " << b5.getCopyRightYear() << endl;
cout << "The price of this book is: $" << b5.getPrice() << endl << endl;
return 0;
}