-
Notifications
You must be signed in to change notification settings - Fork 0
/
Movie.cpp
70 lines (54 loc) · 1.45 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
#include "Movie.h"
Movie::Movie(): title(""), genre(""), yearOfRelease(0), nrLikes(0), trailer(""), duration(0) {}
Movie::Movie(const string& title, const string& genre, int yearOfRelease, int nrLikes, const string& trailer, int duration)
{
this->title = title;
this->genre = genre;
this->yearOfRelease = yearOfRelease;
this->nrLikes = nrLikes;
this->trailer = trailer;
this->duration = duration;
}
bool operator==(const Movie& m1, const Movie& m2)
{
return (m1.getTitle() == m2.getTitle() && m1.getYearOfRelease() == m2.getYearOfRelease());
}
bool operator<(const Movie& m, int a)
{
return (m.getDuration() < a);
}
istream& operator>>(istream& is, Movie& m)
{
string line;
getline(is, line);
stringstream ss(line);
string token;
vector<string> temp;
while (getline(ss, token, ','))
temp.push_back(token);
if (temp.size() != 6)
return is;
m.title = temp[0];
m.genre = temp[1];
m.yearOfRelease = stoi(temp[2]);
m.nrLikes = stoi(temp[3]);
m.trailer = temp[4];
m.duration = stoi(temp[5]);
return is;
}
ostream& operator<<(ostream& os, const Movie& m)
{
os << m.title << "," << m.genre << "," << m.yearOfRelease << "," << m.nrLikes << "," << m.trailer << "," << m.duration<<'\n';
return os;
}
void Movie::increaseLike()
{
this->nrLikes = this->nrLikes + 1;
}
void Movie::playTrailer()
{
system(("open " + this->getTrailer()).c_str());
}
Movie::~Movie()
{
}