-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.cpp
More file actions
62 lines (58 loc) · 1.65 KB
/
Book.cpp
File metadata and controls
62 lines (58 loc) · 1.65 KB
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
#include <iostream>
#include "Book.h"
//setters
void Book::setID(int x) //using scope resolution to specify that it's in the Book namespace
{ //without using Book:: leads to it failing to recognize where the definition is for these
id = x;
}
void Book::setAvailableQuantity(int x)
{
availableQuantity = x;
}
void Book::setTitle(const std::string& x) //used const to make sure the ref isn't modified
{ //the reason to use a reference here is because it's faster in case of long strings
title = x; //here we use pass by reference which is faster for strings but shoudn't be used for int and such
}
void Book::setAuthor(const std::string& x)
{
author = x;
}
void Book::setReleaseYear(int x)
{
releaseYear = x;
}
//getters
int Book::getID() const
{
return id;
}
int Book::getAvailableQuantity() const
{
return availableQuantity;
}
std::string Book::getTitle() const
{
return title;
}
std::string Book::getAuthor() const
{
return author;
}
int Book::getReleaseYear() const
{
return releaseYear;
}
//constructors
Book::Book(int INPUTid, int INPUTavailableQuantity, std::string INPUTtitle, std::string INPUTauthor, int INPUTreleaseYear)
{
id = INPUTid;
availableQuantity = INPUTavailableQuantity;
title = INPUTtitle;
author = INPUTauthor;
releaseYear = INPUTreleaseYear;
}
Book::Book() //for use without any values as a default
: id(0), availableQuantity(0), title("temp"), author("temp"), releaseYear(0) //using a diff way of making a constructor here
{
} //this way uses a : and the member function names are set as the defaults
Book::~Book() = default; //using the default destructor here