Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++; This project is based on the Video Store. The Video Store will do the follo

ID: 3826277 • Letter: C

Question

C++; This project is based on the Video Store. The Video Store will do the following tasks: Rent a video; that is, check out a video. Return, or check in, a video. Create a list of videos owned by the store. Show the details of a particular video. Print a list of all the videos in the store. Check whether a particular video is in the store. Maintain a customer database. Print a list of all the videos rented by each customer. The video store has two major components: videos and customers. The common things associated with a video are as follows: Title of the movie Names of the stars Name of the producer Name of the director Name of the production company Number of copies in the store The class videoType will be used to implement a video. The customer object stores information about a customer, such as the first name, last name, account number, and a list of videos rented by the customer. The class customerType will be used to implement a customer. The basic operations on an object of type customerType are as follows: Print the name, the account number, and the list of rented videos. Set the name and the account number. Rent a video; that is, add the rented video to the list. Return a video; that is, delete the rented video from the list. Show the account number. The video store will maintain various lists: A list of all the videos in the store. A list of all the store’s customers. Lists of the videos currently rented by each customer Use the function createVideoList to read the videos data from the videos input file and create a list of videos. Use another function, createCustomerList, to read the customers data from customers input file and create a list of customers. Use the function displayMenu to inform the user what to do.

Explanation / Answer

testVideoStore.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "binarySearchTree.h"
#include "videoType.h"
#include "videoBinaryTree.h"
#include "unorderedLinkedList.h"
#include "customerType.h"


using namespace std;

void createVideoList(ifstream& infile,
                   videoBinaryTree& videoList);
void createCustomerList(ifstream& infile,
                   unorderedLinkedList<customerType>& videoList);

void displayMenu();

void loginView(customerType&, unorderedLinkedList<customerType>&, bool&);

int main()
{
    videoBinaryTree videoList;
   unorderedLinkedList<customerType> custList;
   customerType currentCustomer;
    int choice;
   bool found;   //finding customer rented movies
   bool custLogin = false;   //whether there is a customer logged in
    char ch;
    string title;

    ifstream infile;

    infile.open("videoDat.txt");
    if (!infile)
    {
        cout << "The input file does not exist" << endl;
        return 1;
    }

    createVideoList(infile, videoList);
    infile.close();

   infile.open("custDat.txt");
   if (!infile)
   {
       cout << "The input file does not exist" << endl;
       return 1;
   }

   createCustomerList(infile, custList);
   infile.close();


   loginView(currentCustomer, custList, custLogin); //logs in the customer
   while (custLogin) { //if customer is logged in
       cout << "Your checked out videos:" << endl;
       currentCustomer.printVideos();
       cout <<"________________________"<< endl;
       displayMenu();
       cout << "Enter your choice: ";
       cin >> choice; //get the request
       cin.get(ch);
       cout << endl;

       //process the request
       while (choice != 9)
       {
           switch (choice)
           {
           case 1:
               cout << "Enter the title: ";
               getline(cin, title);
               cout << endl;
               if (videoList.videoSearch(title))
                   cout << "Title found." << endl;
               else
                   cout << "The store does not carry this title."
                   << endl;
               break;

           case 2:
               cout << "Enter the title: ";
               getline(cin, title);
               cout << endl;
               if (videoList.videoSearch(title))
               {
                   if (videoList.isVideoAvailable(title))
                   {
                       currentCustomer.checkOut(title); //updates customers titles
                       videoList.videoCheckOut(title);
                       cout << "Enjoy your movie: " << title << endl;
                   }
                   else
                       cout << "The video is currently out of stock."
                       << endl;
               }
               else
                   cout << "The video is not in the store." << endl;
               break;

           case 3:
               cout << "Enter the title: ";
               getline(cin, title);
               cout << endl;
               if (videoList.videoSearch(title))
               {
                   found = false;
                   currentCustomer.checkIn(title, found); // searches in customer's list
                   if (!found) { // if not found
                       cout << "You dont have this movie" << endl;
                       break;
                   }
                   videoList.videoCheckIn(title);
                   cout << "Thanks for returning " << title << endl;
               }
               else
                   cout << "This video is not from our store." << endl;
               break;

           case 4:
               cout << "Enter the title: ";
               getline(cin, title);
               cout << endl;
               if (videoList.videoSearch(title))
               {
                   if (videoList.isVideoAvailable(title))
                       cout << "The video is currently in stock."
                       << endl;
                   else
                       cout << "The video is out of stock." << endl;
               }
               else
                   cout << "The video is not in the store." << endl;
               break;

           case 5:
               videoList.videoPrintTitle();
               break;

           case 6:
               videoList.inorderTraversal();
               break;

           default: cout << "Invalid selection." << endl;
           }//end switch

           cout << "Your checked out videos:" << endl;
           currentCustomer.printVideos();
           cout << "________________________" << endl;
           displayMenu();
           cout << "Enter your choice: ";
           cin >> choice; //get the next request
           cin.get(ch);
           cout << endl;
       }//end while
       loginView(currentCustomer, custList, custLogin);
   }
    return 0;
}
void createCustomerList(ifstream& infile, unorderedLinkedList<customerType>& custList)
{
   string fname;
   string lname;
   int num;

   //char   ch;
   while (infile>>fname >> lname >> num)
   {
       cout << "Inserting " << fname << " " << lname << endl; // debug
       custList.insertLast(customerType(fname, lname));
      
   }//end while
}//end createVideoList
void createVideoList(ifstream& infile, videoBinaryTree& videoList)
{
    string title;
    string star1;
    string star2;
    string producer;
    string director;
    string productionCo;
    char   ch;
    int   inStock;

    videoType newVideo;

    getline(infile, title);
    while (infile)
    {
        getline(infile, star1);
        getline(infile, star2);
        getline(infile, producer);
        getline(infile, director);
        getline(infile, productionCo);
        infile >> inStock;
        infile.get(ch);
        newVideo.setVideoInfo(title, star1, star2, producer,
                             director, productionCo, inStock);
        videoList.insert(newVideo);

        getline(infile, title);
    }//end while
}//end createVideoList

