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

10. Redo Programming Exercise 14 of Chapter 5 so that it uses the STL class set

ID: 3769870 • Letter: 1

Question

10. Redo Programming Exercise 14 of Chapter 5 so that it uses the STL class
set to process the list of videos rented by the customer and the list of store
members.

Page 805 http://btechcsrc.weebly.com/uploads/2/5/4/7/25473675/data_structures_using_c_dsmalik.pdf

Chapter 5 exersice 14 info

14.a. Complete the design and implementation of the class customerType defined in the Programming Example Video Store.

b. Design and implement the class customerListType to create and maintain a list of customers for the video store.

PROGRAMMING EXAMPLE: Video Store


#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);


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() const;

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;
private:
string videoTitle;
string movieStar1;
string movieStar2;
string movieProducer;
string movieDirector;
string movieProductionCo;
int copiesInStock;
};

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::checkOut()
{
if (getNoOfCopiesInStock() > 0)
copiesInStock--;
else
cout << "Currently out of stock" << endl;
}
void videoType::checkIn()
{
copiesInStock++;
}
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;
}
Programming Example: Video Store | 331
string videoType::getTitle() const
{
return videoTitle;
}
videoType::videoType(string title, string star1,
string star2, string producer,
string director,
string productionCo, int setInStock)
{
setVideoInfo(title, star1, star2, producer, director,
productionCo, setInStock);
}
bool videoType::operator==(const videoType& other) const
{
return (videoTitle == other.videoTitle);
}
bool videoType::operator!=(const videoType& other) const
{
return (videoTitle != other.videoTitle);
}
ostream& operator<< (ostream& osObject, const videoType& video)
{
osObject << endl;
osObject << "Video Title: " << video.videoTitle << endl;
osObject << "Stars: " << video.movieStar1 << " and "
<< video.movieStar2 << endl;
osObject << "Producer: " << video.movieProducer << endl;
osObject << "Director: " << video.movieDirector << endl;
osObject << "Production Company: "
<< video.movieProductionCo << endl;
osObject << "Copies in stock: " << video.copiesInStock
<< endl;
osObject << "_____________________________________" << endl;
return osObject;
}


#include <string>
#include "unorderedLinkedList.h"
#include "videoType.h"
using namespace std;
class videoListType:public unorderedLinkedList<videoType>
{
public:
bool videoSearch(string title) const;

bool isVideoAvailable(string title) const;

void videoCheckOut(string title);

void videoCheckIn(string title);

bool videoCheckTitle(string title) const;

Programming Example: Video Store | 333
void videoUpdateInStock(string title, int num);

void videoSetCopiesInStock(string title, int num);

void videoPrintTitle() const;

private:
void searchVideoList(string title, bool& found,
nodeType<videoType>* &current) const;

};

void videoListType::searchVideoList(string title, bool& found,
nodeType<videoType>* &current) const
{
found = false;
current = first;
while (current != NULL && !found)
if (current->info.checkTitle(title))
found = true;
else
current = current->link;

}

bool videoListType::isVideoAvailable(string title) const
{
bool found;
nodeType<videoType> *location;
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<videoType> *location;
searchVideoList(title, found, location);
if (found)
location->info.checkIn();

cout << "The store does not carry " << title
<< endl;
}
void videoListType::videoCheckOut(string title)
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location);
if (found)
location->info.checkOut();
else
cout << "The store does not carry " << title
<< endl;
}
bool videoListType::videoCheckTitle(string title) const
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location);
return found;
}
void videoListType::videoUpdateInStock(string title, int num)
{
bool found = false;
nodeType<videoType> *location;
searchVideoList(title, found, location);
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<videoType> *location;
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<videoType> *location;
searchVideoList(title, found, location);
return found;
}
void videoListType::videoPrintTitle() const
{
nodeType<videoType>* current;
current = first;
while (current != NULL)
{
current->info.printTitle();
current = current->link;
}
}

MAIN
PROGRAM

#include <iostream>
#include <fstream>
#include <string>
#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;
//open the input file
infile.open("videoDat.txt");
if (!infile)

{
cout << "The input file does not exist. "
<< "The program terminates!!!" << endl;
return 1;
}

createVideoList(infile, videoList);
infile.close();

