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

Please help me modify these two files to use a list instead of inheriting from a

ID: 3859962 • Letter: P

Question

Please help me modify these two files to use a list instead of inheriting from another class.

These are the two files we need to modify and these are the steps we need to take but I'm still lost.

videoListType.h
---------------
1. Do away with inheritance from unorderedLinkedList.
2. Create a new private variable of list<videoType> to hold the list of videos.
3. Modify searchVideoList function to return a list iterator instead of a pointer to nodeType.

videoListType.cpp
-----------------
1. Modify searchVideoList to iterate through stl list.
2. Modify functions which use searchVideoList to use a list iterator instead of a pointer to a nodeType.
3. Modify videoPrintTitle to loop through stl list to print out the videos.

I'll paste my attempt at changing it but it's still not working. Any help would be amazing.

This is the .h file
#include <string>
#include <list>
#include "unorderedLinkedList.h"
#include "videoType.h"
using namespace std;

class videoListType
{
public:
bool videoSearch(string title) const;
//Function to search the list to see whether a
//particular title, specified by the parameter title,
//is in the store.
//Postcondition: Returns true if the title is found, and
// false otherwise.

bool isVideoAvailable(string title) const;
//Function to determine whether a copy of a particular
//video is in the store.
//Postcondition: Returns true if at least one copy of the
// video specified by title is in the store, and false
// otherwise.

void videoCheckOut(string title);
//Function to check out a video, that is, rent a video.
//Postcondition: copiesInStock is decremented by one.

void videoCheckIn(string title);
//Function to check in a video returned by a customer.
//Postcondition: copiesInStock is incremented by one.

bool videoCheckTitle(string title) const;
//Function to determine whether a particular video is in
//the store.
//Postcondition: Returns true if the video’s title is the
// same as title, and false otherwise.
  
void videoUpdateInStock(string title, int num);
//Function to update the number of copies of a video
//by adding the value of the parameter num. The
//parameter title specifies the name of the video for
//which the number of copies is to be updated.
//Postcondition: copiesInStock = copiesInStock + num;
  
void videoSetCopiesInStock(string title, int num);
//Function to reset the number of copies of a video.
//The parameter title specifies the name of the video
//for which the number of copies is to be reset, and the
//parameter num specifies the number of copies.
//Postcondition: copiesInStock = num;
  
void videoPrintTitle() const;
//Function to print the titles of all the videos in the store.
  
private:
list<videoType> videos;
void searchVideoList(string title, bool& found,
list<videoType>::iterator& i) const;
//This function searches the video list for a particular
//video, specified by the parameter title.

Heres the .cpp file

#include "videoListType.h"

void videoListType::searchVideoList(int element,
list<videoType>::iterator& i){

bool found = false;
list<videoType>::iterator itr;

for (itr = l.begin(); itr != l.end() && !found; itr++)
{
if (element == *itr)
{
i = itr;
found = true;
}
}

return found;

}//end searchVideoList

bool videoListType::isVideoAvailable(string title) const
{
bool found;
list<videoType>::iterator &i;

searchVideoList(title, found, i);

if (found)
found = (i->info.getNoOfCopiesInStock() > 0);
else
found = false;
  
return found;
}

void videoListType::videoCheckIn(string title)
{
bool found = false;
list<videoType>::iterator &i;

searchVideoList(title, found, i); //search the list

if (found)
i->info.checkIn();
else
cout << "The store does not carry " << title << endl;
}

void videoListType::videoCheckOut(string title)
{
bool found = false;
list<videoType>::iterator &i;

searchVideoList(title, found, i); //search the list

if (found)
i->info.checkOut();
else
cout << "The store does not carry " << title << endl;
}

bool videoListType::videoCheckTitle(string title) const
{
bool found = false;
list<videoType>::iterator &i;
  
searchVideoList(title, found, i); //search the list
  
return found;
}

void videoListType::videoUpdateInStock(string title, int num)
{
bool found = false;
list<videoType>::iterator &i;

searchVideoList(title, found, i); //search the list

if (found)
i->info.updateInStock(num);
else
cout << "The store does not carry " << title << endl;
}

void videoListType::videoSetCopiesInStock(string title, int num)
{
bool found = false;
list<videoType>::iterator &i;
  
searchVideoList(title, found, i);
  
if (found)
i->info.setCopiesInStock(num);
else
cout << "The store does not carry " << title << endl;
}

bool videoListType::videoSearch(string title) const
{
bool found = false;
list<videoType>::iterator &i;

searchVideoList(title, found, i);

return found;
}

void videoListType::videoPrintTitle() const
{
list<videoType>::iterator &i;
i = first;
  
while (i != NULL)
{
i->info.printTitle();
i = i->link;
}
}

Explanation / Answer

Given below is the modified version of the videoListType.cpp . You have not given the videoType.h and .cpp files for me to test the changes. I have made the changes to use STL list iterator. I will be glad to help you in case you face any issues. Since the videoType.h is missing, I assumed that there is a function getTitle() in videoType class. This is used for comparing the title we are searching. I can help you in case you find any issues with this code. Post a comment if you need any help further. If the answer helped, please do rate it. Thank you.

#include "videoListType.h"
void videoListType::searchVideoList(string title, bool& found,
list<videoType>::iterator& i){
found = false;
list<videoType>::iterator itr;
for (itr = videos.begin(); itr != videos.end() && !found; itr++)
{
if (title == (*itr).getTitle())
{
i = itr;
found = true;
return;
}
}
  
}//end searchVideoList
bool videoListType::isVideoAvailable(string title) const
{
bool found;
list<videoType>::iterator &itr;
searchVideoList(title, found, itr);
if (found)
found = ((*itr).getNoOfCopiesInStock() > 0);
else
found = false;
  
return found;
}
void videoListType::videoCheckIn(string title)
{
bool found = false;
list<videoType>::iterator &itr;
searchVideoList(title, found, itr); //search the list
if (found)
(*itr).checkIn();
else
cout << "The store does not carry " << title << endl;
}
void videoListType::videoCheckOut(string title)
{
bool found = false;
list<videoType>::iterator &itr;
searchVideoList(title, found, itr); //search the list
if (found)
(*itr).checkOut();
else
cout << "The store does not carry " << title << endl;
}
bool videoListType::videoCheckTitle(string title) const
{
bool found = false;
list<videoType>::iterator &itr;
  
searchVideoList(title, found, itr); //search the list
  
return found;
}
void videoListType::videoUpdateInStock(string title, int num)
{
bool found = false;
list<videoType>::iterator &itr;
searchVideoList(title, found, itr); //search the list
if (found)
(*itr).updateInStock(num);
else
cout << "The store does not carry " << title << endl;
}
void videoListType::videoSetCopiesInStock(string title, int num)
{
bool found = false;
list<videoType>::iterator &itr;
  
searchVideoList(title, found, itr);
  
if (found)
(*itr).setCopiesInStock(num);
else
cout << "The store does not carry " << title << endl;
}
bool videoListType::videoSearch(string title) const
{
bool found = false;
list<videoType>::iterator &itr;
searchVideoList(title, found, itr);
return found;
}
void videoListType::videoPrintTitle() const
{
list<videoType>::iterator itr;
  
for(itr = videos.begin(); itr != videos.end(); ++itr)
{
(*itr).printTitle();
}
}

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