void displayMenu()
{
    cout << "Select one of the following: " << endl;
    cout << "1: To check whether a particular video is in "
         << "the store" << endl;
    cout << "2: To check out a video" << endl;
    cout << "3: To check in a video" << endl;
    cout << "4: To see whether a particular video is in stock"
         << endl;
    cout << "5: To print the titles of all the videos" << endl;
    cout << "6: To print a list of all the videos" << endl;
    cout << "9: To exit" << endl;
}


void loginView(customerType& current, unorderedLinkedList<customerType>& custList, bool& custLogin)
{
   int choice;
   bool loggingIn = true; // for log in looop
   custLogin = false; //updates global bool of having a customer logged in
   string fname, lname, ftemp, ltemp;//for use of finding customer in list
   customerType temp, newCust;
   while (loggingIn) { // customer has these options that loop until customer is found, created a new account or exited
       cout << "Welcome to the Video store type a number and hit enter to make a choice" << endl;
       cout << " 1: Existing user (from database)" << endl;
       cout << " 2: New user" << endl;
       cout << " 3: Exit now" << endl;
       cin >> choice;

      
       switch (choice) {
           case 1:
              
               cout << "Enter a first name" << endl;
               cin >> ftemp;
               cout << "Enter a last name" << endl;
               cin >> ltemp;
               temp = customerType(ftemp, ltemp); //temp customer for search
               if (custList.search(temp)) { //search customer
                   current = custList.get(temp); //retrieves that customer
                   cout << "Hello " << current.getFullName(); //greet
                   //set boolean parameters
                   loggingIn = false;
                   custLogin = true;
               }
               else {
                   cout << "Customer not found" << endl;
               }
               break;
           case 2:
              
               cout << "Enter a first name" << endl;
               cin >> fname;
               cout << "Enter a last name" << endl;
               cin >> lname;
               newCust = customerType(fname, lname); // create a new customer
               custList.insertLast(newCust);//insert to list
               current = newCust; // set current to the new customer
               cout << "Welcome " << current.getFullName(); // greet
               //set boolean params
               custLogin = true;
               loggingIn = false;
               break;
           case 3:
               cout << "Good bye" << endl;

               custLogin = false;
               loggingIn = false;
               break;
           default:
               cout << "Incorrect input" << endl;
               break;
       }

          
   }
}

binarySearchTree.h

//Header File Binary Search Tree

#ifndef H_binarySearchTree
#define H_binarySearchTree
#include <iostream>
#include <cassert>
#include "binaryTree.h"