displayMenu();
cout << "Enter your choice: ";
cin >> choice; //get the request
cin.get(ch);
cout << endl;

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();
cout << "Enter your choice: ";
cin >> choice;
cin.get(ch);
cout << endl;
}
return 0;
}
void createVideoList(ifstream& infile,
videoListType& 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.insertFirst(newVideo);
getline(infile, title);
}
}//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;
}

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;
class customerType
{
friend ostream& operator<< (ostream&, const customerType&);
public:
void setcustomerInfo(string fname, string lname,
string address, int contactNum, int totalCustomers);


int getNoOfCustomers() const;

void checkOut();

void checkIn();

void printInfo() const;

bool checkName(string fname, string lname);

void updateInfo(int num);

void setnumberCustomers(num);

string getName() const;

customerType(string fname = "", string lname = "",
string address = "", int contactNumber = 0, int totalCustomers=0;);

bool operator==(const customerType&) const;
bool operator!=(const customerType&) const;

private:
string customerFname;
string customerLname;
string customerAddress;
int customerContact;

int numberOfCustomers;
};

void customerType::setcustomerInfo(string fname, string lname,
string address, int contactNum,int totalCustomers)
{
customerFname = fname;
customerLname = lname;
customerAddress = address;
customerContact = contactNum;
numberOfCustomers = totalCustomers;

}

void customerType::checkOut()
{
if (getNoOfCustomers () > 0)
numberOfCustomers--;
else
cout << "No customers in the list" << endl;
}
void customerType::checkIn()
{
numberOfCustomers++;
}
int customerType:: getNoOfCustomers () const
{
return numberOfCustomers;
}

void customerType::printInfo() const
{
cout << "Customer First name: " << customerFname << endl;
cout << "Customer Last name: " << customerLname << endl;
cout << "address is: " << customerAddress << endl;
cout << "Contact Number is: " << customerContact << endl;
cout << "Total number of customers are: " << numberOfCustomers << endl;
}


bool customerType::checkName(string fname, string lname)
{

if( customerFname == fname)

{

if( customerLname == lname)

return 0;

else

return 1;

}
}
void customerType::updateInfo(int num)
{
numberOfCustomers += num;
}
void customerType::setnumCustomers(int num)
{
numberOfCustomers = num;
}



string customerType::getName() const
{
return customerFname;
}


customerType::customerType(string fname, string lname,
string address, int contactNum, int totalCustomers)
{
setcustomerInfo(fname, lname, address, contactNum, totalCustomers);
}


bool custromerType::operator==(const customerType& other) const
{
return (customerFname == other.customerFname);
}

bool customerType::operator!=(const customerType& other) const
{
return (customerLname != other.customerLname);
}


ostream& operator<< (ostream& osObject, const customerType& customer)
{
osObject << endl;
osObject << "Customer First name: " << customer.customerFname << endl;
osObject << " Customer Last name: " << customer.customerLname << endl;
osObject << "Address: " << customer.customerAddress << endl;
osObject << "Contact number: " << customer.customerContact << endl;
osObject << "total number of customers: "
<< customer.numberOfCustomers << endl;
osObject << "_____________________________________" << endl;
return osObject;
}

#include <string>
#include "unorderedLinkedList.h"
#include "customerType.h"
using namespace std;
class customerListType:public unorderedLinkedList<customerType>
{
public:
bool customerSearch(string fname, string lname) const;

bool isCustomerAvailable(int contactNum) const;

void customerCheckOut(string fname, stirng lname);

void customerCheckIn(string fname, string lname);

bool customerCheckName(string fname, string lname) const;

void customerUpdateInfo(string fname,string lname, int num);

void SetnumCustomers(int num);

void customerPrintInfo() const;

private:
void searchcustomerList(string fname, bool& found,
nodeType<customerType>* &current) const;

};

void customerListType::searchcustomerList(string fname, bool& found,
nodeType<customerType>* &current) const
{
found = false;
current = first;
while (current != NULL && !found)
if (current->info.checkName(fname, lname))
found = true;
else
current = current->link;

}

bool customerListType::isCustomerAvailable(int contactNum) const
{
bool found;
nodeType<customerType> *location;
searchcustomerList(contactNum, found, location);
if (found)
found = (location->info. getNoOfCustomers () > 0);
else
found = false;
return found;
}
void customerListType::customerCheckIn(string fname, string lname)
{
bool found = false;
nodeType<cutomerType> *location;
searchcustomerList(fname,lname, found, location);
if (found)
location->info.checkIn();

cout << "The customer is not present with this name " << fname<<””<<lname
<< endl;
}


void customerListType::customerCheckOut(string fname, string lname)
{
bool found = false;
nodeType<customerType> *location;
searchcustomerList(fname,lname, found, location);
if (found)
location->info.checkOut();
else
cout << "The customer is not present with this name " << fname<<””<<lname
<< endl;
}
bool customerListType::customerCheckName(string fname, string lname) const
{
bool found = false;
nodeType<customerType> *location;
searchcustomerList(fname,lname, found, location);
return found;
}


