-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovie.cpp
177 lines (145 loc) · 4.25 KB
/
Movie.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// Created by Daniel Akimchuk on 11/8/16.
//
#include <string>
#include "Movie.h"
Movie::Movie() {
this->title = "";
this->year = -1;
this->inStock = -1;
this->wantInStock = -1;
this->waitList = nullptr;
}
Movie::Movie(std::string title, double price, int year, int inStock, int wantInStock) {
this->title = title;
this->year = year;
this->price = price;
this->inStock = inStock;
this->wantInStock = wantInStock;
this->waitList = new LinkedQueue<std::string>();
}
Movie::Movie(const Movie& movie) {
this->title = movie.title;
this->price = movie.price;
this->year = movie.year;
this->inStock = movie.inStock;
this->wantInStock = movie.wantInStock;
this->waitList = new LinkedQueue<std::string>(*(movie.waitList)); //MAKE SURE WE OVERLOAD ASSIGNMENT OPERATOR AND COPY CONSTRUCTOR
}
Movie& Movie::operator=(Movie movie) {
if (this != &movie) {
//delete current
if (waitList != nullptr ) {
delete waitList;
}
waitList = nullptr;
//new values
this->title = movie.title;
this->price = movie.price;
this->year = movie.year;
this->inStock = movie.inStock;
this->wantInStock = movie.wantInStock;
this->waitList = new LinkedQueue<std::string>(*(movie.waitList)); //MAKE SURE WE OVERLOAD ASSIGNMENT OPERATOR AND COPY CONSTRUCTOR
}
return *this;
}
bool Movie::operator==(Movie& other){return(this->title == other.title) && (this->price == other.price) && (this->year == other.year) && (this->inStock == other.inStock) && (this->wantInStock == other.wantInStock);}
Movie::~Movie() {
if (waitList != nullptr ) {
delete waitList;
}
waitList = nullptr;
}
void Movie::setTitle(std::string title) {
this->title = title;
}
void Movie::setPrice(double price) {
this->price = price;
}
void Movie::discountAmount(double amt) {
this->price = this->price - amt;
}
void Movie::discountPercent(double percent) {
this->price = this->price * percent;
}
void Movie::setYear(int year) {
this->year = year;
}
void Movie::setInStock(int inStock) {
this->inStock = inStock;
}
void Movie::setWantInStock(int wantInStock) {
this->wantInStock = wantInStock;
}
std::string Movie::getTitle(){
return this->title;
}
double Movie::getPrice() {
return this->price;
}
int Movie::getYear() {
return this->year;
}
int Movie::getInStock() {
return this->inStock;
}
int Movie::getWantInStock() {
return this->wantInStock;
}
int Movie::getNeeded() {
return this->wantInStock - this->inStock;
}
void Movie::addToWaitList(std::string customer) {
if (this->waitList == nullptr) {
this->waitList = new LinkedQueue<std::string>();
}
this->waitList->enqueue(customer);
}
std::string Movie::removeFromWaitList() {
return this->waitList->dequeue();
}
void Movie::addToStock(int amount) {
setInStock(getInStock() + amount);
while (true) {
try {
if (inStock == 0) {
break;
}
std::string name = waitList->dequeue();
setInStock(getInStock() - 1);
std::cout << name << " was taken off the waitlist for " << getTitle() << ". Current stock is now: " << std::to_string(getInStock()) << std::endl;
} catch (std::out_of_range) {
break;
}
}
}
std::string Movie::toString() {
std::string str = getTitle() + ", " +
std::to_string(getYear()) + ", $" +
std::to_string(getPrice()) + ", " +
std::to_string(getInStock()) + " in stock, " +
std::to_string(getWantInStock()) + " desired in stock.";
return str;
}
LinkedQueue<std::string>* Movie::getWaitList() {
return waitList;
}
std::string Movie::toStringForQuit() {
std::string str = getTitle() + "\n" +
std::to_string(getYear()) + "\n" +
std::to_string(getPrice()) + "\n" +
std::to_string(getInStock()) + "\n" +
std::to_string(getWantInStock()) + "\n";
while (true) {
try {
str += waitList->dequeue() + "|";
} catch (std::out_of_range) {
break;
}
}
str += "\n";
return str;
}
void Movie::setWaitList(LinkedQueue<std::string>* queue) {
this->waitList = queue;
}