diff --git a/OTT.cpp b/OTT.cpp new file mode 100644 index 0000000..1a1ffb2 --- /dev/null +++ b/OTT.cpp @@ -0,0 +1,337 @@ +#include +#include +#include +#include +#include +#include +using namespace std; + +class User { +public: + string name; + string password; + vector rentedMovies; + vector purchasedItems; + int chargeDues; + + User() { + chargeDues = 0; + } +}; + +class Admin { +public: + string name; + string password; + vector movieList; + vector 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 loadUsersFromFile() { + vector 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 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"<> 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"<> movie; + cout << "Rent price: 120\nPay now or add to dues? (NOW/LATER): "<> 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) "<> 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) "<> choice; + cin.ignore(); + if (choice == "yes" || choice == "YES") break; + } +} + +int main() { + callOtt("OTT"); + return 0; +} diff --git a/ros2assignment.zip b/ros2assignment.zip new file mode 100644 index 0000000..5272a09 Binary files /dev/null and b/ros2assignment.zip differ