In: Computer Science
Write a program to manage DVD rental in a video rental store. Create an abstract data type that represents a DVD in this store. Consider all the data and operations that may be necessary for the DVD type to work well within a rental management system. Include a print() member function that displays all the information about the DVD. Test your data type by creating an array of ten DVD instances and filling them using information read from a test input file that you create. Display the DVD information. Language C++.
Ans:
//INPUT file named "sample.txt" used -
Drama/Crime R 1972 11/12/2016 11/15/2016 The_Godfather
Drama/Thriller PG 2008 12/20/2016 12/25/2016 The_Dark_Knight
Mystery R 1960 10/15/2016 10/20/2016 Psycho
SIFI PG 2010 08/02/2016 08/07/2016 Inception
Drama U/A 1997 08/09/2016 08/14/2016 Titanic
Fantasy U/A 2003 08/09/2016 08/14/2016 The_Lord_Of_The_Rings
Drama R 1994 08/09/2016 08/14/2016 The_Shashank_Redemption
Drama/Sport PG 1976 07/01/2016 07/08/2016 Rocky
Adventure 1993 07/01/2016 07/08/2016 Jurassic_Park
Horror R 1973 07/01/2016 07/08/2016 The_Exorcist
// for the program to work correctly copy the above data in a file named sample.txt in the following manner!

// the required program for managing a DVD rental in a video rental store
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
// the abstraction of a DVD class being used here
class DVD
{ string genre;
string type;
string year;
string dateRented;
string dateReturned;
string title;
public:
// various methods which may separately used for updating the
respective fields
void setName (string z) {
title = z;
}
string getName(){
return title;
}
void setmovierating (string w) {
type = w;
}
string getmovierating (){
return type;
}
void setyear (string v){
year = v;
}
string getyear (){
return year;
}
void setdateRented (string u) {
dateRented = u;
}
string getdateRented (){
return dateRented;
}
void setdateReturned (string t) {
dateReturned = t;
}
string getdateReturned (){
return dateReturned;
}
void setmoviegenre (string t) {
genre = t;
}
string getmoviegenre (){
return genre;
}
// Read one DVD from the input file
// Assumes one the mentioned set of fields in their respective
orders per line in input file
bool Read (istream & is)
{
is >> genre >> type >> year >> dateRented
>> dateReturned >> title;
return is.good();
}
// Print one DVD
void Print (ostream & os) const
{ os << "Name: " << title << endl;
os << "Genre: " << genre << endl;
os << "Rated: " << type << endl;
os << "Date Released: " << year << endl;
os << "Date Rented: " << dateRented <<
endl;
os << "Date Returned: " << dateReturned <<
endl;
os << endl;
}
};
int main()
{ DVD a[10];
// using an ifstream object from the fstream library
ifstream dvdfile ("sample.txt"); // Declare and open the file of
DVDs
int ent = 1; // for holding the current state of choice for a
user
do{
//Menu
cout<<"----------------------------------";
cout<<"\nSimple DVD Rental
Management System";
cout<<"\n----------------------------------";
cout<<"\nWelcome
Customer!"; //Menu for the user
cout<<"\n\n\t <1>
Display Rental Records";
cout<<"\n\t <2> Exit
\n\n";
cout<<"Enter Your Choice
:"<<"\t";
cin>>ent;
switch(ent)
{
case 1:
{
for(int i = 0; i<10; i++)
a[i].Read (dvdfile); // Read one DVD from the file
for(int i = 0; i<10; i++)
a[i].Print (cout); // Print one DVD
cout << " These are the required records !
"<<endl;
ent = 0;
break;
}
default:
ent = 0;
break;
}
}while(ent);
return 0;
}
OUTPUT:

// PLEASE DO LIKE AND UPVOTE IF THIS WAS HELPFUL!
// THANK YOU SO MUCH IN ADVANCE!