-
Notifications
You must be signed in to change notification settings - Fork 0
/
drama.cpp
120 lines (97 loc) · 2.66 KB
/
drama.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
// -------------------------------------------------- drama.cpp -----------------------------------------------------
// Name: Ihar Simanovich & Jason Kozodoy
// Course: CSS343 A
// Creation Date: 12/01/2016
// Last Modification: 12/14/2016
// ------------------------------------------------------------------------------------------------------------------
#include <sstream>
#include <iostream>
#include <string>
#include "drama.h"
using namespace std;
Drama::Drama(){
}
Drama::Drama(string director, string title){
this->director = director;
this->title = title;
}
Drama::~Drama(){
}
void Drama::setData(string data){
istringstream dataStream(data); //opening stream
dataStream.ignore(256, ' '); //ignoring first comma
dataStream >> instock; //getting quantity in stock
dataStream.ignore(256, ','); //ignoring comma after number
string temp;
dataStream >> temp;
//reading director
for (;;) {
//no comma case, adding words to title
if (temp.find(',') == -1) {
director += temp;
director += " ";
dataStream >> temp;
}
//comma case, removing comma and adding to title then break
else {
temp = temp.substr(0, temp.size() - 1);
director += temp;
break;
}
}
//reading title
dataStream >> temp;
for (;;) {
//no comma case, adding words to title
if (temp.find(',') == -1) {
title += temp;
title += " ";
dataStream >> temp;
}
//comma case, removing comma and adding to title then break
else {
temp = temp.substr(0, temp.size() - 1);
title += temp;
break;
}
}
//getting a year of the movie
dataStream >> year;
}
void Drama::display()const{
cout << "D, Stock: " << instock << ", Borrowed: "<< borrowedCount
<< ", " << director << ", " << title << ", " << year << endl;
}
//ASSUMPTION: since director is a variable to store both first and last
// names, when sorting drama movies by director, it sorts
// primarily by first name
bool Drama::operator<(const Movie &rhs) const {
const Drama& rhS = static_cast<const Drama&>(rhs);
if (director < rhS.director)
return true;
else if (director == rhS.director && title < rhS.title)
return true;
else
return false;
}
bool Drama::operator<(const Drama &rhs) const {
if (director < rhs.director)
return true;
else if (director == rhs.director && title < rhs.title)
return true;
else
return false;
}
bool Drama::operator==(const Movie& rhs) const {
const Drama& rhS = static_cast<const Drama&>(rhs);
if(director == rhS.director && title == rhS.title)
return true;
else
return false;
}
bool Drama::operator==(const Drama& rhs) const {
if (director == rhs.director && title == rhs.title)
return true;
else
return false;
}