-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomedy.cpp
50 lines (44 loc) · 1.38 KB
/
comedy.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
/**
* Comedy.cpp
* Child class of Movies, a Comedy is a specific type of Movie
* Comedy (‘F’) sorted by Title, then Year it released
*
* @author Olga Kuriatnyk
*/
#include "comedy.h"
// Constructor
Comedy::Comedy(const char &movieType) { this->movieType = movieType; }
// default destructor
Comedy::~Comedy() = default;
// reads the line from the file and sets the values to this object
// has validation check for stock and year
bool Comedy::read(istream &is) {
char discardComma;
is >> this->stock;
is >> discardComma;
this->director = readNextItem(is);
this->title = readNextItem(is);
is >> this->year;
if (!isStockValid()) {
cerr << "ERROR: invalid stock" << endl;
return false;
}
if (!isYearValid()) {
cerr << "ERROR: invalid year" << endl;
return false;
}
this->title += ",";
this->mediaType = 'D'; // because right now we only have one media type
this->itemKey = ItemKey(this->title, to_string(this->year));
return true;
}
// print our comedy movie object
void Comedy::printMovie() const {
cout << "GENRE: " << this->getMovieType() << ", TITLE: " << this->title;
cout << "\n\tDirector: " << this->director
<< ", Year released: " << this->year;
cout << ", In-stock: " << this->stock << ", Borrowed: " << this->borrowedNum
<< endl;
}
// creating the object registers the type at run time
ComedyFactory anonymousComedyFactory;