Question: Video Store example CH5 Page 327 Data Structures Using C++ D.S MALIK videoListType uses the help of unorderedLinkedList which is provided in the files. You
Video Store example CH5 Page 327 Data Structures Using C++ D.S MALIK
videoListType uses the help of unorderedLinkedList which is provided in the files. You are asked 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.
videoListType.h //copy code

videoListTypeImp.cpp //copy code



unorderedLinkedList.h //copy code
#ifndef H_UnorderedLinkedList
#define H_UnorderedLinkedList
#include "linkedList.h"
using namespace std;
template
class unorderedLinkedList: public linkedListType
{
public:
bool search(const Type& searchItem) const;
//Function to determine whether searchItem is in the list.
//Postcondition: Returns true if searchItem is in the list,
// otherwise the value false is returned.
void insertFirst(const Type& newItem);
//Function to insert newItem at the beginning of the list.
//Postcondition: first points to the new list, newItem is
// inserted at the beginning of the list, last points to
// the last node, and count is incremented by 1.
//
void insertLast(const Type& newItem);
//Function to insert newItem at the end of the list.
//Postcondition: first points to the new list, newItem is
// inserted at the end of the list, last points to the
// last node, and count is incremented by 1.
void deleteNode(const Type& deleteItem);
//Function to delete deleteItem from the list.
//Postcondition: If found, the node containing deleteItem
// is deleted from the list. first points to the first
// node, last points to the last node of the updated
// list, and count is decremented by 1.
};
template
bool unorderedLinkedList::
search(const Type& searchItem) const
{
nodeType *current; //pointer to traverse the list
bool found = false;
current = linkedListType::first; //set current to point to the first
/ode in the list
while (current != NULL && !found) //search the list
if (current->info == searchItem) //searchItem is found
found = true;
else
current = current->link; //make current point to
//the next node
return found;
}//end search
template
void unorderedLinkedList::insertFirst(const Type& newItem)
{
nodeType *newNode; //pointer to create the new node
newNode = new nodeType; //create the new node
newNode->info = newItem; //store the new item in the node
newNode->link = linkedListType::first; //insert newNode before first
linkedListType::first = newNode; //make first point to the
//actual first node
linkedListType::count++; //increment count
if (linkedListType::last == NULL) //if the list was empty, newNode is also
//the last node in the list
linkedListType::last = newNode;
}//end insertFirst
template
void unorderedLinkedList::insertLast(const Type& newItem)
{
nodeType *newNode; //pointer to create the new node
newNode = new nodeType; //create the new node
newNode->info = newItem; //store the new item in the node
newNode->link = NULL; //set the link field of newNode
//to NULL
if (linkedListType::first == NULL) //if the list is empty, newNode is
//both the first and last node
{
linkedListType::first = newNode;
linkedListType::last = newNode;
linkedListType::count++; //increment count
}
else //the list is not empty, insert newNode after last
{
linkedListType::last->link = newNode; //insert newNode after last
linkedListType::last = newNode; //make last point to the actual
//last node in the list
linkedListType::count++; //increment count
}
}//end insertLast
template
void unorderedLinkedList::deleteNode(const Type& deleteItem)
{
nodeType *current; //pointer to traverse the list
nodeType *trailCurrent; //pointer just before current
bool found;
if (linkedListType::first == NULL) //Case 1; the list is empty.
cout
else
{
if (linkedListType::first->info == deleteItem) //Case 2
{
current = linkedListType::first;
linkedListType::first = linkedListType::first->link;
linkedListType::count--;
if (linkedListType::first == NULL) //the list has only one node
linkedListType::last = NULL;
delete current;
}
else //search the list for the node with the given info
{
found = false;
trailCurrent = linkedListType::first; //set trailCurrent to point
//to the first node
current = linkedListType::first->link; //set current to point to
//the second node
while (current != NULL && !found)
{
if (current->info != deleteItem)
{
trailCurrent = current;
current = current-> link;
}
else
found = true;
}//end while
if (found) //Case 3; if found, delete the node
{
trailCurrent->link = current->link;
linkedListType::count--;
if (linkedListType::last == current) /ode to be deleted
//was the last node
linkedListType::last = trailCurrent; //update the value
//of last
delete current; //delete the node from the list
}
else
cout
}//end else
}//end else
}//end deleteNode
#endif
1 video ListType.h 4 5 6 7 8 #include #include "unorderedLinked List.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. 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 + nuw; 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* ¤t) const; // 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. 3: 41 42 43 44 45 46 47 48 49 #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*/ /*template void videoListType::searchVideoList// (string, boole,const videotype)*/ void videoListType::searchVideoList(string title, bool& found, nodeType* ¤t) const 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 node Type videoType> "location; searchVideoList(title, found, location); if (found) found = (location->info.getNoOfCopiesInStock() > @); else found = false; return found } void videoListType: :videoCheckin(string title) { bool found - false; nodeTypecvideoType> location searchVideoList(title, found, location); //search the list if (found location info.checkIn(); else cout location searchVideoList(title, found, location); //search the list if (found location->info.checkout(); else cout location searchVideoList(title, found, location); //search the list return found void videoListType: -videoUpdateInStock(string title, int num) { bool found - false; nodeTypecvideoType> location searchVideoList(title, found, location); //search the list if (found location info.updateInStock (num); else cout location searchvideolist(title, found, location); return found } void videoListType: -videoPrintTitle() const { nodeTypesvideoType>* current; current - first while (current .- NULL) current info.printTitle(); current -current link :|