diff --git a/Pradyumn_V/otw.md b/Pradyumn_V/otw.md new file mode 100644 index 0000000..d82e2c4 --- /dev/null +++ b/Pradyumn_V/otw.md @@ -0,0 +1,95 @@ +## Level 0 + +### pswd - bandit0 + +used ssh to login to the server for overthewire where bandit is played + +## Level 1 + +### pswd - ZjLjTmM6FvvyRnrb2rfNWOZOTa6ip5If + +used ls to find readme file and used **cat** to read the contents + +## Level 2 + +### pswd - 263JGJPfgU6LtdEvgfWU1XP5yac29mFx + +used ls to find a file named '-' used ./- to specify the entire directory because passing only cat - can cause problems since - is commonly used to pass arguements to the function + +## Level 3 + +### pswd - MNk8KNH3Usiio41PRUEoDFPqfxLPlSmx + +used quotations to specify the filename when passed as an arguement in cat + +## Level 4 + +### pswd - 2WmrDFRmJIq3IPxneAaMGhap0pFhF3NJ + +used **ls -a** to show all files including hidden ones then read the file using **cat ./...Hidden-From-You** + +## Level 5 + +### pswd - 4oQYVPkxZOOEOO5pTW81FB8j8lxXGUQw + +used file ./* to find the type of text in all files and read the file07 using cat since it contained ASCII characters + +## Level 6 + +### pswd - HWasnPhtq9AVKe0dmk45nxy20cvUa6EG + +executed **file */* | grep "ASCII text" | du -b -a | grep 1033** to extract all ascii text files of size 1033 since only 1 result showed, read that using cat and got the password + +## Level 7 + +### pswd - morbNTDkSW6jIlUc0ymOdMaLnOlFVAaj + +used **find / -user bandit7 -group bandit6 -size 33c 2>/dev/null** we add the last part to hide all permission denied error messages + +## Level 8 + +### pswd - dfwvzFQi4mU0wfNbFOe9RoWskMLg7eEc + +**cat data.txt | grep millionth** returned the complete line containing millionth including the password + +## Level 9 + +### pswd - 4CKMh1JI91bUIZZPXDqGanal4xvAg0JM + +**sort data.txt | uniq -u** sort will sort the file allowing uniq to filter out repeating lines using the -u tag and return the only line appearing once + +## Level 10 + +### pswd - FGUW5ilLVJrxX9kMYMmlN4MgbpfMiqey + +**cat data.txt | strings | grep ==** strings will return all human readable lines and grep filters them + +## Level 11 + +### pswd - dtR173fZKb0RRsDFSGsg2RWnpNVj3qRr + +**cat data.txt | base64 -d** decrypts the encoded text and returns password + +## Level 12 + +### pswd - 7x16WNeHIi5YkIhWsfFIqoognUTyj9Q4 + +**cat data.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m'** translate command is used to execute rotation by 13 on the character skipping numerical values + +## Level 13 + +### pswd - FO5dwFsc0cbaIiH0h8J2eUks2vdTDwAn + +we know that first we extract the hexadecimal contents then on reading it using **xxd** we see gzip compressed files start with 1f 8b as their first few bytes hence we decrypt then we see 425a which is bzip2 we repeat this process and encounter .bin files indicating archive extracted using **tar -xf** + +## Level 14 + +### pswd - MU4VWeTyJk8ROof1qqmcBPaLh7lDCPvS + +first we find the location of the ssh key file using ls then we download it by logging out and accessing the server from our computer using scp (secure copy protocol) for transferring files between hosts over a network then we reduce permissions using chmod 700 and finally login using the sshkey.private with -i tag with ssh + +## Level 15 + +### pswd - 8xCjnmgoKbGLhHFAZlGE5Tmu4M2tKJQo + +submitted level 14 password using **nc localhost 30000** and entering the password when prompted diff --git a/Task2/pradyumn_v/Content.cpp b/Task2/pradyumn_v/Content.cpp new file mode 100644 index 0000000..4ac568d --- /dev/null +++ b/Task2/pradyumn_v/Content.cpp @@ -0,0 +1,7 @@ +#include "Content.h" + +Content::Content(string name, string type, int rated){ + title = name; + genre = type; + rating = (rated<=5)?rated:0; +} \ No newline at end of file diff --git a/Task2/pradyumn_v/Content.h b/Task2/pradyumn_v/Content.h new file mode 100644 index 0000000..f8fe997 --- /dev/null +++ b/Task2/pradyumn_v/Content.h @@ -0,0 +1,13 @@ +#pragma once +#include +using namespace std; + +class Content{ + public: + string title; + string genre; + int rating; + bool is_rented=false; + bool is_purchased=false; + Content(string name, string type, int rated); +}; \ No newline at end of file diff --git a/Task2/pradyumn_v/Dockerfile b/Task2/pradyumn_v/Dockerfile new file mode 100644 index 0000000..daa22e1 --- /dev/null +++ b/Task2/pradyumn_v/Dockerfile @@ -0,0 +1,6 @@ +FROM gcc:latest +WORKDIR /usr/src/app +COPY . . +RUN g++ *.cpp -o media_rental_system +VOLUME ["/app/user", "/app/admin", "/app/catalogues"] +CMD ["./media_rental_system"] diff --git a/Task2/pradyumn_v/admin.cpp b/Task2/pradyumn_v/admin.cpp new file mode 100644 index 0000000..35aa8c1 --- /dev/null +++ b/Task2/pradyumn_v/admin.cpp @@ -0,0 +1,145 @@ +#include "admin.h" + +void Admin::save(const string& filename) { + ofstream out(filename); + if (!out) { + cerr << "Could not open file for writing.\n"; + return; + } + out << username << '\n' << password << '\n'; + + out.close(); +} + +void Admin::load(const string& filename) { + ifstream in(filename); + if (!in) { + cerr << "Could not open file for reading.\n"; + return; + } + getline(in, username); + getline(in, password); + in.close(); +} + + +void Admin::save_catalogues(const string& filename, movie_entry* movie_cat, tv_show_entry* show_cat){ + ofstream out(filename); + if (!out) { + cerr << "Error opening file for writing: " << filename << endl; + return; + } + + movie_entry* m = movie_cat; + while (m) { + Movie* movie = m->data; + out << "MOVIE " << movie->title << " " + << movie->genre << " " << movie->rating << " " + << movie->duration << " " << movie->rent_cost << " " + << movie->purchase_cost << "\n"; + m = m->next; + } + + tv_show_entry* s = show_cat; + while (s) { + Show* show = s->data; + out << "SHOW " << show->title << " " + << show->genre << " " << show->rating << " " + << show->seasons << " " << show->ep_per_season << " " + << show->rent_cost << " " << show->purchase_cost << "\n"; + s = s->next; + } + + out.close(); +} + + + + +movie_entry* Admin::add_movie(string title, string type, int rated, int time, int rent, int purchase, movie_entry* head){ + movie_entry* entry = new movie_entry; + entry->data = new Movie(title, type, rated, time, rent, purchase); + entry->next=nullptr; + bool added = false; + + if(!head){ + return entry; + } + + movie_entry* curr = head; + while(curr->next){ + if(curr->data->genre==entry->data->genre){ + entry->next=curr->next; + curr->next = entry; + added = true; + break; + } + curr = curr->next; + } + if(!added){ + curr->next = entry; + } + return head; +} + +movie_entry* Admin::remove_movie(string name, movie_entry* head){ + movie_entry* curr = head; + movie_entry* prev = nullptr; + if(curr->data->title==name){ + head = curr->next; + return head; + } + while(curr->data->title!=name){ + prev = curr; + curr = curr->next; + if(curr==nullptr){ + return head; + } + } + prev->next = curr->next; + return head; +} + +tv_show_entry* Admin::add_show(string title, string type, int rated, int season, int ep_per_seasons, int time, int rent, int purchase, tv_show_entry* head){ + tv_show_entry* entry = new tv_show_entry; + entry->data = new Show(title, type, rated, season, ep_per_seasons, rent, purchase); + entry->next=nullptr; + bool added = false; + + if(!head){ + return entry; + } + + tv_show_entry* curr = head; + while(curr->next){ + if(curr->data->genre==entry->data->genre){ + entry->next=curr->next; + curr->next = entry; + added = true; + break; + } + curr = curr->next; + } + if(!added){ + curr->next = entry; + } + return head; +} + +tv_show_entry* Admin::remove_show(string name, tv_show_entry* head){ + tv_show_entry* curr = head; + tv_show_entry* prev = nullptr; + if(curr->data->title==name){ + head = curr->next; + return head; + } + while(curr->data->title!=name){ + prev = curr; + curr = curr->next; + if(curr==nullptr){ + return head; + } + } + prev->next = curr->next; + return head; +} \ No newline at end of file diff --git a/Task2/pradyumn_v/admin.h b/Task2/pradyumn_v/admin.h new file mode 100644 index 0000000..1b70171 --- /dev/null +++ b/Task2/pradyumn_v/admin.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include "show_entry.h" +#include "movie_entry.h" +#include +using namespace std; + +class Admin{ + public: + string username; + string password; + void save(const string& filename); + void load(const string& filename); + void save_catalogues(const string& filename, movie_entry* movie_cat, tv_show_entry* show_cat); + movie_entry* add_movie(string title, string type, int rated, int time, int rent, int purchase, movie_entry* head); + movie_entry* remove_movie(string name, movie_entry* head); + tv_show_entry* add_show(string title, string type, int rated, int season, int ep_per_seasons, int time, int rent, int purchase, tv_show_entry* head); + tv_show_entry* remove_show(string name, tv_show_entry* head); +}; \ No newline at end of file diff --git a/Task2/pradyumn_v/admin/admin1.dat b/Task2/pradyumn_v/admin/admin1.dat new file mode 100644 index 0000000..3d47a4c --- /dev/null +++ b/Task2/pradyumn_v/admin/admin1.dat @@ -0,0 +1,2 @@ +admin1 +34567 diff --git a/Task2/pradyumn_v/catalogues/data.dat b/Task2/pradyumn_v/catalogues/data.dat new file mode 100644 index 0000000..d0d5244 --- /dev/null +++ b/Task2/pradyumn_v/catalogues/data.dat @@ -0,0 +1,3 @@ +MOVIE MeBeforeYou Romantic 3 100 120 140 +SHOW TBBT SitCom 4 8 24 300 350 +SHOW HIMYM SitCom 2 11 13 400 3000 diff --git a/Task2/pradyumn_v/main.cpp b/Task2/pradyumn_v/main.cpp new file mode 100644 index 0000000..50b05c7 --- /dev/null +++ b/Task2/pradyumn_v/main.cpp @@ -0,0 +1,253 @@ +#include +#include "user.h" +#include "admin.h" +#include +using namespace std; + +void load_cat(const string& filename, movie_entry** movie_cat, tv_show_entry** show_cat) { + ifstream in(filename); + if (!in) { + cerr << "Error opening file for reading: " << filename << endl; + return; + } + + *movie_cat = nullptr; + *show_cat = nullptr; + + string line; + while (getline(in, line)) { + istringstream iss(line); + string type; + iss >> type; + + if (type == "MOVIE") { + string title, genre; + int rating, duration, rent_cost, purchase_cost; + iss >> title >> genre >> rating >> duration >> rent_cost >> purchase_cost; + + Movie* new_movie = new Movie(title, genre, rating, duration, rent_cost, purchase_cost); + movie_entry* new_entry = new movie_entry{new_movie, nullptr}; + + if (!*movie_cat) { + *movie_cat = new_entry; + } else { + movie_entry* current = *movie_cat; + while (current->next) current = current->next; + current->next = new_entry; + } + + } else if (type == "SHOW") { + string title, genre; + int rating, seasons, ep_per_season, rent_cost, purchase_cost; + iss >> title >> genre >> rating >> seasons >> ep_per_season >> rent_cost >> purchase_cost; + + Show* new_show = new Show(title, genre, rating, seasons, ep_per_season, rent_cost, purchase_cost); + tv_show_entry* new_entry = new tv_show_entry{new_show, nullptr}; + + if (!*show_cat) { + *show_cat = new_entry; + } else { + tv_show_entry* current = *show_cat; + while (current->next) current = current->next; + current->next = new_entry; + } + } + } + in.close(); +} + +int main(){ + int logged_in = 0, rated, duration, rent, purchase, seasons, episodes; + string user, pswd, input, title, type; + int decision = 0, decision_ua=0; + movie_entry* movie_cat = nullptr; + tv_show_entry* show_cat = nullptr; + load_cat("catalogues/data.dat", &movie_cat, &show_cat); + User* active_user=nullptr; + Admin* active_admin=nullptr; + while(true){ + if(!logged_in){ + cout<<"[1] Login"<>decision; + if(decision==1){ + cout<<"Enter Username: "<>user; + cout<<"Enter Password: "<>pswd; + cout<<"[1] Admin"<>decision_ua; + if(decision_ua==1){ + active_admin = new Admin; + active_admin->load("admin/"+user+".dat"); + if(active_admin->password==pswd){ + logged_in=2; + } + else{ + cout<<"Username or password is incorrect.\n"; + active_admin = nullptr; + logged_in=0; + } + } + if(decision_ua==2){ + active_user = new User; + active_user->load("users/"+user+".dat", movie_cat, show_cat); + if(active_user->password==pswd){ + logged_in=1; + } + else{ + cout<<"Username or password is incorrect.\n"; + active_admin = nullptr; + logged_in=0; + } + } + } + else if(decision==2){ + cout<<"[1] Admin"<>decision; + if(decision==1){ + cout<<"Enter Admin Username"<>user; + cout<<"Enter Admin Password"<>pswd; + active_admin = new Admin; + active_admin->username = user; + active_admin->password = pswd; + logged_in=2; + } + else{ + + cout<<"Enter Username"<>user; + cout<<"Enter Password"<>pswd; + active_user = new User; + active_user->username = user; + active_user->password = pswd; + logged_in=1; + } + } + + else{ + break; + } + + } + + if(logged_in==1){ + cout<<"[1] Search by title\n[2] Search by genre\n[3] Rent a title\n[4] Purchase a title\n[5] View Purchased\n[6] View Rented\n[7] Show dues\n[8] Return title\n[9] Log out\n"; + cin>>decision; + switch(decision){ + case 1: + cout<<"Enter the title: \n"; + cin>>input; + active_user->search_title(input, movie_cat, show_cat); + break; + case 2: + cout<<"Enter the genre: \n"; + cin>>input; + active_user->search_genre(input, movie_cat, show_cat); + break; + case 3: + cout<<"Enter the title you wish to rent: \n"; + cin>>input; + active_user->rent(input, movie_cat, show_cat); + break; + case 4: + cout<<"Enter the title you wish to purchase: \n"; + cin>>input; + active_user->purchase(input, movie_cat, show_cat); + break; + case 5: + active_user->view_purchased(); + break; + case 6: + active_user->view_rented(); + break; + case 7: + active_user->dues(); + break; + case 8: + cout<<"Enter the title you wish to return: \n"; + cin>>input; + active_user->return_(input); + break; + case 9: + logged_in = false; + + active_user->save("users/"+active_user->username+".dat"); + active_user=nullptr; + cout<<"Successfuly logged out\n"; + break; + + } + } + else if(logged_in==2){ + cout<<"[1] Add a movie\n[2] Add a show\n[3] Remove a movie\n[4] Remove a show\n[5] Log out\n"; + cin>>decision; + switch(decision){ + case 1: + cout<<"Title: "; + cin>>title; + cout<<"\nGenre: "; + cin>>type; + cout<<"\nRating: "; + cin>>rated; + cout<<"\nDuration: "; + cin>>duration; + cout<<"\nRent Cost: "; + cin>>rent; + cout<<"\nPurchase Cost: "; + cin>>purchase; + movie_cat = active_admin->add_movie(title, type, rated, duration, rent, purchase, movie_cat); + cout<<"Movie has been added\n"; + break; + case 2: + cout<<"Title: "; + cin>>title; + cout<<"\nGenre: "; + cin>>type; + cout<<"\nRating: "; + cin>>rated; + cout<<"\nSeasons: "; + cin>>seasons; + cout<<"\nEpisodes: "; + cin>>episodes; + cout<<"\nDuration Per Episode: "; + cin>>duration; + cout<<"\nRent Cost: "; + cin>>rent; + cout<<"\nPurchase Cost: "; + cin>>purchase; + show_cat = active_admin->add_show(title, type, rated, seasons, episodes, duration, rent, purchase, show_cat); + cout<<"Show has been added\n"; + break; + case 3: + cout<<"Enter Title to remove: "; + cin>>title; + movie_cat = active_admin->remove_movie(title, movie_cat); + break; + case 4: + cout<<"Enter Title to remove: "; + cin>>title; + show_cat = active_admin->remove_show(title, show_cat); + break; + case 5: + logged_in = false; + active_admin->save("admin/"+active_admin->username+".dat"); + active_admin->save_catalogues("catalogues/data.dat", movie_cat, show_cat); + active_admin=nullptr; + cout<<"Successfully logged out\n"; + break; + } + } +} + + return 0; + +} + +//docker \ No newline at end of file diff --git a/Task2/pradyumn_v/media_rental_system b/Task2/pradyumn_v/media_rental_system new file mode 100755 index 0000000..5eaaa25 Binary files /dev/null and b/Task2/pradyumn_v/media_rental_system differ diff --git a/Task2/pradyumn_v/movie.cpp b/Task2/pradyumn_v/movie.cpp new file mode 100644 index 0000000..8d7af68 --- /dev/null +++ b/Task2/pradyumn_v/movie.cpp @@ -0,0 +1,7 @@ +#include "movie.h" + +Movie::Movie(string name, string type, int rated, int time, int rent, int purchase):Content(name, type, rated){ + duration = time; + rent_cost = rent; + purchase_cost = purchase; +}; \ No newline at end of file diff --git a/Task2/pradyumn_v/movie.h b/Task2/pradyumn_v/movie.h new file mode 100644 index 0000000..675d939 --- /dev/null +++ b/Task2/pradyumn_v/movie.h @@ -0,0 +1,13 @@ +#pragma once +#include +#include "Content.h" + +using namespace std; + +class Movie: public Content{ + public: + int duration; + int rent_cost; + int purchase_cost; + Movie(string name, string type, int rated, int time, int rent, int purchase); +}; \ No newline at end of file diff --git a/Task2/pradyumn_v/movie_entry.h b/Task2/pradyumn_v/movie_entry.h new file mode 100644 index 0000000..6428130 --- /dev/null +++ b/Task2/pradyumn_v/movie_entry.h @@ -0,0 +1,8 @@ +#pragma once +#include +#include "movie.h" + +struct movie_entry{ + Movie* data; + movie_entry* next; +}; \ No newline at end of file diff --git a/Task2/pradyumn_v/show.cpp b/Task2/pradyumn_v/show.cpp new file mode 100644 index 0000000..7397d43 --- /dev/null +++ b/Task2/pradyumn_v/show.cpp @@ -0,0 +1,8 @@ +#include "show.h" + +Show::Show(string name, string type, int rated, int season, int ep_per_seasons, int rent, int purchase):Content(name, type, rated){ + seasons = season; + ep_per_season = ep_per_seasons; + rent_cost = rent; + purchase_cost = purchase; +}; \ No newline at end of file diff --git a/Task2/pradyumn_v/show.h b/Task2/pradyumn_v/show.h new file mode 100644 index 0000000..ecffccf --- /dev/null +++ b/Task2/pradyumn_v/show.h @@ -0,0 +1,12 @@ +#pragma once +#include +#include "Content.h" + +class Show: public Content{ + public: + int seasons; + int ep_per_season; + int rent_cost; + int purchase_cost; + Show(string name, string type, int rated, int season, int ep_per_seasons, int rent, int purchase); +}; \ No newline at end of file diff --git a/Task2/pradyumn_v/show_entry.h b/Task2/pradyumn_v/show_entry.h new file mode 100644 index 0000000..7c4d489 --- /dev/null +++ b/Task2/pradyumn_v/show_entry.h @@ -0,0 +1,9 @@ +#pragma once +#include +#include "show.h" +using namespace std; + +struct tv_show_entry{ + Show* data; + tv_show_entry* next; +}; \ No newline at end of file diff --git a/Task2/pradyumn_v/user.cpp b/Task2/pradyumn_v/user.cpp new file mode 100644 index 0000000..9b37d60 --- /dev/null +++ b/Task2/pradyumn_v/user.cpp @@ -0,0 +1,335 @@ +#include "user.h" +#include + +void User::search_title(string name, movie_entry* movie_catalog, tv_show_entry* show_catalog){ + tv_show_entry* iter = show_catalog; + movie_entry* iter_movie = movie_catalog; + bool printed=false; + while(iter){ + if(iter->data->title==name){ + cout<<"--------------------"<data->title<data->genre<data->seasons<data->ep_per_season<data->rent_cost<data->purchase_cost<next; + } + + while(iter_movie){ + if(iter_movie->data->title==name){ + cout<<"--------------------"<data->title<data->genre<data->duration<data->rent_cost<data->purchase_cost<next; + } + if(!printed){ + cout<<"Could not find title"; + } +} + +void User::search_genre(string genres, movie_entry* movie_catalog, tv_show_entry* show_catalog){ + tv_show_entry* iter = show_catalog; + movie_entry* iter_movie = movie_catalog; + bool printed = false; + while(iter){ + if(iter->data->genre==genres){ + cout<<"--------------------"<data->title<data->genre<data->seasons<data->ep_per_season<data->rent_cost<data->purchase_cost<next; + } + + while(iter_movie){ + if(iter_movie->data->genre==genres){ + cout<<"--------------------"<data->title<data->genre<data->duration<data->rent_cost<data->purchase_cost<next; + } + if(!printed){ + cout<<"Could not find title\n"; + } +} + +void User::return_(string name){ + movie_entry* curr = rented; + movie_entry* prev = nullptr; + while(curr){ + if(curr->data->title == name){ + if(prev) prev->next = curr->next; + else rented = curr->next; + delete curr; + cout << "Movie returned"<next; + } + + tv_show_entry* curr_show = rented_show; + tv_show_entry* prev_show = nullptr; + while(curr_show){ + if(curr_show->data->title == name){ + if(prev_show) prev_show->next = curr_show->next; + else rented_show = curr_show->next; + delete curr_show; + cout << "Show returned"<next; + } + + cout << "Item not found\n"; +} + + +void User::dues(){ + cout<data->title==name){ + found=true; + break; + } + curr=curr->next; + } + + while(curr_show!=nullptr){ + if(curr_show->data->title==name){ + found=true; + break; + } + curr_show=curr_show->next; + } + + if(curr&&found){ + movie_entry* new_head = new movie_entry; + new_head->data = curr->data; + new_head->next = nullptr; + curr = new_head; + if(!rented){ + rented = curr; + } + else{ + curr->next=rented; + rented=curr; + } + + due+=curr->data->rent_cost; + } + else if(curr_show&&found){ + tv_show_entry* new_head = new tv_show_entry; + new_head->data = curr_show->data; + new_head->next = nullptr; + curr_show = new_head; + if(!rented_show){ + rented_show = curr_show; + } + else{ + curr_show->next=rented_show; + rented_show=curr_show; + } + + due+=curr_show->data->rent_cost; + } + else{ + cout<<"Could not find the title you searched for\n"; + } +} + +void User::purchase(string name, movie_entry* movie_catalog, tv_show_entry* tv_catalog){ + movie_entry* curr = movie_catalog; + tv_show_entry* curr_show = tv_catalog; + bool found; + while(curr!=nullptr){ + if(curr->data->title==name){ + found=true; + break; + } + curr=curr->next; + } + + while(curr_show!=nullptr){ + if(curr_show->data->title==name){ + found=true; + break; + } + curr_show=curr_show->next; + } + + if(curr&&found){ + movie_entry* new_head = new movie_entry; + new_head->data = curr->data; + new_head->next = nullptr; + curr = new_head; + if(!purchased){ + purchased = curr; + } + else{ + curr->next=rented; + purchased=curr; + } + + due+=curr->data->rent_cost; + } + else if(curr_show&&found){ + tv_show_entry* new_head = new tv_show_entry; + new_head->data = curr_show->data; + new_head->next = nullptr; + curr_show = new_head; + if(!purchased_show){ + purchased_show = curr_show; + } + else{ + curr_show->next=purchased_show; + purchased_show=curr_show; + } + + due+=curr_show->data->rent_cost; + } + else{ + cout<<"Could not find the title you searched for\n"; + } +} + +void User::view_purchased(){ + movie_entry* iter = purchased; + tv_show_entry* iter_show = purchased_show; + cout<<"Purchased Titles"<data->title<data->genre<data->purchase_cost<next; + } + + while(iter_show!=nullptr){ + cout<<"Title: "<data->title<data->genre<data->purchase_cost<next; + } + cout<<"--------------------"<data->title<data->genre<data->purchase_cost<next; + } + + while(iter_show){ + cout<<"Title: "<data->title<data->genre<data->purchase_cost<next; + } + cout<<"--------------------"<data->title<<'\n'; + m = m->next; + } + m = purchased; + while (m) { + out << "PURCHASED_MOVIE " << m->data->title <<'\n'; + m = m->next; + } + tv_show_entry* s = rented_show; + while (s) { + out << "RENTED_SHOW " << s->data->title << '\n'; + s = s->next; + } + s = purchased_show; + while (s) { + out << "PURCHASED_SHOW " << s->data->title << '\n'; + s = s->next; + } + out.close(); +} + +void User::load(const string& filename, movie_entry* movie_cat, tv_show_entry* show_cat) { + ifstream in(filename); + if (!in) { + cerr << "Could not open file for reading.\n"; + return; + } + getline(in, username); + getline(in, password); + + string due_line; + getline(in, due_line); + due = stoi(due_line); + + string line; + while (getline(in, line)) { + istringstream iss(line); + string type, title, genre; + int rating; + iss >> type >> title >> genre >> rating; + if (type == "RENTED_MOVIE") { + rent(title, movie_cat, show_cat); + } else if (type == "PURCHASED_MOVIE") { + purchase(title, movie_cat, show_cat); + } else if (type == "RENTED_SHOW") { + rent(title, movie_cat, show_cat); + } else if (type == "PURCHASED_SHOW") { + purchase(title, movie_cat, show_cat); + } + } + in.close(); +} + diff --git a/Task2/pradyumn_v/user.h b/Task2/pradyumn_v/user.h new file mode 100644 index 0000000..d94b691 --- /dev/null +++ b/Task2/pradyumn_v/user.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include "show_entry.h" +#include "movie_entry.h" +#include +using namespace std; + +class User{ + private: + movie_entry* rented=nullptr; + movie_entry* purchased=nullptr; + tv_show_entry* rented_show=nullptr; + tv_show_entry* purchased_show=nullptr; + int due = 0; + public: + string username; + string password; + void save(const string& filename); + void load(const string& filename, movie_entry* movie_cat, tv_show_entry* show_cat); + void search_title(string name, movie_entry* movie_catalog, tv_show_entry* show_catalog); + void search_genre(string genre, movie_entry* movie_catalog, tv_show_entry* show_catalog); + void rent(string name, movie_entry* movie_catalog, tv_show_entry* tv_catalog); + void purchase(string name, movie_entry* movie_catalog, tv_show_entry* tv_catalog); + void return_(string name); + void dues(); + void view_purchased(); + void view_rented(); +}; + diff --git a/Task2/pradyumn_v/users/pradyumnv.dat b/Task2/pradyumn_v/users/pradyumnv.dat new file mode 100644 index 0000000..a34d2fc --- /dev/null +++ b/Task2/pradyumn_v/users/pradyumnv.dat @@ -0,0 +1,5 @@ +pradyumnv +123456 +2100 +RENTED_MOVIE MeBeforeYou +PURCHASED_SHOW TBBT