-
Notifications
You must be signed in to change notification settings - Fork 0
/
Book.cc
82 lines (61 loc) · 1.82 KB
/
Book.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "Book.h"
//Book ctor - with member initializer syntax and callNumber data member - t08
Book::Book(int i, string cn, string t, string a, int y)
: id(i), callNumber(cn), title(t), author(a), year(y){
cout << "## in Book ctor : A new book is created! ##" << endl;
}
/*
//This Book Ctor is similar as above. This one doesn't use member initializer
//syntax and doesn't initialize the callNumber data member.
Book::Book(int i, string t, string a, int y)
{
id = i;
title = t;
author = a;
year = y;
cout << "## CTOR BOOK ##" << endl;
}
*/
//Book dtor - is now made virtual
Book::~Book(){
cout << "Book Destroyed" << endl;
}
//Sets book's id number, title, author and year
void Book::setBook(int i, string t, string a, int y/*, string cn*/)
{
id = i;
title = t;
author = a;
year = y;
//callNumber = cn;
}
//Prints a single book object
void Book::print()
{
cout << setw(3) << id
<<" Title: " << setw(40) << title
<<"; Author: " << setw(20) << /*author*/ getAuthorName()
<<"; Year: " << setw(10) << year
<<"; Call Number: " << /*callNumber*/ getCallNumber() << endl;
}
//lessThan() implementation is taken because it's pure virtual
//Compares two books according to their year of publication
//bool Book::lessThan(Book* book);
//{
/* cout << "@@ COMPARING BOOKS @@" << endl;
//This return statement also works:
//return (year < book->year);
return (this->year < book->year);*/
//}
//Getter member function for author name. Will be used when book is added.
string Book::getAuthorName(){
return author;
}
//Getter member function for call number. Will be used when book is added.
string Book::getCallNumber(){
return callNumber;
}