-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
236 lines (206 loc) · 8.32 KB
/
main.cpp
File metadata and controls
236 lines (206 loc) · 8.32 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <iostream>
#include "MoviesSystem.h"
#include <climits>
using namespace std;
void printHeader() {
std::cout << " .---. ___ ,---, .---. \n";
std::cout << " /. ./| ,--.'|_ ,--.' | /. ./| ,--, \n";
std::cout << " .--'. ' ; | | :,' | | : .--'. ' ; ,--.'| \n";
std::cout << " /__./ \\ : | : : ' : : : : /__./ \\ : | | |, .--.--. \n";
std::cout << " .--'. ' \\' . ,--.--. .;__,' / ,---. : | |,--. .--'. ' \\' . `--'_ / / ' ,---. \n";
std::cout << "/___/ \\ | ' ' / \\ | | | / \\ | : ' | /___/ \\ | ' ' ,' ,'| | : /`./ / \\ \n";
std::cout << "; \\ \\; : .--. .-. | :__,'| : / / ' | | /' : ; \\ \\; : ' | | | : ;_ / / | \n";
std::cout << " \\ ; ` | \\__\\/: . . ' : |__ . ' / ' : | | | \\ ; ` | | | : \\ \\ `. . ' / | \n";
std::cout << " . \\ .\\ ; ,\" .--.; | | | '.'| ' ; :__ | | ' | : . \\ .\\ ; ' : |__ `----. \\ ' ; /| \n";
std::cout << " \\ \\ ' \\ | / / ,. | ; : ; ' | '.'| | : :_:,' \\ \\ ' \\ | | | '.'| / /`--' / ' | / | \n";
std::cout << " : ' |--\" ; : .' \\ | , / | : : | | ,' : ' |--\" ; : ; '--'. / | : | \n";
std::cout << " \\ \\ ; | , .-./ ---`-' \\ \\ / `--'' \\ \\ ; | , / `--'---' \\ \\ / \n";
std::cout << " '---\" `--`---' `----' '---\" ---`-' `----' \n";
}
void displayMainMenu() {
cout << "\n1- Watch a Movie\n"
<< "2- Trending\n"
<< "3- Top Rated\n"
<< "4- Filter\n"
<< "5- Recommended Movies\n"
<< "6- Profile\n"
<< "7- Exit\n";
}
void handleWatchMovie(MovieSystem* NexFlix, User* user, LinkedList* moviesList) {
while(true){
int watchChoice;
cout << "1- Search by Movie ID\n"
<< "2- Search By Movie Title\n";
cin >> watchChoice;
if (cin.fail()) {
cin.clear(); // Clear the error flag
cin.ignore(INT_MAX, '\n'); // Ignore the invalid input
cout << "Invalid input. Please enter a number.\n";
continue; // Ask for input again
}
MovieNode* watched = nullptr;
switch (watchChoice) {
case 1: {
int movieIdInput;
cout << "\nEnter Movie ID\n";
cin >> movieIdInput;
watched = moviesList->searchMovie(movieIdInput);
break;
}
case 2: {
string movieTitleInput;
cout << "\nEnter Movie Title\n";
cin >> movieTitleInput;
watched = moviesList->search_by_name(movieTitleInput);
break;
}
default:
cout << "Invalid choice. Returning to main menu.\n";
return;
}
if (watched) {
watched->display();
user->updateWatchedMovies(user->userId, watched->title);
int afterWatch;
cout << ".........Watched........."
<< "\n1- Add Reviews\n"
<< "2- Report Movie\n"
<< "3- Main Menu\n";
cin >> afterWatch;
if (cin.fail()) {
cin.clear(); // Clear the error flag
cin.ignore(INT_MAX, '\n'); // Ignore the invalid input
cout << "Invalid input. Returning to main menu.\n";
break;
}
switch (afterWatch) {
case 1: {
string reviewInput;
cout << "\nEnter review\n";
cin.ignore(); // Ignore the newline character left in the input buffer
getline(cin, reviewInput);
string review = "Movie ID: " + to_string(watched->movieId) + " Movie Title: " + watched->title + " Review: " + reviewInput;
user->reviewStack.addReview(review, user->userId);
cout << "Review Added.....\n";
return;
}
case 2:
moviesList->removeMovie(watched->movieId);
user->removeWatched(watched->title, user->userId);
cout << "Movie removed...........\nWe apologize for the inconvenience.....\n";
return;
default:
return;
}
} else {
cout << "Movie not found.\n";
}
}
}
void handleTrending(LinkedList* moviesList) {
cout << "\nTop 10 Trending Movies\n";
LinkedList* trending = moviesList->sort_by_votes();
trending->printLimited(10);
delete trending;
}
void handleTopRated(LinkedList* moviesList) {
cout << "\nTop Rated Movies\n";
LinkedList* topRated = moviesList->sort_by_rating();
topRated->printLimited(10);
delete topRated;
}
void handleFilter(LinkedList* moviesList) {
int filterType;
cout << "\n1- Filter by Genre\n"
<< "2- Filter by Production\n";
cin >> filterType;
string filterInput;
switch (filterType) {
case 1:
cout << "\nEnter preferred Genre: ";
cin >> filterInput;
moviesList->print_by_genre(filterInput);
break;
case 2:
cout << "Enter preferred Production: ";
cin >> filterInput;
moviesList->print_by_production(filterInput);
break;
default:
cout << "Invalid filter type.\n";
break;
}
}
void handleRecommendedMovies(User* user, LinkedList* moviesList, RecommendationGraph& recommend) {
vector<string> userWatched = user->getWatchedMovies(user->userId);
vector<TreeNode*> recommendedGraph = recommend.getRecommendation(userWatched, moviesList);
RecommendationHeap recommendedMovies;
for (TreeNode* treeNode : recommendedGraph) {
recommendedMovies.insert(treeNode);
}
cout << "......Movies Based on your Activity......\n";
recommendedMovies.printHeapByPriority();
}
void handleProfile(User* user) {
cout << "Username: " << user->username;
cout << " ID: " << user->userId;
cout << "\nWatch History\n";
for (const string& movieName : user->getWatchedMovies(user->userId)) {
cout << movieName << "\n";
}
cout << "\nReviews\n";
user->reviewStack.displayReviews(user->userId);
}
int main() {
MovieSystem* NexFlix = new MovieSystem();
RecommendationGraph recommend;
// Login or Signup
User* user = nullptr;
printHeader();
while (!user) {
user = NexFlix->authenticate();
}
LinkedList* moviesList = new LinkedList();
NexFlix->loadData(moviesList);
int mainChoice;
bool running = true;
while (running) {
displayMainMenu();
cin >> mainChoice;
if (cin.fail()) {
cin.clear(); // Clear the error flag
cin.ignore(INT_MAX, '\n'); // Ignore the invalid input
cout << "Invalid input. Please enter a number.\n";
continue; // Ask for input again
}
switch (mainChoice) {
case 1:
handleWatchMovie(NexFlix, user, moviesList);
break;
case 2:
handleTrending(moviesList);
break;
case 3:
handleTopRated(moviesList);
break;
case 4:
handleFilter(moviesList);
break;
case 5:
handleRecommendedMovies(user, moviesList, recommend);
break;
case 6:
handleProfile(user);
break;
case 7:
running = false;
break;
default:
cout << "Invalid choice. Please try again.\n";
break;
}
}
delete moviesList;
delete NexFlix;
return 0;
}