using namespace std;

template <class elemType>
class bSearchTreeType: public binaryTreeType<elemType>
{
public:
    bool search(const elemType& searchItem) const;
    void insert(const elemType& insertItem);

    void deleteNode(const elemType& deleteItem);

private:
    void deleteFromTree(binaryTreeNode<elemType>* &p);
};


template <class elemType>
bool bSearchTreeType<elemType>::
              search(const elemType& searchItem) const
{
    binaryTreeNode<elemType> *current;
    bool found = false;

    if (root == NULL)
       cerr << "Cannot search the empty tree." << endl;
    else
    {
        current = root;

        while (current != NULL && !found)
        {
            if (current->info == searchItem)
                found = true;
            else if (current->info > searchItem)
                current = current->llink;
            else
                current = current->rlink;
        }//end while
    }//end else

    return found;
}//end search

template <class elemType>
void bSearchTreeType<elemType>::insert(const elemType& insertItem)
{
    binaryTreeNode<elemType> *current; //pointer to traverse the tree
    binaryTreeNode<elemType> *trailCurrent; //pointer behind current
    binaryTreeNode<elemType> *newNode; //pointer to create the node
   trailCurrent = root;//fix error
    newNode = new binaryTreeNode<elemType>;
    assert(newNode != NULL);
    newNode->info = insertItem;
    newNode->llink = NULL;
    newNode->rlink = NULL;

    if (root == NULL)
        root = newNode;
    else
    {
        current = root;

        while (current != NULL)
        {
            trailCurrent = current;

            if (current->info == insertItem)
            {
                cerr << "The insert item is already in the list-";
                cerr << "duplicates are not allowed."
                     << insertItem << endl;
                return;
            }
            else if (current->info > insertItem)
                current = current->llink;
            else
                current = current->rlink;
        }//end while

        if (trailCurrent->info > insertItem)
            trailCurrent->llink = newNode;
        else
            trailCurrent->rlink = newNode;
    }
}//end insert

template <class elemType>
void bSearchTreeType<elemType>::deleteNode(const elemType& deleteItem)
{
    binaryTreeNode<elemType> *current; //pointer to traverse the tree
    binaryTreeNode<elemType> *trailCurrent; //pointer behind current
    bool found = false;

    if (root == NULL)
        cout << "Cannot delete from the empty tree." << endl;
    else
    {
        current = root;
        trailCurrent = root;

        while (current != NULL && !found)
        {
            if (current->info == deleteItem)
                found = true;
            else
            {
                trailCurrent = current;

                if (current->info > deleteItem)
                    current = current->llink;
                else
                    current = current->rlink;
            }
        }//end while

        if (current == NULL)
            cout << "The delete item is not in the tree." << endl;
        else if (found)
        {
            if (current == root)
                deleteFromTree(root);
            else if (trailCurrent->info > deleteItem)
                deleteFromTree(trailCurrent->llink);
            else
                deleteFromTree(trailCurrent->rlink);
        }//end if
    }
}//end deleteNode

template <class elemType>
void bSearchTreeType<elemType>::deleteFromTree
                                 (binaryTreeNode<elemType>* &p)
{
    binaryTreeNode<elemType> *current; //pointer to traverse the tree
    binaryTreeNode<elemType> *trailCurrent;   //pointer behind current
    binaryTreeNode<elemType> *temp;        //pointer to delete the node

    if (p == NULL)
        cerr << "Error: The node to be deleted is NULL." << endl;
    else if(p->llink == NULL && p->rlink == NULL)
    {
        temp = p;
        p = NULL;
        delete temp;
    }
    else if(p->llink == NULL)
    {
        temp = p;
        p = temp->rlink;
        delete temp;
    }
    else if(p->rlink == NULL)
    {
        temp = p;
        p = temp->llink;
        delete temp;
    }
    else
    {
        current = p->llink;
        trailCurrent = NULL;

        while (current->rlink != NULL)
        {
            trailCurrent = current;
            current = current->rlink;
        }//end while

        p->info = current->info;

        if (trailCurrent == NULL) //current did not move;
                                  //current == p->llink; adjust p
            p->llink = current->llink;
        else
            trailCurrent->rlink = current->llink;

        delete current;
    }//end else
}//end deleteFromTree


#endif

binaryTree.h

