Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use an official GCC image
FROM gcc:latest

# Set working directory
WORKDIR /app

# Copy source files into the container
COPY . .

# Create users directory if not present
RUN mkdir -p users

# Compile the project
RUN g++ -std=c++17 -o netflix main.cpp

# Set the entrypoint to run the CLI
CMD ["./netflix"]
60 changes: 60 additions & 0 deletions Inventory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef INVENTORY_H
#define INVENTORY_H

#include "movie.h"
#include "tvshows.h"
#include <vector>
#include <fstream>

class Inventory {
private:
vector<Content*> contents;

public:
~Inventory() {
for (auto c : contents) delete c;
}

void addContent(Content* c) {
contents.push_back(c);
}

void displayAll() const {
for (const auto& c : contents)
c->display();
}

void displayByGenre(const string& genre) const {
for (const auto& c : contents)
if (c->getGenre() == genre)
c->display();
}

Content* searchByTitle(const string& title) {
for (auto& c : contents)
if (c->getTitle() == title)
return c;
return nullptr;
}

void saveToFile(const string& filename) {
ofstream file(filename);
for (const auto& c : contents)
file << c->serialize() << "\n";
file.close();
}

void loadFromFile(const string& filename) {
ifstream file(filename);
string line;
while (getline(file, line)) {
if (line.find("Movie|") == 0)
contents.push_back(Movie::deserialize(line));
else if (line.find("TVShow|") == 0)
contents.push_back(TVShow::deserialize(line));
}
file.close();
}
};

#endif
27 changes: 27 additions & 0 deletions UserUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef USER_UTILS_H
#define USER_UTILS_H

#include "user.h"
#include <filesystem>

namespace fs = std::filesystem;

inline bool userExists(const string& username) {
return fs::exists("users/" + username + ".txt");
}

inline User* loadUser(const string& username) {
ifstream file("users/" + username + ".txt");
string line;
getline(file, line);
file.close();
return User::deserialize(line);
}

inline void saveUser(User* user) {
ofstream file("users/" + user->getUsername() + ".txt");
file << user->serialize();
file.close();
}

#endif
36 changes: 36 additions & 0 deletions content.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

#ifndef CONTENT_H
#define CONTENT_H

#include <string>
using namespace std;

class Content {
protected:
string title;
string genre;
float rating;
bool is_rented;
bool is_purchased;

public:
Content(string t, string g, float r) : title(t), genre(g), rating(r), is_rented(false), is_purchased(false) {}

virtual void display() const = 0;
virtual float getRentCost() const = 0;
virtual float getPurchaseCost() const = 0;

string getTitle() const { return title; }
string getGenre() const { return genre; }
float getRating() const { return rating; }
bool getIsRented() const { return is_rented; }
bool getIsPurchased() const { return is_purchased; }

void setRented(bool val) { is_rented = val; }
void setPurchased(bool val) { is_purchased = val; }

virtual string serialize() const = 0;
virtual ~Content() {}
};

#endif
41 changes: 41 additions & 0 deletions inventory.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Movie|The Matrix|Sci-Fi|8.7|0|0|136|4.99|14.99
Movie|Inception|Sci-Fi|8.8|0|0|148|5.99|15.99
Movie|Interstellar|Adventure|8.6|0|0|169|6.49|16.99
Movie|The Dark Knight|Action|9.0|0|0|152|5.49|14.49
Movie|Pulp Fiction|Crime|8.9|0|0|154|4.49|13.99
Movie|The Godfather|Crime|9.2|0|0|175|5.99|15.49
Movie|The Shawshank Redemption|Drama|9.3|0|0|142|5.99|14.99
Movie|Forrest Gump|Drama|8.8|0|0|144|4.99|13.49
Movie|Avengers: Endgame|Action|8.4|0|0|181|6.99|17.99
Movie|Parasite|Thriller|8.6|0|0|132|5.49|14.49
Movie|La La Land|Romance|8.0|0|0|128|3.99|11.99
Movie|Spirited Away|Animation|8.6|0|0|125|4.49|12.49
Movie|The Lion King|Animation|8.5|0|0|88|3.99|9.99
Movie|Joker|Drama|8.4|0|0|122|5.99|13.99
Movie|Tenet|Sci-Fi|7.5|0|0|150|4.99|12.99
Movie|Gladiator|Action|8.5|0|0|155|5.49|13.99
Movie|Django Unchained|Western|8.4|0|0|165|4.99|13.49
Movie|Titanic|Romance|7.8|0|0|195|4.49|12.49
Movie|The Social Network|Drama|7.7|0|0|120|3.99|10.99
Movie|1917|War|8.3|0|0|119|4.99|13.99

TVShow|Stranger Things|Horror|8.9|0|0|4|8|3.99|12.99
TVShow|Breaking Bad|Crime|9.5|0|0|5|13|4.99|14.99
TVShow|Friends|Comedy|8.9|0|0|10|24|3.49|9.99
TVShow|Game of Thrones|Fantasy|9.3|0|0|8|10|5.99|18.99
TVShow|The Office|Comedy|8.8|0|0|9|22|3.49|9.99
TVShow|Money Heist|Thriller|8.2|0|0|5|10|4.99|13.99
TVShow|The Mandalorian|Sci-Fi|8.7|0|0|3|8|4.99|12.99
TVShow|Sherlock|Mystery|9.1|0|0|4|3|3.99|11.99
TVShow|Dark|Sci-Fi|8.8|0|0|3|8|4.99|12.49
TVShow|Narcos|Crime|8.8|0|0|3|10|4.49|11.99
TVShow|Brooklyn Nine-Nine|Comedy|8.4|0|0|8|20|3.49|9.49
TVShow|Black Mirror|Sci-Fi|8.8|0|0|5|6|4.99|11.99
TVShow|The Boys|Superhero|8.7|0|0|3|8|4.49|12.49
TVShow|Peaky Blinders|Drama|8.8|0|0|6|6|4.49|13.99
TVShow|The Witcher|Fantasy|8.1|0|0|2|8|4.99|13.49
TVShow|Lucifer|Fantasy|8.2|0|0|6|10|3.99|10.99
TVShow|How I Met Your Mother|Comedy|8.3|0|0|9|22|3.49|9.99
TVShow|Rick and Morty|Animation|9.2|0|0|5|10|3.99|11.99
TVShow|House of the Dragon|Fantasy|8.5|0|0|1|10|5.99|14.99
TVShow|Squid Game|Thriller|8.0|0|0|1|9|4.49|12.49
167 changes: 167 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#include <iostream>
#include <string>
#include <filesystem>
#include "Inventory.h"
#include "user.h"
#include "UserUtils.h"

using namespace std;
namespace fs = std::filesystem;

const string ADMIN_USERNAME = "admin";
const string ADMIN_PASSWORD = "admin123"; // For demo

void userMenu(User* user, Inventory& inventory) {
int choice;
while (true) {
cout << "\nUSER MENU - " << user->getUsername() << "\n";
cout << "1. Browse all content\n2. Search by title\n3. Rent\n4. Purchase\n5. Return\n6. View rented\n7. View purchased\n8. Charges due\n9. Logout\nChoice: ";
cin >> choice;
cin.ignore();

if (choice == 1) {
inventory.displayAll();
} else if (choice == 2) {
string title;
cout << "Enter title: ";
getline(cin, title);
Content* c = inventory.searchByTitle(title);
if (c) c->display();
else cout << "Not found.\n";
} else if (choice == 3) {
string title;
cout << "Enter title to rent: ";
getline(cin, title);
Content* c = inventory.searchByTitle(title);
if (c) user->rent(c);
else cout << "Not found.\n";
} else if (choice == 4) {
string title;
cout << "Enter title to purchase: ";
getline(cin, title);
Content* c = inventory.searchByTitle(title);
if (c) user->purchase(c);
else cout << "Not found.\n";
} else if (choice == 5) {
string title;
cout << "Enter title to return: ";
getline(cin, title);
Content* c = inventory.searchByTitle(title);
if (c) user->returnItem(c);
else cout << "Not found.\n";
} else if (choice == 6) {
user->viewRented();
} else if (choice == 7) {
user->viewPurchased();
} else if (choice == 8) {
user->viewCharges();
} else if (choice == 9) {
saveUser(user);
cout << "Logged out.\n";
break;
} else {
cout << "Invalid choice.\n";
}
}
}

void adminMenu(Inventory& inventory) {
int choice;
while (true) {
cout << "\nADMIN MENU\n";
cout << "1. Add Movie\n2. Add TV Show\n3. Remove Content\n4. View All Content\n5. Logout\nChoice: ";
cin >> choice;
cin.ignore();

if (choice == 1) {
string title, genre;
float rating, rent, purchase;
int duration;
cout << "Enter title, genre, rating, duration, rent cost, purchase cost:\n";
getline(cin, title); getline(cin, genre);
cin >> rating >> duration >> rent >> purchase; cin.ignore();
inventory.addContent(new Movie(title, genre, rating, duration, rent, purchase));
cout << "Movie added.\n";
} else if (choice == 2) {
string title, genre;
float rating, rent, purchase;
int seasons, eps;
cout << "Enter title, genre, rating, seasons, eps/season, rent/season, purchase/season:\n";
getline(cin, title); getline(cin, genre);
cin >> rating >> seasons >> eps >> rent >> purchase; cin.ignore();
inventory.addContent(new TVShow(title, genre, rating, seasons, eps, rent, purchase));
cout << "TV Show added.\n";
} else if (choice == 3) {
string title;
cout << "Enter title to remove: ";
getline(cin, title);
// Simplified: just mark as not available, or skip (you can implement actual removal later)
cout << "Feature not implemented.\n";
} else if (choice == 4) {
inventory.displayAll();
} else if (choice == 5) {
cout << "Admin logged out.\n";
break;
} else {
cout << "Invalid choice.\n";
}
}
}

int main() {
fs::create_directory("users");

Inventory inventory;
inventory.loadFromFile("inventory.txt");

while (true) {
int option;
cout << "\n--- NETFLIX CLI SYSTEM ---\n";
cout << "1. User Sign Up\n2. User Login\n3. Admin Login\n4. Exit\nChoice: ";
cin >> option;
cin.ignore();

if (option == 1) {
string uname;
cout << "Enter new username: ";
getline(cin, uname);
if (userExists(uname)) {
cout << "Username already exists.\n";
} else {
User* u = new User(uname);
saveUser(u);
cout << "Sign-up successful. You can now log in.\n";
}
} else if (option == 2) {
string uname;
cout << "Enter username: ";
getline(cin, uname);
if (!userExists(uname)) {
cout << "User not found.\n";
} else {
User* user = loadUser(uname);
cout << "Welcome " << user->getUsername() << "!\n";
userMenu(user, inventory);
}
} else if (option == 3) {
string uname, pass;
cout << "Enter admin username: ";
getline(cin, uname);
cout << "Enter admin password: ";
getline(cin, pass);
if (uname == ADMIN_USERNAME && pass == ADMIN_PASSWORD) {
adminMenu(inventory);
} else {
cout << "Invalid admin credentials.\n";
}
} else if (option == 4) {
inventory.saveToFile("inventory.txt");
cout << "Exiting...\n";
break;
} else {
cout << "Invalid input.\n";
}
}

return 0;
}
Loading