14. (Video Store Program) Using classes to implement the video data, video list
ID: 3772112 • Letter: 1
Question
14. (Video Store Program) Using classes to implement the video data, video list data, customer data, and customer list data, as designed in this chapter and in Programming Exercises 12 and 13, design and complete the program to put the video store into operation.
Page 683http://btechcsrc.weebly.com/uploads/2/5/4/7/25473675/data_structures_using_c_dsmalik.pdf
#include <iostream>
#include <string>
using namespace std;
class videoType
{
friend ostream& operator<<(ostream&, const videoType&);
public:
void setVideoInfo(string title, string star1,
string star2, string producer,
string director, string productionCo,
int setInStock);
654 | Chapter 11: Binary Trees and B-Trees
1
1
int getNoOfCopiesInStock() const;
void checkOut();
void checkIn();
void printTitle() const;
void printInfo() const;
bool checkTitle(string title);
void updateInStock(int num);
void setCopiesInStock(int num);
string getTitle();
videoType(string title = "", string star1 = "",
string star2 = "", string producer = "",
string director = "", string productionCo = "",
int setInStock = 0);
bool operator==(const videoType&) const;
bool operator!=(const videoType&) const;
bool operator<(const videoType&) const;
bool operator<=(const videoType&) const;
bool operator>(const videoType&) const;
bool operator>=(const videoType&) const;
private:
string videoTitle;
string movieStar1;
string movieStar2;
string movieProducer;
string movieDirector;
string movieProductionCo;
int copiesInStock;
};
//Overload the relational operators.
bool videoType::operator==(const videoType& right) const
{
return (videoTitle == right.videoTitle);
}
bool videoType::operator!=(const videoType& right) const
{
return (videoTitle != right.videoTitle);
}
bool videoType::operator <(const videoType& right) const
{
return (videoTitle < right.videoTitle);
}
Programming Example: Video Store (Revisited) | 655
bool videoType::operator <=(const videoType& right) const
{
return (videoTitle <= right.videoTitle);
}
bool videoType::operator >(const videoType& right) const
{
return (videoTitle > right.videoTitle);
}
bool videoType::operator >=(const videoType& right) const
{
return (videoTitle >= right.videoTitle);
}
#include <iostream>
#include <string>
#include "binarySearchTree.h"
#include "videoType.h"
using namespace std;
class videoBinaryTree:public bSearchTreeType<videoType>
{
public:
bool videoSearch(string title);
bool isVideoAvailable(string title);
void videoCheckOut(string title);
void videoCheckIn(string title);
bool videoCheckTitle(string title);
void videoUpdateInStock(string title, int num);
void videoSetCopiesInStock(string title, int num);
void videoPrintTitle();
private:
void searchVideoList(string title, bool& found,
binaryTreeNode<videoType>* ¤t);
void inorderTitle(binaryTreeNode<videoType> *p);
};
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::inorderTitle(binaryTreeNode<videoType> *p)
{
if (p != NULL)
{
inorderTitle(p->llink);
p->info.printTitle();
inorderTitle(p->rlink);
}
}
void videoBinaryTree::videoPrintTitle()
{
inorderTitle(root);
}
#include <iostream>
#include <fstream>
#include <string>
#include "binarySearchTree.h"
#include "videoType.h"
#include "videoBinaryTree.h"
using namespace std;
void createVideoList(ifstream& infile,
videoBinaryTree& videoList);
void displayMenu();
int main()
{
videoBinaryTree videoList;
int choice;
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();
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))
{
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))
{
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
displayMenu();
cout << "Enter your choice: ";
cin >> choice; //get the next request
cin.get(ch);
cout << endl;
}//end while
return 0;
}
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;
}
Explanation / Answer
#include <iostream>
#include <string>
#include "videoType.h"
using namespace std;
void videoType::setVideoInfo(string title, string star1, string star2, string producer, string director, string productionCo, int setInStock)
{
videoTitle = title;
movieStar1 = star1;
movieStar2 = star2;
movieProducer = producer;
movieDirector = director;
movieProductionCo = productionCo;
copiesInStock = setInStock;
}
void videoType::checkIn()
{
copiesInStock++;
}
void videoType::checkOut()
{
if(getNoOfCopiesInStock() > 0)
copiesInStock--;
else
cout<<"Currently out of Stock"<<endl;
}
int videoType::getNoOfCopiesInStock() const
{
return copiesInStock;
}
void videoType::printTitle() const
{
cout<<"Video Title: "<<videoTitle<<endl;
}
void videoType::printInfo() const
{
cout<<"Video Title: "<<videoTitle<<endl;
cout<<"Stars: "<<movieStar1<<" and "<<movieStar2<<endl;
cout<<"Producer: "<<movieProducer<<endl;
cout<<"Director: "<<movieDirector<<endl;
cout<<"Production Company: "<<movieProductionCo<<endl;
cout<<"Copies in stock: "<<copiesInStock<<endl;
}
bool videoType::checkTitle(string title)
{
return(videoTitle == title);
}
void videoType::updateInStock(int num)
{
copiesInStock += num;
}
void videoType::setCopiesInStock(int num)
{
copiesInStock = num;
}
string videoType::getTitle()
{
return videoTitle;
}
videoType::videoType(string title, string star1, string star2, string producer, string director, string productionCo, int setInStock)
{
videoTitle = title;
movieStar1 = star1;
movieStar2 = star2;
movieProducer = producer;
movieDirector = director;
movieProductionCo = productionCo;
copiesInStock = setInStock;
}
bool videoType::operator==(const videoType& right) const
{
return (videoTitle == right.videoTitle);
}
bool videoType::operator!=(const videoType& right) const
{
return (videoTitle != right.videoTitle);
}
bool videoType::operator<(const videoType& right) const
{
return (videoTitle < right.videoTitle);
}
bool videoType::operator<=(const videoType& right) const
{
return (videoTitle <= right.videoTitle);
}
bool videoType::operator>(const videoType& right) const
{
return (videoTitle > right.videoTitle);
}
bool videoType::operator>=(const videoType& right) const
{
return (videoTitle >= right.videoTitle);
}
ostream& operator<<(ostream& os, const videoType &video)
{
os<<endl;
os<<"Video Title: "<<video.videoTitle<<endl;
os<<"Stars: "<<video.movieStar1<<" and "
<<video.movieStar2<<endl;
os<<"Producer: "<<video.movieProducer<<endl;
os<<"Director: "<<video.movieDirector<<endl;
os<<"Production Company: "<<video.movieProductionCo<<endl;
os<<"Copies in stock: "<<video.copiesInStock<<endl;
os<<" "<<endl;
return os;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.