//Header File Binary Search Tree
#ifndef H_binaryTree
#define H_binaryTree


#include <iostream>

using namespace std;

     //Definition of the node
template <class elemType>
struct binaryTreeNode
{
    elemType info;
    binaryTreeNode<elemType> *llink;
    binaryTreeNode<elemType> *rlink;
};

   //Definition of the class
template <class elemType>
class binaryTreeType
{
public:
    const binaryTreeType<elemType>& operator=
                 (const binaryTreeType<elemType>&);
    bool isEmpty() const;
    void inorderTraversal() const;
    void preorderTraversal() const;
    void postorderTraversal() const;
    int treeHeight() const;
    int treeNodeCount() const;
    int treeLeavesCount() const;
    void destroyTree();
    binaryTreeType(const binaryTreeType<elemType>& otherTree);
    binaryTreeType();
    ~binaryTreeType();

protected:
    binaryTreeNode<elemType> *root;

private:
    void copyTree(binaryTreeNode<elemType>* &copiedTreeRoot,
                  binaryTreeNode<elemType>* otherTreeRoot);
    void destroy(binaryTreeNode<elemType>* &p);
    void inorder(binaryTreeNode<elemType> *p) const;
    void preorder(binaryTreeNode<elemType> *p) const;
    void postorder(binaryTreeNode<elemType> *p) const;

    int height(binaryTreeNode<elemType> *p) const;
    int max(int x, int y) const;
    int nodeCount(binaryTreeNode<elemType> *p) const;
    int leavesCount(binaryTreeNode<elemType> *p) const;
};

    //Definition of member functions

template <class elemType>
binaryTreeType<elemType>::binaryTreeType()
{
    root = NULL;
}

template <class elemType>
bool binaryTreeType<elemType>::isEmpty() const
{
    return (root == NULL);
}

template <class elemType>
void binaryTreeType<elemType>::inorderTraversal() const
{
    inorder(root);
}

template <class elemType>
void binaryTreeType<elemType>::preorderTraversal() const
{
    preorder(root);
}

template <class elemType>
void binaryTreeType<elemType>::postorderTraversal() const
{
    postorder(root);
}

template <class elemType>
int binaryTreeType<elemType>::treeHeight() const
{
    return height(root);
}

template <class elemType>
int binaryTreeType<elemType>::treeNodeCount() const
{
    return nodeCount(root);
}

template <class elemType>
int binaryTreeType<elemType>::treeLeavesCount() const
{
    return leavesCount(root);
}

template <class elemType>
void binaryTreeType<elemType>::copyTree
                      (binaryTreeNode<elemType>* &copiedTreeRoot,
                       binaryTreeNode<elemType>* otherTreeRoot)
{
    if (otherTreeRoot == NULL)
        copiedTreeRoot = NULL;
    else
    {
        copiedTreeRoot = new binaryTreeNode<elemType>;
        copiedTreeRoot->info = otherTreeRoot->info;
        copyTree(copiedTreeRoot->llink, otherTreeRoot->llink);
        copyTree(copiedTreeRoot->rlink, otherTreeRoot->rlink);
    }
} //end copyTree

template <class elemType>
void binaryTreeType<elemType>::inorder(binaryTreeNode<elemType> *p) const
{
    if (p != NULL)
    {
        inorder(p->llink);
        cout << p->info << " ";
        inorder(p->rlink);
    }
}

template <class elemType>
void binaryTreeType<elemType>::preorder(binaryTreeNode<elemType> *p) const
{
   if (p != NULL)
   {
       cout<<p->info<<" ";
       preorder(p->llink);
       preorder(p->rlink);
   }
}

template <class elemType>
void binaryTreeType<elemType>::postorder(binaryTreeNode<elemType> *p) const
{
    if (p != NULL)
    {
        postorder(p->llink);
        postorder(p->rlink);
        cout << p->info << " ";
    }      
}

     //Overload the assignment operator
template <class elemType>
const binaryTreeType<elemType>& binaryTreeType<elemType>::
           operator=(const binaryTreeType<elemType>& otherTree)
{
    if (this != &otherTree) //avoid self-copy
    {
        if (root != NULL) //if the binary tree is not empty,
                           //destroy the binary tree
            destroy(root);

        if (otherTree.root == NULL) //otherTree is empty
            root = NULL;
        else
            copyTree(root, otherTree.root);
    }//end else

    return *this;
}

