book class 1.0

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Chapter 9 Exercise 5
Using std_lib_facilities.h by Bjarne Stroustrup.
Using Chrono.h and Chrono.cpp by Bjarne Stroustrup,
including the Chrono.h header file and the Chrono.cpp source file. Chrono is an extensive date class used in this exercise.

My project includes the following files:
Chrono.h date class header file
Chrono.cpp date class source file
p339_5_book_main.cpp my main cpp file
p339_5_my_book_class.h my book class header file
p339_5_book_source.cpp my book class header file’s source file

p339_5_book_main.cpp my main cpp file

//	Philipp Siedler
//	Bjarne Stroustrup's PPP
//	Chapter 9 Exercise 5

#include "p339_5_my_book_class.h"
using namespace Chrono;

int main()
	Book myBook(ISBN(), "book1", "author1", Date(2000, Date::jul, 5), false);
catch (runtime_error e) {
	cout << e.what() << endl;
catch (...) {
	cout << "Exiting" << endl;

p339_5_my_book_class.h header file

#include "std_lib_facilities.h"
#include "Chrono.h"
using namespace Chrono;

//BOOK CLASS------
struct ISBN {
	int n0, n1, n2;
	char x;
	ISBN(int n0, int n1, int n2, char x);

class Book {
	ISBN isbn;
	string title;
	string author;
	Date copyright_date;
	bool checked_out;

	Book(ISBN _isbn, string _title, string _author, Date _copyright_date, bool _checked_out);
	ISBN isbnf() { return isbn; }
	string titlef() { return title; }
	string authorf() { return author; }
	Date copyright_datef() { return copyright_date; }

	bool checked_outf() { return checked_out; }
	void book_out();
	void book_in();
//endBOOK CLASS------

p339_5_book_source.cpp my book class header file’s source file

#include "p339_5_my_book_class.h"

ISBN::ISBN(int _n0, int _n1, int _n2, char _x) {
	n0 = _n0;
	n1 = _n1;
	n2 = _n2;
	x = _x;

	n0 = 0;
	n1 = 0;
	n2 = 0;
	x = '0';

Book::Book(ISBN _isbn, string _title, string _author, Date _copyright_date, bool _checked_out) {
	cout << "Creating book\n";
	isbn = _isbn;
	title = _title;
	author = _author;
	copyright_date = _copyright_date;
	checked_out = _checked_out;

Book::Book() {
	cout << "Creating book\n";
	isbn = ISBN();
	title = "noTitle";
	author = "noAuthor";
	copyright_date = Date();
	checked_out = false;

void Book::book_out() {
	checked_out = true;

void Book::book_in() {
	checked_out = false;
Creating book
Please enter a character to exit

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.