forked from AerialRobotics-IITK/Induction-Y24
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOTT.cpp
More file actions
337 lines (302 loc) · 11.1 KB
/
OTT.cpp
File metadata and controls
337 lines (302 loc) · 11.1 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
using namespace std;
class User {
public:
string name;
string password;
vector<string> rentedMovies;
vector<string> purchasedItems;
int chargeDues;
User() {
chargeDues = 0;
}
};
class Admin {
public:
string name;
string password;
vector<string> movieList;
vector<string> TVshows;
Admin() {
movieList= {
"The Shawshank Redemption",
"The Godfather",
"The Dark Knight",
"Pulp Fiction",
"Schindler's List",
"The Lord of the Rings: The Return of the King",
"Fight Club",
"Forrest Gump",
"Inception",
"The Matrix",
"Goodfellas",
"The Godfather: Part II",
"Interstellar",
"Gladiator",
"The Silence of the Lambs",
"Titanic",
"Saving Private Ryan",
"The Green Mile",
"Avengers: Endgame",
"The Lion King (1994)"
};
TVshows = {
"Breaking Bad",
"Game of Thrones",
"Stranger Things",
"The Boys",
"The Crown",
"The Last of Us",
"Peaky Blinders",
"Money Heist",
"Dark",
"Chernobyl",
"The Mandalorian",
"The Witcher",
"The Office",
"Friends",
"Narcos",
"Better Call Saul",
"Loki",
"The Queen's Gambit",
"House of the Dragon",
"Wednesday"
};
}
};
//using file handling to save the data of users
void saveUserToFile(const User& user) {
ofstream file("users.txt", ios::app); // Append mode
file << user.name << "," << user.password << "," << user.chargeDues << ",";
for (size_t i = 0; i < user.rentedMovies.size(); ++i) {
file << user.rentedMovies[i];
if (i != user.rentedMovies.size() - 1) file << "|";
}
file << ",";
for (size_t i = 0; i < user.purchasedItems.size(); ++i) {
file << user.purchasedItems[i];
if (i != user.purchasedItems.size() - 1) file << "|";
}
file << "\n";
file.close();
}
vector<User> loadUsersFromFile() {
vector<User> users;
ifstream file("users.txt");
string line;
while (getline(file, line)) {
User user;
stringstream ss(line);
string rented, purchased;
getline(ss, user.name, ',');
getline(ss, user.password, ',');
string dues;
getline(ss, dues, ',');
user.chargeDues = stoi(dues);
getline(ss, rented, ',');
stringstream rs(rented);
string item;
while (getline(rs, item, '|')) {
if (!item.empty()) user.rentedMovies.push_back(item);
}
getline(ss, purchased);
stringstream ps(purchased);
while (getline(ps, item, '|')) {
if (!item.empty()) user.purchasedItems.push_back(item);
}
users.push_back(user);
}
file.close();
return users;
}
void callOtt(string msn) {
vector<User> persons = loadUsersFromFile();
Admin admin;
while (true) {
cout << "... ....... WELCOME ....... ...\n";
cout << ".........SIGN UP......" << endl;
cout << "Want to sign up as user? Type user\n";
cout << "Want to sign up as admin? Type admin\n";
string s;
getline(cin, s);
if (s == "user") {
string p, q;
cout << "Enter your name: (use Snakecase eg. user_case)" << endl;
getline(cin, p);
// Check if user already exists
User* userPtr = nullptr;
for (auto& user : persons) {
if (user.name == p) {
userPtr = &user;
break;
}
}
// If user doesn't exist, create new user
bool isNewUser = (userPtr == nullptr);
if (isNewUser) {
persons.push_back(User());
userPtr = &persons.back();
userPtr->name = p;
}
User& user = *userPtr; // Reference to either existing or new user
cout << "Enter your password (default: 1234): " << endl;
cin >> q;
cin.ignore();
user.password = q;
if (q != "1234") {
cout << "Incorrect password ,try again" << endl;
return;
}
cout << "......WELCOME........" << endl;
cout << "Press 1 -> Browse content\n";
cout << "Press 2 -> Rent movies\n";
cout << "Press 3 -> Return rented content\n";
cout << "Press 4 -> View rented items\n";
cout << "Press 5 -> View purchased items\n";
cout << "Press 6 -> Check charges due\n";
int choice;
cin >> choice;
cin.ignore();
if (choice == 1) {
string content;
cout << "Search your content (Movie/TV Show),(use Snakecase eg. user_case): ";
cin >> content;
int press;
cout << "Press 1 to rent"<<endl;
cout<< "Press 2 to purchase"<<endl;
cout<< "Press 3 to watch"<<endl;
cin >> press;
if (press == 1) {
cout << "Rent price: 120\n Rent period: 1 year\nType 'ok' to rent: ";
string rent;
cin >> rent;
if (rent == "ok") {
user.rentedMovies.push_back(content);
cout << content << " is added to your rented list\n";
}
} else if (press == 2) {
cout << "Pay 200 through UPI\nType 'ok' to buy: ";
string purchase;
cin >> purchase;
if (purchase == "ok") {
user.purchasedItems.push_back(content);
cout << "Thanks for shopping here\n";
}
} else if (press == 3) {
cout<<"duration of movie 3hrs"<<endl;
cout << "Enjoy your movie!\n";
}
} else if (choice == 2) {
cout << "Enter movie name: ,(use Snakecase eg. user_case)"<<endl;
string movie;
cin >> movie;
cout << "Rent price: 120\nPay now or add to dues? (NOW/LATER): "<<endl;
string pay;
cin >> pay;
if (pay == "NOW") {
cout << "Paying 120 via UPI...\n";
user.rentedMovies.push_back(movie);
} else if (pay == "LATER") {
user.chargeDues += 120;
cout << "Added to charge dues\n";
}
} else if (choice == 3) {
cout << "Enter movie name to return:,(use Snakecase eg. user_case) "<<endl;
string movie;
getline(cin, movie);
auto it = find(user.rentedMovies.begin(), user.rentedMovies.end(), movie);
if (it != user.rentedMovies.end()) {
user.rentedMovies.erase(it);
cout << "Returned successfully\n";
} else {
cout << "Movie not found in rented list!\n";
}
} else if (choice == 4) {
cout << "Rented movies:\n";
for (auto& m : user.rentedMovies) cout << m << "\n";
} else if (choice == 5) {
cout << "Purchased items:\n";
for (auto& p : user.purchasedItems) cout << p << "\n";
} else if (choice == 6) {
cout << "Total charges due: " << user.chargeDues << "\n";
}
// Save the user and add to memory
persons.push_back(user);
saveUserToFile(user);
}
else if (s == "admin") {
cout << "Enter name: ";
string name;
getline(cin, name);
admin.name = name;
cout << "Enter password (default 4321): "<<endl;
string pass;
cin >> pass;
cin.ignore();
if (pass == "4321") {
cout << "Press 1 -> Add movie\n";
cout << "Press 2 -> Remove movie\n";
cout << "Press 3 -> View dues\n";
cout << "Press 4 -> View users profile\n";
cout<< "Press 5 -> view list of all movies and tv shows \n";
int press;
cin >> press;
cin.ignore();
if (press == 1) {
string movie;
cout << "Movie/TV show to add:,(use Snakecase eg. admin_case) "<<endl;
getline(cin, movie);
admin.movieList.push_back(movie);
cout << "Added successfully.\n";
} else if (press == 2) {
string movie;
cout << "Movie/TV show to remove:(use Snakecase eg. admin_case) "<<endl;
getline(cin, movie);
auto it = find(admin.movieList.begin(), admin.movieList.end(), movie);
if (it != admin.movieList.end()) {
admin.movieList.erase(it);
cout << "Removed successfully.\n";
} else {
cout << "Not found in list.\n";
}
} else if (press == 3) {
for (auto& u : persons) {
cout << u.name << " : " << u.chargeDues << endl;
}
} else if (press == 4) {
for (auto& u : persons) {
cout << u.name << endl;
}
}
else if(press==5){
cout<<"all movies: "<<endl;
for(int i=0;i<admin.movieList.size();i++){
cout<<admin.movieList[i]<<endl;
}
cout<<endl<<endl;
cout<<"all tv shows: "<<endl;
for(int i=0;i<admin.TVshows.size();i++){
cout<<admin.TVshows[i]<<endl;
}
cout<<endl;
}
} else {
cout << "Wrong password!\n";
}
}
string choice;
cout << "\nExit platform? (yes/no): ";
cin >> choice;
cin.ignore();
if (choice == "yes" || choice == "YES") break;
}
}
int main() {
callOtt("OTT");
return 0;
}