template <class elemType>
void binaryTreeType<elemType>::destroy(binaryTreeNode<elemType>* &p)
{
    if (p != NULL)
    {
        destroy(p->llink);
        destroy(p->rlink);
        delete p;
        p = NULL;
    }
}

template <class elemType>
void binaryTreeType<elemType>::destroyTree()
{
    destroy(root);
}

   //copy constructor
template <class elemType>
binaryTreeType<elemType>::binaryTreeType
              (const binaryTreeType<elemType>& otherTree)
{
    if (otherTree.root == NULL) //otherTree is empty
        root = NULL;
    else
        copyTree(root, otherTree.root);
}

template <class elemType>
binaryTreeType<elemType>::~binaryTreeType()
{
    destroy(root);
}

template <class elemType>
int binaryTreeType<elemType>::height(binaryTreeNode<elemType> *p) const
{
    if (p == NULL)
        return 0;
    else
        return 1 + max(height(p->llink), height(p->rlink));
}

template <class elemType>
int binaryTreeType<elemType>::max(int x, int y) const
{
    if (x >= y)
        return x;
    else
        return y;
}

template <class elemType>
int binaryTreeType<elemType>::nodeCount(binaryTreeNode<elemType> *p) const
{
    cout << "Write the definition of the function nodeCount"
         << endl;

    return 0;
}

template <class elemType>
int binaryTreeType<elemType>::leavesCount(binaryTreeNode<elemType> *p) const
{
    cout << "Write the definition of the function leavesCount"
         << endl;

    return 0;
}

#endif

customerType.cpp

#include "customerType.h"

customerType::customerType(string f, string l)
{
   fname = f;
   lname = l;
}

customerType::customerType()
{
}

string customerType::getFullName() const
{
   return fname + " " + lname;
}

string customerType::getFirstName() const
{
   return fname;
}

string customerType::getLastName() const
{
   return lname;
}

int customerType::getNumCheckedOut() const
{
   return videoList.length();
}


void customerType::setFisrtName(string name)
{
   fname = name;
}

void customerType::setFirstName(string name)
{
   fname = name;
}

void customerType::printVideos()
{
   videoList.print();
}

void customerType::checkOut(string video)
{
   videoList.insertFirst(video);
}

void customerType::checkIn(string video, bool found)
{
   if (videoList.search(video)) {
       videoList.deleteNode(video);
       found = true;
   }
   else {
       cout << "You dont have that video" << endl;
       found = false;
   }

}

bool customerType::operator==(const customerType& right) const
{
   return (getFullName() == right.getFullName());
}

bool customerType::operator!=(const customerType& right) const
{
   return (getFullName() != right.getFullName());
}

bool customerType::operator<(const customerType& right) const
{
   return (getFullName() < right.getFullName());
}

bool customerType::operator<=(const customerType& right) const
{
   return (getFullName() <= right.getFullName());
}

bool customerType::operator>(const customerType& right) const
{
   return (getFullName() > right.getFullName());
}

bool customerType::operator>=(const customerType& right) const
{
   return (getFullName() >= right.getFullName());
}

ostream& operator<<(ostream& os, const customerType &cust)
{
   os << endl;
   os << "First Name " << cust.getFirstName() << endl;
   os << "Last Name " << cust.getLastName() << endl;
   os << "Movies Checked out: "<< cust.getNumCheckedOut() << endl;
  
   os << "_____________________________________" << endl;
   return os;
}

customerType.h

#include "videoType.h"
#include "unorderedLinkedList.h"
#include "videoBinaryTree.h"
using namespace std;


class customerType {
public:
   customerType(string,string);
   customerType();
   string getFullName()const;
   string getFirstName() const;
   string getLastName() const;
   int getNumCheckedOut()const;
   void setFisrtName(string);
   void setFirstName(string);
   void checkOut(string video);
   void checkIn(string,bool);
   void printVideos();
  
   bool operator==(const customerType&) const;
   bool operator!=(const customerType&) const;
   bool operator<(const customerType&) const;
   bool operator<=(const customerType&) const;
   bool operator>(const customerType&) const;
   bool operator>=(const customerType&) const;

  
private:
   string fname;
   string lname;
   unorderedLinkedList<string> videoList;


};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote