-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
70 lines (59 loc) · 2.55 KB
/
main.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 "cinemania.h"
#include <fstream>
#include "movie.h"
#include <QApplication>
#include <iostream>
int main(int argc, char *argv[])
{
vector<movie> movieList; // initial vector to hold movie data
string myText;
int position;
fstream MyReadFile("MovieDataset.txt");
getline (MyReadFile, myText); // read first line to skip header
// loop through each line of text in the file
while (getline (MyReadFile, myText)) {
// parsing to get movie attributes separated by tabs
position = myText.find('\t');
string movieid = myText.substr(0, position);
myText = myText.substr(position + 1, myText.size());
position = myText.find('\t');
string title = myText.substr(0, position);
myText = myText.substr(position + 1, myText.size());
if (title[0] == '\"'){
title = title.substr(1, title.size()-2);
}
position = myText.find('\t');
string year = myText.substr(0, position);
myText = myText.substr(position + 1, myText.size());
position = myText.find('\t');
string runtime = myText.substr(0, position);
myText = myText.substr(position + 1, myText.size());
position = myText.find('\t');
string genre = myText.substr(0, position);
myText = myText.substr(position + 1, myText.size());
if (genre[0] == '\"'){
position = genre.find(',');
genre = genre.substr(1, position-1);
}
position = myText.find('\t');
string rating = myText.substr(0, position);
myText = myText.substr(position + 1, myText.size());
position = myText.find('\t');
string numVotes = myText.substr(0, position);
myText = myText.substr(position + 1, myText.size());
// create movie object that contains all attributes found
movie CurrentMovie(movieid, title, year, runtime, genre, rating, numVotes);
movieList.push_back(CurrentMovie); // put in vector
}
MyReadFile.close(); // close input file
// create arrays to store movie objects
movie* moviesArr = new movie[movieList.size()];
movie* unchangedArr = new movie[movieList.size()];
// copy objects from initial vector into the new arrays
copy(movieList.begin(), movieList.end(), moviesArr);
copy(movieList.begin(), movieList.end(), unchangedArr);
QApplication a(argc, argv); // create QApplication object
CineMania w(nullptr, moviesArr, unchangedArr, movieList.size()); // create cinemania object
w.show(); // display main window
return a.exec();
}