From dd117082a79ec8d2ad8ee787403ef246258bec83 Mon Sep 17 00:00:00 2001 From: Stinson-83 Date: Wed, 14 May 2025 11:38:04 +0530 Subject: [PATCH 1/3] Add files via upload --- content.txt | 2 + start.cpp | 246 ++++++++++++++++++++++++++++++++++++++++++++++++++++ users.txt | 1 + 3 files changed, 249 insertions(+) create mode 100644 content.txt create mode 100644 start.cpp create mode 100644 users.txt diff --git a/content.txt b/content.txt new file mode 100644 index 0000000..7525358 --- /dev/null +++ b/content.txt @@ -0,0 +1,2 @@ +M|k|h|5|6|90.000000|545.000000 +T|g|7g|6|8|46|97.000000|34.000000 diff --git a/start.cpp b/start.cpp new file mode 100644 index 0000000..dfea9a9 --- /dev/null +++ b/start.cpp @@ -0,0 +1,246 @@ +#define USER_H + +#include +#include +#include +#include +#include +using namespace std; + +class user { +private: + string username; + string password; + +public: + user(string uname, string pass) + : username(uname), password(pass) {} + + string getusername() const { return username; } + + bool checkpass(const string& pass) const { + return password == pass; + } + + void showmenu(); +}; + +class systemManager { +private: + vector users; + +public: + void loadUsersFromFile() { + ifstream file("users.txt"); + string line; + + while (getline(file, line)) { + stringstream ss(line); + string uname, pass; + getline(ss, uname, ','); + getline(ss, pass, ','); + users.emplace_back(uname, pass); + } + } + + void saveUserToFile(const string& uname, const string& pass) { + ofstream file("users.txt", ios::app); + file << uname << "," << pass << "\n"; + } + + void signUp(); + void login(); +}; + +class Movie { +public: + string title, genre, rating; + int duration; + float rent_cost, purchase_cost; + + Movie() {} + Movie(string t, string g, string r, int d, float rent, float purchase) + : title(t), genre(g), rating(r), duration(d), + rent_cost(rent), purchase_cost(purchase) {} + + string serialize() const { + return "M|" + title + "|" + genre + "|" + rating + "|" + + to_string(duration) + "|" + to_string(rent_cost) + "|" + to_string(purchase_cost); + } + + void show() const { + cout << "[Movie] " << title << " (" << genre << ", " << rating + << "), " << duration << " mins, Rent: " << rent_cost + << ", Buy: " << purchase_cost << endl; + } +}; + +class TVShow { +public: + string title, genre, rating; + int seasons, episodes; + float rent_cost, purchase_cost; + + TVShow() {} + TVShow(string t, string g, string r, int s, int eps, float rent, float purchase) + : title(t), genre(g), rating(r), seasons(s), episodes(eps), + rent_cost(rent), purchase_cost(purchase) {} + + string serialize() const { + return "T|" + title + "|" + genre + "|" + rating + "|" + + to_string(seasons) + "|" + to_string(episodes) + "|" + + to_string(rent_cost) + "|" + to_string(purchase_cost); + } + + void show() const { + cout << "[TV Show] " << title << " (" << genre << ", " << rating + << "), " << seasons << " seasons, " << episodes << " eps/season, " + << "Rent: " << rent_cost << ", Buy: " << purchase_cost << endl; + } +}; + +void addContent() { + int choice; + cout << "1. Add Movie\n2. Add TV Show\nChoice: "; + cin >> choice; + + ofstream out("content.txt", ios::app); + + if (choice == 1) { + string t, g, r; + int d; + float rc, pc; + cout << "Title Genre Rating Duration RentCost PurchaseCost:\n"; + cin >> t >> g >> r >> d >> rc >> pc; + Movie m(t, g, r, d, rc, pc); + out << m.serialize() << endl; + } else { + string t, g, r; + int s, eps; + float rc, pc; + cout << "Title Genre Rating Seasons Episodes/Season RentCost PurchaseCost:\n"; + cin >> t >> g >> r >> s >> eps >> rc >> pc; + TVShow tv(t, g, r, s, eps, rc, pc); + out << tv.serialize() << endl; + } + + cout << "Content added.\n"; +} + +void viewContent() { + ifstream in("content.txt"); + string line; + + while (getline(in, line)) { + stringstream ss(line); + string type; + getline(ss, type, '|'); + + if (type == "M") { + string t, g, r; + int d; + float rc, pc; + getline(ss, t, '|'); getline(ss, g, '|'); getline(ss, r, '|'); + ss >> d; ss.ignore(); + ss >> rc; ss.ignore(); + ss >> pc; + Movie m(t, g, r, d, rc, pc); + m.show(); + } else if (type == "T") { + string t, g, r; + int s, eps; + float rc, pc; + getline(ss, t, '|'); getline(ss, g, '|'); getline(ss, r, '|'); + ss >> s; ss.ignore(); ss >> eps; ss.ignore(); ss >> rc; ss.ignore(); ss >> pc; + TVShow tv(t, g, r, s, eps, rc, pc); + tv.show(); + } + } +} + +void user::showmenu() { + int choice; + do { + cout << "\n1. Browse Content\n2. Logout\nChoice: "; + cin >> choice; + + if (choice == 1) viewContent(); + } while (choice != 2); +} + +void systemManager::signUp() { + string uname, pass; + cout << "Enter username: "; + cin >> uname; + for (user& u : users) { + if (u.getusername() == uname) { + cout << "Username already exists.\n"; + return; + } + } + cout << "Enter password: "; + cin >> pass; + users.emplace_back(uname, pass); + saveUserToFile(uname, pass); + cout << "Signup successful.\n"; +} + +void systemManager::login() { + string uname, pass; + cout << "Username: "; + cin >> uname; + cout << "Password: "; + cin >> pass; + + if (uname == "admin" && pass == "admin") { + int choice; + do { + cout << "ADMIN PANEL\n1. Add Content\n2. View Content\n3. Logout\nChoice: "; + cin >> choice; + if (choice == 1) addContent(); + else if (choice == 2) viewContent(); + } while (choice != 3); + return; + } + + for (user& u : users) { + if (u.getusername() == uname && u.checkpass(pass)) { + cout << "Login successful.\n"; + u.showmenu(); + return; + } + } + + cout << "Invalid credentials.\n"; +} + +int main() { + systemManager sys; + sys.loadUsersFromFile(); // Load users from file + + int choice; + do { + cout << "\n===== Welcome to StreamIt =====\n"; + cout << "1. Sign Up\n"; + cout << "2. Login\n"; + cout << "3. Exit\n"; + cout << "Enter your choice: "; + cin >> choice; + + switch (choice) { + case 1: + sys.signUp(); + break; + case 2: + sys.login(); + break; + case 3: + cout << "Goodbye!\n"; + break; + default: + cout << "Invalid choice. Please try again.\n"; + } + } while (choice != 3); + + return 0; +} diff --git a/users.txt b/users.txt new file mode 100644 index 0000000..3a0a324 --- /dev/null +++ b/users.txt @@ -0,0 +1 @@ +kritik,1201 From b59b13b9380b68cfb8466d4b639aaca94f1c872c Mon Sep 17 00:00:00 2001 From: Stinson-83 Date: Wed, 14 May 2025 11:50:08 +0530 Subject: [PATCH 2/3] content.txt --- content.txt | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/content.txt b/content.txt index 7525358..442c5f1 100644 --- a/content.txt +++ b/content.txt @@ -1,2 +1,40 @@ -M|k|h|5|6|90.000000|545.000000 -T|g|7g|6|8|46|97.000000|34.000000 +M|Inception|Sci-Fi|8.8|50|200| +M|The Dark Knight|Action|9|45|180| +M|Interstellar|Sci-Fi|8.6|55|220| +M|Parasite|Thriller|8.6|40|170| +M|The Matrix|Sci-Fi|8.7|50|190| +M|Gladiator|Action|8.5|45|175| +M|Joker|Drama|8.4|40|160| +M|La La Land|Musical|8|35|150| +M|Titanic|Romance|7.9|50|200| +M|Shutter Island|Mystery|8.2|40|170| +M|The Godfather|Crime|9.2|55|230| +M|Avengers: Endgame|Superhero|8.4|60|250| +M|Forrest Gump|Drama|8.8|45|180| +M|Fight Club|Thriller|8.8|45|190| +M|The Prestige|Mystery|8.5|40|170| +M|Coco|Animation|8.4|35|140| +M|Whiplash|Drama|8.5|40|160| +M|Toy Story|Animation|8.3|30|120| +M|The Lion King|Animation|8.5|30|130| +M|The Social Network|Biography|7.7|35|150| +T|Breaking Bad|Crime|9.5|100|400 +T|Stranger Things|Sci-Fi|8.7|90|350 +T|Game of Thrones|Fantasy|9.2|110|500 +T|Friends|Comedy|8.9|70|300 +T|The Office|Comedy|8.9|70|280 +T|Sherlock|Mystery|9.1|90|360 +T|Dark|Sci-Fi|8.8|85|320 +T|Narcos|Crime|8.8|80|300 +T|The Crown|Drama|8.6|85|320 +T|Money Heist|Thriller|8.3|85|330 +T|Peaky Blinders|Crime|8.8|90|340 +T|The Mandalorian|Sci-Fi|8.7|90|320 +T|Better Call Saul|Crime|8.9|100|380 +T|The Witcher|Fantasy|8.2|85|310 +T|Brooklyn Nine-Nine|Comedy|8.4|75|290 +T|The Boys|Superhero|8.7|90|340 +T|Lucifer|Fantasy|8.1|85|310 +T|House of Cards|Drama|8.7|80|300 +T|The 100|Sci-Fi|7.6|75|270 +T|Rick and Morty|Animation|9.2|80|320 From 5005c35d03adf2aaa085046f3e26ee347b389a39 Mon Sep 17 00:00:00 2001 From: Stinson-83 Date: Wed, 14 May 2025 15:37:32 +0530 Subject: [PATCH 3/3] Create Dockerfile --- Dockerfile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5d86654 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Use a base image with g++ +FROM gcc:latest + +# Set working directory inside the container +WORKDIR /app + +# Copy your files into the container +COPY start.cpp . +COPY content.txt . +COPY users.txt . + +# Compile your C++ code +RUN g++ start.cpp -o app + +# Run the compiled program by default +CMD ["./app"]