Write the definitions of the functions of the class videoBinaryTree not given in
ID: 3864258 • Letter: W
Question
Write the definitions of the functions of the class videoBinaryTree not given in the Programming Example Video Store. Use the additional code for reference to what the function should do.
CODE: ** Only need the code for the ones that say "See Programming exercise 12." **
#include <iostream>
#include <string>
#include "videoBinaryTree.h"
using namespace std;
bool videoBinaryTree::isVideoAvailable(string title)
{
cout << "See Programming Exercise 12." << endl;
return false;
}
void videoBinaryTree::videoCheckIn(string title)
{
cout << "See Programming Exercise 12." << endl;
}
void videoBinaryTree::videoCheckOut(string title)
{
cout << "See Programming Exercise 12." << endl;
}
bool videoBinaryTree::videoCheckTitle(string title)
{
cout << "See Programming Exercise 12." << endl;
return false;
}
void videoBinaryTree::videoUpdateInStock(string title, int num)
{
cout << "See Programming Exercise 12." << endl;
}
void videoBinaryTree::videoSetCopiesInStock(string title,
int num)
{
cout << "See Programming Exercise 12." << endl;
}
bool videoBinaryTree::videoSearch(string title)
{
cout << "See Programming Exercise 12." << endl;
return false;
}
void videoBinaryTree::searchVideoList(string title, bool& found,
binaryTreeNode<videoType>* ¤t)
{
found = false;
videoType temp;
temp.setVideoInfo(title, "", "", "", "", "", 0);
if (root == NULL) //the tree is empty
cout << "Cannot search an empty list. " << endl;
else
{
current = root; //set current point to the root node
//of the binary tree
found = false; //set found to false
while (!found && current != NULL) //search the tree
if (current->info == temp) //the item is found
found = true;
else if(current->info > temp)
current = current->llink;
else
current = current->rlink;
} //end else
}
void videoBinaryTree::videoPrintTitle()
{
inorderTitle(root);
}
void videoBinaryTree::inorderTitle(binaryTreeNode<videoType> *p)
{
if (p != NULL)
{
inorderTitle(p->llink);
p->info.printTitle();
inorderTitle(p->rlink);
}
}
Additional Reference CODE:
#ifndef H_VideoLinkedListType
#define H_VideoLinkedListType
#include <iostream>
#include <string>
#include "binarySearchTree.h"
#include "videoType.h"
using namespace std;
class videoBinaryTree:public bSearchTreeType<videoType>
{
public:
bool videoSearch(string title);
//Function to search the list to see whether a particular
//title, specified by the parameter title, is in stock.
//Postcondition: Returns true if the title is found,
// false otherwise.
bool isVideoAvailable(string title);
//Function to determine whether at least one copy of a
//particular video is in stock.
//Postcondition: Returns true if at least one copy is in
// stock, false otherwise.
void videoCheckOut(string title);
//Function to check out a video, that is, rent a video.
//Postcondition: copiesInStock is decremented by 1.
void videoCheckIn(string title);
//Function to check in a video returned by a customer.
//Postcondition: copiesInStock is incremented by 1.
bool videoCheckTitle(string title);
//Function to determine whether a particular video is in
//stock.
//Postcondition: Returns true if the video is in stock,
// 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; the parameter num
//specifies the number of copies.
//Postcondition: copiesInStock = num
void videoPrintTitle();
//Function to print the titles of all the videos in stock.
private:
void searchVideoList(string title, bool& found,
binaryTreeNode<videoType>* ¤t);
//Function to search 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, false otherwise. The parameter current
// points to the node containing the video.
void inorderTitle(binaryTreeNode<videoType> *p);
//Function to print the titles of all the videos in stock.
};
#endif
Explanation / Answer
As asked into the qusetion, definitions are required for below functions:
1)Function to search the list
2)Function to determine whether at least one copy of a particular video is in stock.
3)Function to check out a video
4)Function to check in a video returned by a customer
5)Function to determine whether a particular video is in stock
6)Function to update the number of copies
7)Function to reset the number of copies of a video
8)Function to print the titles of all the videos in stock
9)Function to search the video list for a particular video
10)Function to print the titles of all the videos in stock
Per chegg terms and servises, we are only advised to provide solution for fisrt 4 sub parts. I will try as much as possible in order to help you out. Please make sure to post questions as per Chegg guidelines. Thanks.
1)Function to search the list
bool videoSearch(string title)
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location);
return found;
}
2)Function to determine whether at least one copy of a particular video is in stock.
bool isVideoAvailable(string title)
{
bool found;
nodeType<videoType> *location;
searchVideoList(title, found, location);
if (found)
found = (location->info.getNoOfCopiesInStock() > 0);
else
found = false;
return found;
}
3)Function to check out a video
void videoCheckOut(string title)
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location); //search the list
if (found)
location->info.checkOut();
else
cout << "The store does not carry " << title<< endl;
}
4)Function to check in a video returned by a customer
void videoCheckIn(string title)
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location); //search the list
if (found)
location->info.checkIn();
Programming Example: Video Store | 335
else
cout << "The store does not carry " << title<< endl;
}
5)Function to determine whether a particular video is in stock
bool videoCheckTitle(string title)
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location); //search the list
return found;
}
6)Function to update the number of copies
void videoUpdateInStock(string title, int num)
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location); //search the list
if (found)
location->info.updateInStock(num);
else
cout << "The store does not carry " << title<< endl;
}
7)Function to reset the number of copies of a video
void videoSetCopiesInStock(string title, int num)
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location);
if (found)
location->info.setCopiesInStock(num);
else
cout << "The store does not carry " << title<< endl;
}
8)Function to print the titles of all the videos in stock
void videoPrintTitle()
{
nodeType<videoType>* current;
current = first;
while (current != NULL)
{
current->info.printTitle();
current = current->link;
}
}
9)Function to search the video list for a particular video
void searchVideoList(string title, bool& found,binaryTreeNode<videoType>* ¤t)
{
found = false; //set found to false
current = first; //set current to point to the first node
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
}
10)Function to print the titles of all the videos in stock
void inorderTitle(binaryTreeNode<videoType> *p)
{
if (p != NULL)
{
inorderTitle(p->llink);
p->info.printTitle();
inorderTitle(p->rlink);
}
}
Note : Please put whole function into your code carrefully at right place before executing.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.