-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
168 lines (148 loc) · 5.06 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <iostream>
#include <iomanip>
#include "parse.h"
#include "movies.h"
#include "quicksort.h"
#include "mergesort.h"
#include "search.h"
#include "welcome.h"
#include <string>
#include <vector>
using namespace std;
void printMoviesArr(Movies arr[], int len) {
for (int i = 0; i < len; i++) {
cout << arr[i].getMovieName() << endl;
cout << " Rating: " << std::setprecision(2) << arr[i].getRating() << endl;
}
}
void testQuick() {
vector<Movies> vec = parseMovies(5);
int n = vec.size();
Movies arr[n];
copy(vec.begin(), vec.end(), arr);
arr[0].setRating(8);
arr[1].setRating(5);
arr[2].setRating(2);
arr[3].setRating(10);
arr[4].setRating(9);
cout << "\nunsorted:" << endl;
//printMoviesArr(arr, n);
cout << "\nperforming quick sort..." << endl;
quickSort(arr, 0, n - 1);
printMoviesArr(arr, n);
}
void testMerge() {
vector<Movies> vec = parseMovies(5);
int n = vec.size();
Movies arr[n];
copy(vec.begin(), vec.end(), arr);
arr[0].setRating(8);
arr[1].setRating(5);
arr[2].setRating(2);
arr[3].setRating(10);
arr[4].setRating(9);
cout << "\nunsorted:" << endl;
//printMoviesArr(arr, n);
cout << "\nperforming merge sort..." << endl;
mergeSort(arr, 0, n - 1);
printMoviesArr(arr, n);
}
void testParse() {
// print first 5 lines of movies.csv
cout << "Creating 5 movie objects:" << endl;
vector<Movies> movieObjects = parseMovies(5);
for (auto & movieObject : movieObjects) {
cout << movieObject.getMovieName() << endl;
cout << " Genre: ";
vector<string> genres = movieObject.getGenre();
for (int i = 0; i < genres.size(); i++) {
cout << genres.at(i) << ", ";
}
cout << "\n";
cout << " Rating: " << to_string(movieObject.getRating()) << endl;
cout << " Starring: ";
vector<string> stars = movieObject.getStar();
for (int i = 0; i < stars.size(); i++) {
cout << stars.at(i) << ", ";
}
cout << "\n";
}
}
int main() {
// testQuick();
// testMerge();
// testParse();
// searchDistributor(4, "", 2);
welcomeText();
// 1. do parsing with parse.h
// 2. Prompt user with search options
string userInput;
userInput = "";
string searchTerm = ""; // search term will hold either actor, director, or genre.
int searchOption = 0; // will hold which option user chooses: 1) actor, 2) director, 3) genre, 4) gross box office
while (userInput != "1" && userInput != "2" && userInput != "3" && userInput != "4") { // will loop if user does not input 1-4
cout << "How would you like to search?" << endl;
cout << "1) Search by actor" << endl;
cout << "2) Search by director" << endl;
cout << "3) Search by genre" << endl;
cout << "4) Search by gross box office" << endl;
cout << "Enter a number 1-4:" << endl;
getline(cin, userInput);
if (userInput == "1") {
cout << "What actor would you like to search for?" << endl;
getline(cin, searchTerm);
searchOption = 1;
}
else if (userInput == "2") {
cout << "What director would you like to search for?" << endl;
getline(cin, searchTerm);
searchOption = 2;
}
else if (userInput == "3") {
cout << "What genre would you like to search for? (options: Action, Adventure, Animation, Crime, Family, Fantasy, History, Horror, Romance, Sci-Fi, Film-Noir, Sports, Thriller, War)" << endl;
// maybe print options later?
cin >> searchTerm;
searchOption = 3;
}
else if (userInput == "4") {
// Option 4 (box office) doesn't need a secondary question
searchOption = 4;
}
else {
cout << "Please enter 1-4." << endl;
}
}
userInput = ""; // resetting userInput
// 3. Prompt user with sort options
while (userInput != "1" && userInput != "2") { // will loop if user does not input 1-2
cout << "Select a sorting algorithm" << endl;
cout << "1) Merge Sort" << endl;
cout << "2) Quick Sort" << endl;
cout << "Enter a number 1-2:" << endl;
cin >> userInput;
// check for input errors
if (userInput != "1" && userInput != "2") {
cout << "Please enter 1 or 2." << endl;
}
}
//4. Search
if (searchOption == 1) {
cout << "Searching movies for the actor " << searchTerm;
}
else if (searchOption == 2) {
cout << "Searching movies for the director " << searchTerm;
}
else if (searchOption == 3) {
cout << "Searching movies for " << searchTerm << " genre";
}
else if (searchOption == 4) {
cout << "Showing highest grossing movies";
}
if (userInput == "1") {
cout << " with Merge Sort...\n" << endl;
}
else if (userInput == "2") {
cout << " with Quick Sort...\n" << endl;
}
searchDistributor(searchOption, searchTerm, stoi(userInput));
}