-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMoviesSystem.h
More file actions
155 lines (132 loc) · 4.26 KB
/
MoviesSystem.h
File metadata and controls
155 lines (132 loc) · 4.26 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
#ifndef SYSTEM_H
#define SYSTEM_H
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include "MoviesData.h"
#include "UserLogin.h"
#include "MoviesTree.h"
#include "Recommendation.h"
#include "User.h"
using namespace std;
class MovieSystem {
public:
// Function to Log In to the System
User* logIn(){
string username, password;
cout<<"Enter Username: ";
cin>>username;
cout<<"Enter Password: ";
cin>>password;
int loggedin = (userExists(username, password));
if (loggedin != -1){
return new User(loggedin, username);
}
else{
return nullptr;
}
}//LogIn ends here
//Function to Sign Up to the System
User* SignUP(){
string username, password;
cout<<"Enter Username: ";
cin>>username;
if(!(checkUnique(username))){
cout<<"Username already taken....";
return SignUP();
}
else{
cout<<"Enter Password: ";
cin>>password;
int id = getLastID();
if(createUser(username,password, id+1)){
cout<<"User created with ID: "<<id+1<<endl;
return new User(id+1, username);
}
else{
return nullptr;
}
}
} //SignUp ends here
User* authenticate(){
int choice;
cout<<"Enter 1 to Login\n"
<<"Enter 2 to SignUP: ";
cin>>choice;
if (choice == 1){
User* user = this->logIn();
if(user){
cout<<"WELCOME "<<user->username<<endl;
return user;
}
else{
cout<<"Incorrect Username or Password....."<<endl;
return nullptr;
}
}
else if(choice == 2){
User* user = this->SignUP();
if(user){
cout<<"WELCOME "<<user->username<<endl;
return user;
}
else{
cout<<"We are having Technical Issues.... Try Again..."<<endl;
return nullptr;
}
}
}
//Function to Split String(Genre and Production strings to vectors) helper for loading dataset
vector<string> splitString(const string& input) {
vector<string> tokens;
stringstream ss(input);
string token;
char d = '-';
while (getline(ss, token, d)) {
tokens.push_back(token);
}
return tokens;
}
// Function to load all the Data from CSV
LinkedList* loadData(LinkedList*& movieList){
ifstream fin("movies_metadata.csv");
string line, word;
vector<string> lineData;
int lines = 0;
while (getline(fin, line)) {
stringstream s(line);
while (getline(s, word, ',')) {
lineData.push_back(word);
}
// Ensure that the line contains the expected number of fields
if (lineData.size() == 8) {
// Type casting id, vote_count, and runtime from string to int, and vote_average from string to float
stringstream idStream(lineData[1]);
stringstream voteCountStream(lineData[2]);
stringstream voteAverageStream(lineData[3]);
stringstream runtimeStream(lineData[5]);
int id, voteCount, runtime;
double voteAverage;
idStream >> id;
voteCountStream >> voteCount;
voteAverageStream >> voteAverage;
runtimeStream >> runtime;
vector<string> production = splitString(lineData[6]);
vector<string> genres = splitString(lineData[7]);
// Adding data to linked list
movieList->addMovie(lineData[0], id, voteCount, voteAverage, lineData[4], runtime, production, genres );
} else {
// Handle invalid data format
cerr << "Invalid data format in line " << lines + 1 << ": " << line << endl;
}
lineData.clear();
lines++;
}
fin.close();
return movieList;
}
};
#endif