Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdlib>
- #include <fstream>
- #include <algorithm>
- #include <opencv2/opencv.hpp>
- #include<deque>
- #include "MPleaseHeader.h"
- using namespace std;
- using namespace cv;
- MovieList::MovieList()//insert new movie
- {
- ifstream infile;
- mnodehead = NULL;
- Movie *pre;
- pre = new Movie[MovieLineCount(infile)];
- MovieInfile(infile, pre);
- }
- int MovieList::MovieIDGenerator()//generates movie ID automatically
- {
- int max;//holds value of highest vidID and return it after incrementing it by 1
- MovieNode *nodePtr;
- if (!mnodehead)
- {
- cout << "Movie list is empty." << endl;
- system("pause");
- }
- else
- {
- nodePtr = mnodehead;
- while (nodePtr)
- {
- if (nodePtr->next != NULL)
- {
- nodePtr = nodePtr->next;
- }
- else
- {
- max = nodePtr->movies.vidID;
- return max + 1;
- }
- }
- }
- }
- void MovieList::MovieInfile(ifstream &infile, Movie movloader[])
- {
- Movie movholder;//temporary holder of the movies struct retrieved in the text file
- int counter = 0;//iterator for the index of the loader struct array
- infile.open("movies2img.txt");
- if (infile.fail())
- {
- cout << "Error! Movie text file has not yet been created." << endl;
- system("pause");
- return;
- }
- else
- {
- while (!infile.eof())
- {
- infile >> movholder.vidID;
- infile.ignore();
- getline(infile, movholder.title);
- getline(infile, movholder.genre);
- getline(infile, movholder.production);
- infile >> movholder.copies;
- infile.ignore();
- getline(infile, movholder.filename);
- movloader[counter] = movholder;
- counter+= 1;
- }
- for (int i = 0; i < counter; i++)
- {
- InsertNewMovie(movloader[i]);
- }
- }
- infile.close();
- return;
- }
- int MovieList::MovieLineCount(ifstream &infile)//counts the number of lines in the movie text file and returns it after dividing it by six for determining the size of the array
- {
- string holder;//so the while loop will work
- int count = 0;//counts the lines in the text file
- infile.open("movies2img.txt");
- if (infile.fail())
- {
- cout << "Error! Movie text file has not yet been created." << endl;
- system("pause");
- return 0;
- }
- else
- {
- while (getline(infile, holder))
- {
- count++;
- }
- }
- infile.close();
- system("pause");
- return (count / 6);//count is divided by 6 because there are 6 members inside each node of movies;
- }
- void MovieList::RentMovie(int vidID)//subtracts the number of copies of one movie rented by the user
- {
- MovieNode *previousNode, *nodePtr;
- int found = 0;
- if (!mnodehead)
- {
- cout << "Movie List is empty" << endl;
- return;
- }
- if (mnodehead->movies.vidID == vidID)
- {
- if (Availability(mnodehead->movies.vidID))
- {
- cout << "Movie has been succesfully rented! " << endl;
- mnodehead->movies.copies = mnodehead->movies.copies - 1;
- found = 1;
- }
- else if (!Availability(mnodehead->movies.vidID))
- {
- cout << "Movie is not available." << endl;
- }
- }
- else
- {
- nodePtr = mnodehead;
- previousNode = NULL;
- while (nodePtr != NULL && nodePtr->movies.vidID != vidID)
- {
- previousNode = nodePtr;
- nodePtr = nodePtr->next;
- }
- if (nodePtr != NULL)
- {
- if (Availability(nodePtr->movies.vidID))
- {
- cout << "Movie has been succesfully rented! " << endl;
- nodePtr->movies.copies = nodePtr->movies.copies - 1;
- found = 1;
- }
- else if (!Availability(nodePtr->movies.vidID))
- {
- cout << "Movie is not available." << endl;
- }
- found = 1;
- }
- }
- if (found == 0)
- {
- cout << "Movie is not available!" << endl;
- }
- }
- void MovieList::PrintMovieList()//Displays all movies
- {
- MovieNode *nodePtr;
- if (mnodehead == NULL)
- {
- cout << "Movie list is empty" << endl;
- }
- else
- {
- nodePtr = mnodehead;
- while (nodePtr)
- {
- cout << "Movie Code :" << nodePtr->movies.vidID << endl;
- cout << "Title :" << nodePtr->movies.title << endl;
- cout << "Genre :" << nodePtr->movies.genre << endl;
- cout << "Production :" << nodePtr->movies.production << endl;
- cout << "# of Copies :" << nodePtr->movies.copies << endl;
- cout << "Image Filename :" << nodePtr->movies.filename << endl;
- cout << "*********************" << endl;
- cout << endl;
- nodePtr = nodePtr->next;
- }
- }
- }
- void MovieList::InsertNewMovie(Movie movie)//Inserts a new movie node
- {
- MovieNode *newNode, *nodePtr, *previousNode;
- newNode = new MovieNode;
- newNode->movies.vidID = movie.vidID;
- newNode->movies.title = movie.title;
- newNode->movies.genre = movie.genre;
- newNode->movies.production = movie.production;
- newNode->movies.filename = movie.filename;
- newNode->movies.copies = movie.copies;
- newNode->next = NULL;
- if (!mnodehead)
- {
- mnodehead = newNode;
- newNode->next = NULL;
- }
- else
- {
- nodePtr = mnodehead;
- previousNode = NULL;
- while (nodePtr != NULL && nodePtr->movies.vidID < movie.vidID)
- {
- previousNode = nodePtr;
- nodePtr = nodePtr->next;
- }
- if (previousNode == NULL)
- {
- mnodehead = newNode;
- newNode->next = nodePtr;
- }
- else
- {
- previousNode->next = newNode;
- newNode->next = nodePtr;
- }
- }
- }
- void MovieList::ReturnMovie(int vidID)//returns a movie, adding the 1 to its number of copies
- {
- MovieNode *nodePtr;
- if (mnodehead->movies.vidID == vidID)
- {
- ShowMovieDetails(vidID);
- mnodehead->movies.copies += 1;
- }
- else
- {
- nodePtr = mnodehead;
- while (nodePtr != NULL && nodePtr->movies.vidID != vidID)
- {
- nodePtr = nodePtr->next;
- }
- if (nodePtr != NULL)
- {
- nodePtr->movies.copies += 1;
- }
- else
- {
- cout << "Movie unavailable.";
- }
- }
- cout << "\nMovie has been successfully returned!" << endl;
- }
- void MovieList::ShowMovieDetails(int vidID)//displays the details of the movie along with its movie poster
- {
- Mat image;
- MovieNode *nodePtr;
- int found = 0;
- if (!mnodehead)
- {
- cout << "There are no movies available." << endl;
- return;
- }
- if (mnodehead->movies.vidID == vidID)//checks if first movie in the list is the movie
- {
- nodePtr = mnodehead;
- cout << "Movie Title: " << nodePtr->movies.title;
- cout << "\nMovie Genre: " << nodePtr->movies.genre;
- cout << "\nMovie Production: " << nodePtr->movies.production;
- cout << "\nMovie Number of Copies: " << nodePtr->movies.copies;
- cout << "\nImage Filename: " << nodePtr->movies.filename;
- image = imread(nodePtr->movies.filename + ".jpg");
- if (image.empty())//if the image does not exist, a message will instead be displayed
- {
- cout << "\nImage does not exist.";
- }
- else//else, if the image does exist, the image will be displayed
- {
- imshow("Movie Poster", image);
- }
- waitKey(0);
- found = 1;
- }
- else//goes through the rest of thie list if the movie is not found
- {
- nodePtr = mnodehead;
- while (nodePtr != NULL && nodePtr->movies.vidID != vidID)
- {
- nodePtr = nodePtr->next;
- }
- if (nodePtr != NULL)
- {
- cout << "Movie Title: " << nodePtr->movies.title;
- cout << "\nMovie Genre: " << nodePtr->movies.genre;
- cout << "\nMovie Production: " << nodePtr->movies.production;
- cout << "\nMovie Number of Copies: " << nodePtr->movies.copies;
- cout << "\nImage Filename: " << nodePtr->movies.filename;
- image = imread(nodePtr->movies.filename + ".jpg");
- if (image.empty())
- {
- cout << "\nImage does not exist.";
- }
- else
- {
- imshow("Movie Poster", image);
- }
- waitKey(0);
- found = 1;
- }
- }
- if (found == 0)
- {
- cout << "Movie does not exist." << endl;
- }
- }
- void MovieList::CheckAvailability(int vidID)//calls the availability function to determine whether a movie is available or not
- {
- MovieNode *nodePtr, *previousNode;
- int found = 0;
- if (!mnodehead)
- {
- cout << "There are no movies available." << endl;
- return;
- }
- if (mnodehead->movies.vidID == vidID)
- {
- nodePtr = mnodehead;
- cout << "Movie Title: " << nodePtr->movies.title;
- cout << "\nMovie Genre: " << nodePtr->movies.genre;
- cout << "\nMovie Production: " << nodePtr->movies.production;
- cout << "\nMovie Number of Copies: " << nodePtr->movies.copies;
- cout << "\nImage Filename: " << nodePtr->movies.filename;
- if (Availability(vidID))
- {
- cout << "\nAvailability: Available" << endl;
- }
- else
- {
- cout << "\nAvailability: Unavailable" << endl;
- }
- found = 1;
- }
- else
- {
- nodePtr = mnodehead;
- previousNode = NULL;
- while (nodePtr != NULL && nodePtr->movies.vidID != vidID)
- {
- previousNode = nodePtr;
- nodePtr = nodePtr->next;
- }
- if (nodePtr != NULL)
- {
- cout << "\nMovie Code: " << nodePtr->movies.vidID;
- cout << "\nMovie Title: " << nodePtr->movies.title;
- cout << "\nMovie Genre: " << nodePtr->movies.genre;
- cout << "\nMovie Production: " << nodePtr->movies.production;
- cout << "\nMovie Number of Copies: " << nodePtr->movies.copies;
- cout << "\nImage Filename: " << nodePtr->movies.filename;
- if (Availability(vidID))
- {
- cout << "\nAvailability: Available" << endl;
- }
- else
- {
- cout << "\nAvailability: Unavailable" << endl;
- }
- found = 1;
- }
- }
- if (found == 0)
- {
- cout << "Movie does not exist." << endl;
- }
- }
- bool MovieList::Availability(int vidID)//returns a bool value, if copies < 1 then the movie is unavailable
- {
- MovieNode *nodePtr, *previousNode;
- bool availability;
- int found = 0;
- if (!mnodehead)
- {
- cout << "There are no movies available." << endl;
- return false;
- }
- if (mnodehead->movies.vidID == vidID)
- {
- nodePtr = mnodehead;
- if (mnodehead->movies.copies > 0)
- {
- availability = true;
- }
- else
- {
- availability = false;
- }
- found = 1;
- }
- else
- {
- nodePtr = mnodehead;
- previousNode = NULL;
- while (nodePtr != NULL && nodePtr->movies.vidID != vidID)
- {
- previousNode = nodePtr;
- nodePtr = nodePtr->next;
- }
- if (nodePtr != NULL)
- {
- // original code: previousNode->next = nodePtr;
- if (nodePtr->movies.copies > 0)
- {
- availability = true;
- }
- else
- {
- availability = false;
- }
- found = 1;
- }
- }
- if (found == 0)
- {
- cout << "Movie does not exist." << endl;
- }
- return availability;
- }
- MovieList::~MovieList()
- {
- MovieNode *nodePtr, *nextNode;
- ofstream outfile;
- outfile.open("movies2img.txt");
- if (mnodehead == NULL)
- {
- cout << "Movie list is empty" << endl;
- }
- else
- {
- nodePtr = mnodehead;//nodePtr traverses the list and outputs the contents of each node
- while (nodePtr)
- {
- outfile << nodePtr->movies.vidID << endl;
- outfile << nodePtr->movies.title << endl;
- outfile << nodePtr->movies.genre << endl;
- outfile << nodePtr->movies.production << endl;
- outfile << nodePtr->movies.copies << endl;
- if (nodePtr->next == NULL)
- {
- outfile << nodePtr->movies.filename;
- }
- else
- {
- outfile << nodePtr->movies.filename << endl;
- }
- nodePtr = nodePtr->next;
- }
- }
- outfile.close();
- nodePtr = mnodehead;
- while (nodePtr != NULL)
- {
- nextNode = nodePtr->next;
- delete nodePtr;
- nodePtr = nextNode;
- }
- cout << "Movie List has been destroyed!" << endl;
- }
- //Customer Codes
- CustomerList::CustomerList()
- {
- ifstream infile;
- cnodehead = NULL;
- Customer *pre;
- pre = new Customer[CustomerLineCount(infile)];
- CustomerInfile(infile, pre);
- }
- int CustomerList::CustomerLineCount(ifstream &infile)//similar logic to movielinecount, will count number of lines in customer text file and return them divided by three which is representative of the contents of each customer struct
- {
- string temp;//holds the text inside the text file for customers
- int count = 0;
- infile.open("customers.txt");
- if (infile.fail())
- {
- cout << "Error! Customer text file has not yet been created!" << endl;
- system("pause");
- return 0;
- }
- else
- {
- while (getline(infile, temp))
- {
- count++;
- }
- }
- infile.close();
- return (count / 3);
- }
- void CustomerList::CustomerInfile(ifstream &infile, Customer custloader[])//used for gathering the data from the text file.
- {
- Customer custholder;
- infile.open("customers.txt");
- if (infile.fail())
- {
- cout << "Error! Customer text file has not yet been created!" << endl;
- system("pause");
- return;
- }
- else
- {
- int iterator = 0;
- while (!infile.eof())
- {
- infile >> custholder.custID;
- infile.ignore();
- getline(infile, custholder.name);
- getline(infile, custholder.address);
- custloader[iterator] = custholder;
- iterator += 1;
- }
- for (int i = 0; i < iterator; i++)
- {
- addCustomer(custloader[i]);
- }
- }
- infile.close();
- }
- int CustomerList::CustomerIDGenerator()//generates new ID by finding the highest ID in the customerlist and incrementing it by 1 before returning it
- {
- int max;//holds value of highest custID and return it after incrementing it by 1
- CustomerNode *nodePtr;
- if (!cnodehead)
- {
- cout << "Movie list is empty." << endl;
- system("pause");
- }
- else
- {
- nodePtr = cnodehead;
- while (nodePtr)
- {
- if (nodePtr->next != NULL)
- {
- nodePtr = nodePtr->next;
- }
- else
- {
- max = nodePtr->customers.custID;
- return max + 1;
- }
- }
- }
- }
- void CustomerList::addCustomer(Customer customer)//adds the customer
- {
- CustomerNode *newNode, *nodePtr, *previousNode;
- newNode = new CustomerNode;
- newNode->customers.custID = customer.custID;//automatically generated
- newNode->customers.name = customer.name;
- newNode->customers.address = customer.address;
- newNode->next = NULL;
- if (!cnodehead)
- {
- cnodehead = newNode;
- newNode->next = NULL;
- }
- else
- {
- nodePtr = cnodehead;
- previousNode = NULL;
- while (nodePtr != NULL && nodePtr->customers.custID < customer.custID)
- {
- previousNode = nodePtr;
- nodePtr = nodePtr->next;
- }
- if (previousNode == NULL)
- {
- cnodehead = newNode;
- newNode->next = nodePtr;
- }
- else
- {
- previousNode->next = newNode;
- newNode->next = nodePtr;
- }
- }
- }
- void CustomerList::showCustomer(int ID)//shows the info of each customer
- {
- CustomerNode *nodePtr, *previousNode;
- bool found;
- if (!cnodehead)
- {
- cout << "Customer List empty!" << endl;
- }
- else if (cnodehead->customers.custID == ID)
- {
- system("cls");
- cout << "Customer ID: " << cnodehead->customers.custID;
- cout << "\nCustomer Name: " << cnodehead->customers.name;
- cout << "\nCustomer Address: " << cnodehead->customers.address;
- found = true;
- }
- else
- {
- nodePtr = cnodehead;
- while (nodePtr != NULL && nodePtr->customers.custID != ID)
- {
- previousNode = nodePtr;
- nodePtr = nodePtr->next;
- }
- if (nodePtr != NULL)
- {
- //di pa pantay
- system("cls");
- cout << "Customer ID: " << nodePtr->customers.custID;
- cout << "\nCustomer Name: " << nodePtr->customers.name;
- cout << "\nCustomer Address: " << nodePtr->customers.address;
- found = true;
- }
- }
- if (found == false)
- {
- cout << "Customer does not exist." << endl;
- }
- }
- void CustomerList::printCustomerList()//displays all customers
- {
- CustomerNode *nodePtr;
- nodePtr = cnodehead;
- while (nodePtr != NULL)
- {
- cout <<"Customer ID :" << nodePtr->customers.custID << endl;
- cout << "Customer Name :" << nodePtr->customers.name << endl;
- cout << "Customer Address :" << nodePtr->customers.address << endl;
- cout << "*********************" << endl;
- cout << endl;
- nodePtr = nodePtr->next;
- }
- }
- CustomerList::~CustomerList()//destructor of the customer list that will store all the nodes into the text file
- {
- CustomerNode *nodePtr, *nextNode;
- ofstream outfile;
- outfile.open("customers.txt");
- if (cnodehead == NULL)
- {
- cout << "Customer list is empty" << endl;
- }
- else
- {
- nodePtr = cnodehead;
- while (nodePtr)
- {
- outfile << nodePtr->customers.custID << endl;
- outfile << nodePtr->customers.name << endl;
- if (nodePtr->next)
- {
- outfile << nodePtr->customers.address << endl;
- }
- else
- {
- outfile << nodePtr->customers.address;
- }
- nodePtr = nodePtr->next;
- }
- }
- outfile.close();
- nodePtr = cnodehead;
- while (nodePtr != NULL)
- {
- nextNode = nodePtr->next;
- delete nodePtr;
- nodePtr = nextNode;
- }
- cout << "\nCustomer List has been destroyed!" << endl;
- }
- //Customer Rent Functions
- CustomerRentedList::CustomerRentedList()
- {
- }
- CustomerRentedList::~CustomerRentedList()
- {
- ofstream outfile;
- CustomerRent out;
- deque<int>IDsholder;
- outfile.open("Rented.txt");
- if (outfile.fail())
- {
- cout << "Error! No customer has rented a movie yet." << endl;
- }
- else
- {
- while (!Renter.empty())
- {
- out = Renter.front();
- outfile << '#' << out.customerRenting.custID << endl;
- outfile << out.customerRenting.name << endl;
- outfile << out.customerRenting.address << endl;
- IDsholder = out.vidID;
- while (!IDsholder.empty())
- {
- outfile << IDsholder.front() << endl;
- IDsholder.pop_front();
- }
- }
- }
- outfile.close();
- }
- void CustomerRentedList::RentAVideo(int custID, deque<int> vidIDs)
- {
- CustomerNode *cnodePtr;
- bool found = false;
- CustomerRent holder;
- if (!cnodehead)
- {
- cout << "Customer List empty!" << endl;
- }
- else if (cnodehead->customers.custID == custID)
- {
- holder.customerRenting = cnodehead->customers;
- holder.vidID = vidIDs;
- found = true;
- }
- else
- {
- cnodePtr = cnodehead;
- while (cnodePtr != NULL && cnodePtr->customers.custID != custID)
- {
- cnodePtr = cnodePtr->next;
- }
- if (cnodePtr != NULL)
- {
- //newNode->Renter.customerRenting = cnodePtr->customers;
- holder.customerRenting = cnodePtr->customers;
- holder.vidID = vidIDs;
- found = true;
- }
- }
- if (found == false)
- {
- cout << "Customer does not exist." << endl;
- return;
- }
- Renter.push_back(holder);
- }
- void CustomerRentedList::PrintAllRented(int custID)
- {
- CustomerRent temp;
- int ID;
- if (Renter.empty())
- {
- cout << "Customer Rent List is empty." << endl;
- return;
- }
- temp = Renter.front();
- if (temp.customerRenting.custID == custID)
- {
- showCustomer(custID);
- cout << "\n\nList of Videos Rented..." << endl;
- while (!temp.vidID.empty())
- {
- ID = temp.vidID.front();
- ShowMovieTitle(ID);
- temp.vidID.pop_front();
- }
- }
- }
- void CustomerRentedList::ShowMovieTitle(int vidID)
- {
- MovieNode *nodePtr;
- int found = 0;
- if (!mnodehead)
- {
- cout << "There are no movies available." << endl;
- return;
- }
- if (mnodehead->movies.vidID == vidID)//checks if first movie in the list is the movie
- {
- nodePtr = mnodehead;
- cout << "\nMovie ID: " << vidID;
- cout << "\nMovie Title: " << nodePtr->movies.title;
- }
- else
- {
- nodePtr = mnodehead;
- while (nodePtr != NULL && nodePtr->movies.vidID != vidID)
- {
- nodePtr = nodePtr->next;
- }
- if (nodePtr != NULL)
- {
- cout << "\nMovie ID: " << vidID;
- cout << "\nMovie Title: " << nodePtr->movies.title;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement