Question
Question is about Video Store Program from Data Structures Using c++ by D.S. Malik. In the Video Store Program, videoListType uses the help of unorderedLinkedList
Question is about Video Store Program from Data Structures Using c++ by D.S. Malik.
In the Video Store Program,
videoListType uses the help of unorderedLinkedList . I need to implement it with the help of STL library and update the given member functions for the operations such as check video availability, check-in and check-out of videos, search and other member functions accordingly.
Given files: ( All necessary files, videoType, personType, linkedList and unorderedLinkedList, are given but only sharing the ones needed to change.)
videoListType.h
#include
#include "unorderedLinkedList.h"
#include "videoType.h"
using namespace std;
class videoListType:public unorderedLinkedList
{
public:
bool videoSearch(string title) const;
//Function to search the list to see whether a particular title is in the store.
bool isVideoAvailable(string title) const;
//Function to determine whether a copy of a particular video is in the store.
void videoCheckOut(string title);
//Function to check out a video, that is, rent a video.copiesInStock is decremented by one.
void videoCheckIn(string title);
//Function to check in a video returned by a customer.copiesInStock is incremented by one.
bool videoCheckTitle(string title) const;
//Function to determine whether a particular video is in the store.
void videoUpdateInStock(string title, int num);
//Function to update the number of copies of a video. copiesInStock = copiesInStock + num;
void videoSetCopiesInStock(string title, int num);
//Function to reset the number of copies of a video. copiesInStock = num;
void videoPrintTitle() const;
//Function to print the titles of all the videos in the store.
private:
void searchVideoList(string title, bool& found, nodeType
//This function searches the video list for a particular video, specified by the parameter title.
//Postcondition: If the video is found, the parameter found is set to true, otherwise it is set to false.
//The parameter current points to the node containing the video.
};
videoListTypeImp.cpp
#include
#include
#include "videoListType.h"
using namespace std;
/*
Change the necessary implementations via the usage of STL instead of unordered Linked List here
*/
/*Code snippets for reference are given below*/
void videoListType::searchVideoList(string title, bool& found,
nodeType
{
found = false; //set found to false
current = first; //set current to point to the first node
//in the list
while (current != NULL && !found) //search the list
if (current->info.checkTitle(title)) //the item is found
found = true;
else
current = current->link; //advance current to
//the next node
}//end searchVideoList
bool videoListType::isVideoAvailable(string title) const
{
bool found;
nodeType
searchVideoList(title, found, location);
if (found)
found = (location->info.getNoOfCopiesInStock() > 0);
else
found = false;
return found;
}
void videoListType::videoCheckIn(string title)
{
bool found = false;
nodeType
searchVideoList(title, found, location); //search the list
if (found)
location->info.checkIn();
else
cout << "The store does not carry " << title
<< endl;
}
void videoListType::videoCheckOut(string title)
{
bool found = false;
nodeType
searchVideoList(title, found, location); //search the list
if (found)
location->info.checkOut();
else
cout << "The store does not carry " << title
<< endl;
}
bool videoListType::videoCheckTitle(string title) const
{
bool found = false;
nodeType
searchVideoList(title, found, location); //search the list
return found;
}
void videoListType::videoUpdateInStock(string title, int num)
{
bool found = false;
nodeType
searchVideoList(title, found, location); //search the list
if (found)
location->info.updateInStock(num);
else
cout << "The store does not carry " << title
<< endl;
}
void videoListType::videoSetCopiesInStock(string title, int num)
{
bool found = false;
nodeType
searchVideoList(title, found, location);
if (found)
location->info.setCopiesInStock(num);
else
cout << "The store does not carry " << title
<< endl;
}
bool videoListType::videoSearch(string title) const
{
bool found = false;
nodeType
searchVideoList(title, found, location);
return found;
}
void videoListType::videoPrintTitle() const
{
nodeType
current = first;
while (current != NULL)
{
current->info.printTitle();
current = current->link;
}
}
//template void videoListType::searchVideoList//
testVideoStore.cpp
#include
#include
#include
#include "videoType.h"
#include "videoListType.h"
using namespace std;
void createVideoList(ifstream& infile,
videoListType& videoList);
void displayMenu();
int main()
{
videoListType videoList;
int choice;
char ch;
string title;
ifstream infile;
/* File Check and Creating Video List Open file, create a list of videos, close the file*
/*Remark: Check the function definition given below; createVideoList() */
//show the menu
displayMenu();
cout << "Enter your choice: ";
cin >> choice; //get the request
cin.get(ch);
cout << endl;
//process the requests
while (choice != 9)
{
switch (choice)
{
case 1:
cout << "Enter the title: ";
getline(cin, title);
cout << endl;
if (videoList.videoSearch(title))
cout << "The store carries " << title
<< endl;
else
cout << "The store does not carry "
<< title << endl;
break;
case 2:
cout << "Enter the title: ";
getline(cin, title);
cout << endl;
if (videoList.videoSearch(title))
{
if (videoList.isVideoAvailable(title))
{
videoList.videoCheckOut(title);
cout << "Enjoy your movie: "
<< title << endl;
}
else
cout << "Currently " << title
<< " is out of stock." << endl;
}
else
cout << "The store does not carry "
<< title << endl;
break;
case 3:
cout << "Enter the title: ";
getline(cin, title);
cout << endl;
if (videoList.videoSearch(title))
{
videoList.videoCheckIn(title);
cout << "Thanks for returning "
<< title << endl;
}
else
cout << "The store does not carry "
<< title << endl;
break;
case 4:
cout << "Enter the title: ";
getline(cin, title);
cout << endl;
if (videoList.videoSearch(title))
{
if (videoList.isVideoAvailable(title))
cout << title << " is currently in "
<< "stock." << endl;
else
cout << title << " is currently out "
<< "of stock." << endl;
}
else
cout << "The store does not carry "
<< title << endl;
break;
case 5:
videoList.videoPrintTitle();
break;
case 6:
videoList.print();
break;
default:
cout << "Invalid selection." << endl;
}//end switch
displayMenu(); //display menu
cout << "Enter your choice: ";
cin >> choice; //get the next request
cin.get(ch);
cout << endl;
}//end while
return 0;
}
void createVideoList(ifstream& infile,
videoListType& videoList)
{
string title;
string star1;
string star2;
string producer;
string director;
string productionCo;
char ch;
int inStock;
/* File Check and Creating Video List, Do assignments by referencing the variables.*/
}//end while
}//end createVideoList
void displayMenu()
{
cout << "Select one of the following:" << endl;
cout << "1: To check whether the store carries a "
<< "particular video." << endl;
cout << "2: To check out a video." << endl;
cout << "3: To check in a video." << endl;
cout << "4: To check whether a particular video is "
<< "in stock." << endl;
cout << "5: To print only the titles of all the videos."
<< endl;
cout << "6: To print a list of all the videos." << endl;
cout << "9: To exit" << endl;
} //end createVideoList
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started