-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclassic.cpp
More file actions
117 lines (104 loc) · 4.34 KB
/
classic.cpp
File metadata and controls
117 lines (104 loc) · 4.34 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
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
//----------------------------------------------------------------------------
// Classic.cpp
// Implementation:
// -- This class is responsible for handling the classic movies available in
// the store. Classic inherits the public variables and methods from Movie.
// Assumptions:
// -- Data file will be formatted correctly, although data may be incorrect
// -- Factory determines which type of movie object is created
//----------------------------------------------------------------------------
#include "classic.hpp"
//--------------------------------constructor---------------------------------
Classic::Classic() : Movie() { }
//---------------------------------destructor---------------------------------
Classic::~Classic() { }
//----------------------------------display-----------------------------------
// will display the movies data members for the displayInventory method in
// the store class
void Classic::display() const {
cout << left << setw(8) << setfill(' ') << "stock:" << left << setw(4)
<< setfill(' ') << stock;
cout << left << setw(11) << setfill(' ') << "director: " << left
<< setw(20) << setfill(' ') << director;
cout << left << setw(8) << setfill(' ') << "title: " << left
<< setw(35) << setfill(' ') << title;
cout << left << setw(6) << setfill(' ') << "year:" << year << " ";
cout << left << setw(7) << setfill(' ') << "month:" << month << " ";
cout << endl;
}
//----------------------------------setData-----------------------------------
// sets the data for the blank classic object after the factory creates a new
// classic movie
void Classic::setData(ifstream& infile) {
infile.ignore();
infile >> stock;
infile.ignore();
getline(infile >> ws, director, ',');
infile.ignore();
getline(infile >> ws, title, ',');
infile.ignore();
infile >> actorFName;
infile.ignore();
infile >> actorLName;
infile.ignore();
infile >> month;
infile.ignore();
infile >> year;
}
//-------------------------------setTempData----------------------------------
// sets temporary data in processTransactions so movie can be retrieved from
// the inventory tree
void Classic::setTempData(ifstream& infile) {
infile >> month >> year >> actorFName >> actorLName;
}
//--------------------------------operator<-----------------------------------
// determines if this is less than the other
bool Classic::operator<(const Movie& other) const {
const Classic& classicMovie = static_cast<const Classic&>(other);
if (year < classicMovie.year) {
return true;
} else if (year == classicMovie.year && actorFName <
classicMovie.actorFName) {
return true;
} else if (actorFName == classicMovie.actorFName && actorLName <
classicMovie.actorLName) {
return true;
} else {
return false;
}
}
//--------------------------------operator<-----------------------------------
// determines if this is greater than the other
bool Classic::operator>(const Movie& other) const {
const Classic& classicMovie = static_cast<const Classic&>(other);
if (year > classicMovie.year) {
return true;
} else if (year == classicMovie.year && actorFName >
classicMovie.actorFName) {
return true;
} else if (actorFName == classicMovie.actorFName && actorLName >
classicMovie.actorLName){
return true;
} else {
return false;
}
}
//-------------------------------operator==-----------------------------------
// determines if this is equal to the other
bool Classic::operator==(const Movie& other) const {
const Classic& classicMovie = static_cast<const Classic&>(other);
return (year == classicMovie.year && month == classicMovie.month);
}
//-------------------------------operator!=-----------------------------------
// determines if this is not equal to the other
bool Classic::operator!=(const Movie& other) const {
const Classic& classicMovie = static_cast<const Classic&>(other);
return !(*this == classicMovie);
}
//----------------------------------create------------------------------------
// returns a new Comedy object to the factory to be inserted into binary tree
// data will be set right after object is created in the buildInventory
// funtion in the store class.
Movie* Classic::create() {
return new Classic();
}