#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
class DVD
{
private:
string movieTitle;
string name;
string charName;
double movieLength;
int movieYear;
public:
DVD(){
movieTitle = "";
movieLength = 0;
movieYear = 0;
}
DVD(string n)
{
name = n;
}
void setTitle(string t)
{
movieTitle = t;
}
void setLength(double l)
{
movieLength = l;
}
void setYear(int y)
{
movieYear = y;
}
string getName()
{
return name;
}
string getTitle()
{
return movieTitle;
}
double getLength()
{
return movieLength;
}
int getYear()
{
return movieYear;
}
};
int showMenu()
{
cout << "Welcome to the DVD Collection Program! \n What do you want to do?\n " << endl;
cout << "1. Add DVD" << endl;
cout << "2. Remove DVD" << endl;
cout << "3. Update DVD" << endl;
cout << "4. Show DVDs" << endl;
cout << "5. EXIT" << endl;
int c;
cin >> c;
return c;
}
void list(vector<DVD> &vectorName, vector<string>&vectorCharName, DVD *mydvd)
{
//table format
cout << setw(10) << "\nMovie Title: "
<< setw(10) << "Length:"
<< setw(10) << "Year: "
<< setw(10) << "Actors/Actresses:"
<< setw(10) << "Characters:\n" << endl;
cout << "------------------------------------------------------------\n";
for (int i = 0; i < vectorName.size(); i++)
{
if(i <1)
{
if(mydvd[i].getLength()!=0)
{
cout <<endl<<setw(10)<< right << mydvd[i].getTitle()
<<setw(10) << mydvd[i].getLength()
<< setw(10) << mydvd[i].getYear();
}
else
{
cout <<setw(10)<< right << mydvd[i].getTitle();
}
}
else
{
if(mydvd[i].getLength()!=0)
{
cout <<endl<<setw(10)<< right << mydvd[i].getTitle()
<<setw(10) << mydvd[i].getLength()
<< setw(10) << mydvd[i].getYear();
}
else
{
cout <<setw(10)<< right << mydvd[i].getTitle();
}
}
if(i <1)
cout<<"\t\t"<<vectorName[i].getName()
<< " "<<vectorCharName[i] << endl;
else
{
cout<<"\t\t\t\t"<<vectorName[i].getName()
<< " "<<vectorCharName[i] << endl;
}
}
}
int main()
{
const int ARRAY = 50;
DVD mydvd[ARRAY];
vector<DVD> vectorList;
vector<DVD> vectorName;
vector<string> vectorCharName;
string actor, character, title;
double length;
int year;
int quantity;
int ch;
int dvdNum=0;
// Constants for menu choices
const int SHOW_LIST = 1, ADD_DVD = 2, REMOVE_DVD = 3, UPDATE_DVD = 4, QUIT_CHOICE = 5;
while (1){
ch = showMenu();
for (int i = 0; i < 1; i++){
if (ch == 1){
// Ask the user to enter the details of DVD
cout <<"Enter DVD#: ";
cin >>dvdNum;
cout << "\nEnter the movie title, length, and year released. \n"
<< "Hit [ENTER] after each input: ";
cin.ignore();
std::getline(std::cin, title);;
cin >> length;
cin >> year;
cout << endl;
cout << "\nHow many actors? ";
cin >> quantity;
for (int i = 0; i < quantity; i++)
{
cin.ignore();
cout << "Actor " << (i + 1) << ": ";
std::getline(std::cin, actor);
cin.ignore();
cout << "Character " << ": ";
std::getline(std::cin, character);
// get user input
vectorName.push_back(actor);
vectorCharName.push_back(character);
}
// Store the DVD details
mydvd[dvdNum].setTitle(title);
mydvd[dvdNum].setLength(length);
mydvd[dvdNum].setYear(year);
list(vectorName, vectorCharName, mydvd);
}
else if (ch == 4)
{
list(vectorName, vectorCharName, mydvd); // displays dvd list
}
else if (ch == 5)
exit(0);
else if (ch == 3)
{
list(vectorName, vectorCharName, mydvd); // displays dvd list
int sn;
cout << "Enter serial number of dvd(starting from 1 ) you wish to update :";
cin >> sn;
cout << "Enter the movie title, length, and year released.\n"
<< "Hit [ENTER] after each input: ";
cin >> title;
cin >> length;
cin >> year;
cout << "\nThe DVD is now updated\n";
// Store the DVD details
mydvd[sn - 1].setTitle(title);
mydvd[sn - 1].setLength(length);
mydvd[sn - 1].setYear(year);
}
else if (ch == 2) // removes a dvd
{
int sn;
cout << "Enter serial number of dvd(starting from 1 ) you wish to update :";
cin >> sn;
cout << "Enter the movie title, length, and year of the DVD, you would like to removed.\n"
<< "Hit [ENTER] after each input: ";
cin >> title;
cin >> length;
cin >> year;
// Store the DVD details
mydvd[i].setTitle(title);
mydvd[i].setLength(length);
mydvd[i].setYear(year);
cout << "\nThe DVD is now Remove\n";
}
}
}
return 0;
}