-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (58 loc) · 1.59 KB
/
Copy pathmain.cpp
File metadata and controls
82 lines (58 loc) · 1.59 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
// COMSC 210 | Lab 15 | Robert Stonemetz
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
class Movie {
private:
string title;
int yearReleased;
string screenWriter;
public:
//constructors
Movie() : yearReleased(0) {}
Movie (string t, int y, string sw) : title(t), yearReleased(y), screenWriter(sw) {}
//setters
void setTitle(const string& t){title = t;}
void setYearReleased(int y) {yearReleased = y;}
void setScreenWriter(const string& sw){screenWriter = sw;}
//getters
string getTitle() const {
return title;
}
int getYearReleased() const {
return yearReleased;
}
string getScreenWriter() const {
return screenWriter;
}
void print() const{
cout << "Movie: " << title << endl;
cout << " Year Released: " << yearReleased << endl;
cout << " Screenwriter: " << screenWriter << endl << endl;
}
};
int main(){
vector <Movie> movies;
ifstream inputFile ("Movies.txt");
if (!inputFile) {
cerr << "Error opening input file!" << endl;
return 1;
}
string title;
int year;
string screenWriter;
while (getline(inputFile, title) && inputFile >> year) {
inputFile.ignore();
getline (inputFile, screenWriter);
Movie tempMovie (title, year, screenWriter);
movies.push_back(tempMovie);
}
inputFile.close();
cout << "Contents of the movie vector:" << endl;
for (const auto& movie : movies) {
movie.print();
}
return 0;
}