void customerListType::customerUpdateInfo(string fname,sring lname,int num)
{
bool found = false;
nodeType<customerType> *location;
searchcustomerList(fname,lname, found, location);
if (found)
location->info.updateInfo(num);
else
cout << "The customer is not present with this name " << fname<<””<<lname << endl;
}
void customerListType::SetnumCustomers(int num)
{

numberOfCustomers= num;


}


bool customerListType::customerSearch(string fname, string lname) const
{
bool found = false;
nodeType<customerType> *location;
searchcustomerList(fname,lname, found, location);
return found;
}
void customerListType::customerPrintInfo() const
{
nodeType<customerType>* current;
current = first;
while (current != NULL)
{
current->info.printInfo();
current = current->link;
}
}

MAIN
PROGRAM

#include <iostream>
#include <fstream>
#include <string>
#include "customerType.h"
#include "customerListType.h"
using namespace std;
void createcustomerList(ifstream& infile,
customerListType& customerList);
void displayMenu();
int main()
{
customerListType customerList;
int choice;
char ch;
string fname;

string lname;
ifstream infile;
//open the input file

infile.open("customerDat.txt");
if (!infile)

{
cout << "The input file does not exist. "
<< "The program terminates!!!" << endl;
return 1;
}

createcustomerList(infile, customerList);
infile.close();

displayMenu();
cout << "Enter your choice: ";
cin >> choice; //get the request
cin.get(ch);
cout << endl;

while (choice != 9)
{
switch (choice)
{
case 1:
cout << "Enter the first name: ";
getline(cin, fname);
cout << endl;

cout<<”Enter the last name:”;

getline(cin, lname);

cout<<endl;
if (customerList.customerSearch(fname, lname))
cout << "The customer is present with the name" << fname<<” “<<lname
<< endl;
else
cout << " The customer is not present with the name" << fname<<” “<<lname
<< title << endl;
break;


case 2:
cout << "Enter the first name: ";
getline(cin, fname);
cout << endl;

cout << "Enter the last name: ";
getline(cin, lname);
cout << endl
if (customerList.customerSearch(fname,lname))
{
if (customerList.iscustomerAvailable(fname,lname))
{
customerList.customerCheckOut(fname,lname);
}
else
cout << "Currently " << fname <<” “<<lname
<< " is not present." << endl;
}


break;
case 3:
cout << "Enter the first name: ";
getline(cin, fname);
cout << endl;

cout<<”Enter the last name:”;

getline(cin, lname);

cout<<endl
if (customerList.customerSearch(fname,lname))
{
customerList.customerCheckIn(fname,lname);
cout << "Thanks for returning " << endl;
}
else
cout << endl;
break;


case 4:
cout << "Enter the first name: ";
getline(cin, fname);
cout << endl;

cout<<”Enter the last name:”;

getline(cin, lname);

cout<<endl if (customerList.customerSearch(fname,lname))
{
if (customerList.iscustomerAvailable(contactNum))
cout << fname<<” “<<lanme<< " is currently in "<< endl;
else
cout << fname << “ “ <<lname << " is currently out " << endl;
}
else
cout << endl;
break;


case 5:
customerList.customerPrintInfo();
break;


case 6:
customerList.print();
break;


default:
cout << "Invalid selection." << endl;
}//end switch
displayMenu();
cout << "Enter your choice: ";
cin >> choice;
cin.get(ch);
cout << endl;
}
return 0;
}
void createcustomerList(ifstream& infile,
customerListType& customerList)
{
string fname;
string lname;
string address;
char ch;
int contactNumber;

int totalCustomers;
customerType newCustomer;
getline(infile, fname, lname);
while (infile)
{
getline(infile, fname);
getline(infile, lname);
getline(infile, address);
infile >> contactnumber;

infile>> totalCustomers;
infile.get(ch);
newCustomer.setcustomerInfo(fname, lname, address, contactNum,totalcustomers);
customerList.insertFirst(newCustomer);
getline(infile, fname,lname);
}
}//end createVideoList
void displayMenu()
{
cout << "Select one of the following:" << endl;
cout << "1: To check whether the particular person is present or not "<< endl;
cout << "2: To check out a customer." << endl;
cout << "3: To check in a customer." << endl;
cout << "4: To check whether a particular customer name is present"<< endl;
cout << "5: To print the information about customers."<< endl;
cout << "6: To print a list of all the customers." << endl;
cout << "9: To exit" << endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote