-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovies.cpp
79 lines (69 loc) · 2.9 KB
/
Movies.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
/******************************************************************
* Movies.h
*
* Models a collection of Movies as a std::vector
*
* ***************************************************************/
#include <iostream>
#include "Movies.h"
/*************************************************************************
Movies no-args constructor
**************************************************************************/
Movies::Movies() {
}
/*************************************************************************
Movies destructor
**************************************************************************/
Movies::~Movies() {
}
/*************************************************************************
add_movie expects the name of the movie, rating and watched count
It will search the movies vector to see if a movie object already exists
with the same name.
If it does then return false since the movie already exists
Otherwise, create a movie object from the provided information
and add that movie object to the movies vector and return true
*********************************************************************/
bool Movies::add_movie(std::string name, std::string rating, int watched) {
for (const Movie &movie: movies) {
if (movie.get_name() == name)
return false;
}
Movie temp {name, rating, watched};
movies.push_back(temp);
return true;
}
/*************************************************************************
increment_watched expects the name of the move to increment the
watched count
It will search the movies vector to see if a movie object already exists
with the same name.
If it does then increment that objects watched by 1 and return true.
Otherwise, return false since then no movies object with the movie name
provided exists to increment
*********************************************************************/
bool Movies::increment_watched(std::string name) {
for (Movie &movie: movies) {
if (movie.get_name() == name) {
movie.increment_watched();
return true;
}
}
return false;
}
/*************************************************************************
display() method
display all the movie objects in the movies vector.
for each movie call the movie.display method so the movie
object displays itself
*********************************************************************/
void Movies::display() const {
if (movies.size() == 0) {
std::cout << "Sorry, no movies to display\n" << std::endl;
} else {
std::cout << "\n===================================" << std::endl;
for (const auto &movie: movies)
movie.display();
std::cout << "\n===================================" << std::endl;
}
}