Question
Stuck again. My program now runs but the title, year, and length is being overwritten when a new movie is added. The actors and characters
Stuck again. My program now runs but the title, year, and length is being overwritten when a new movie is added. The actors and characters seem to be working okay but no data is saved when program is closed than reopened.
This program will allow the user to keep track of a CD or DVD collection. This can only work exclusively with either CDs or DVDs since some of the data is differentyour choice. Each CD/DVD in the collection will be represented as a class, so you will have one class that is a single CD/DVD. The DVD class will have data members for the title of the movie, the length of the movie, and the year the movie was released. The class will have a vector which is used to store the name of the actors and actresses in the movie. Another vector will be used to maintain the character names that the actor/actress played in the movie. These two vectors must work in parallel, meaning the first actor/actress in the list must correspond to the first character in the other vector. The program will maintain a list of CD/DVDs. This list will be a vector of that class type (CD or DVD). The program must provide methods (functions) to add a CD/DVD, remove a CD/DVD and update a CD/DVD. There should also be a function that displays the entire list of CDs/DVDs. The output must be a table format, with heading. For the DVDs Movie Title Length of Movie Year Released Actors/Actresses Characters NOTE: the movie title, length of movie and year released should only appear once while the actors/actresses and characters will have several lines. So the other columns must be displayed with blanks.
Header file
#ifndef DVD_COLLECTION_H
#define DVD_COLLECTION_H
#include
#include
using namespace std;
class DVDCollection
{
private:
string title; //Holds title of dvd
int year; //Year made
int length; //Holds length of movie
public:
DVDCollection(); // Default Constructor
DVDCollection(string, int, int); // Constructor
vector
vector
// Mutator functions
void setTitle(string);
void setLength(int);
void setYear(int);
void setCharInfo(string, string);
// Accessor functions
string getTitle() const;
int getLength() const;
int getYear() const;
string getCharInfo() const;
};
#endif
DVDCollection. Cpp
#include
#include "DVDCollection.h"
#include
#include
DVDCollection::DVDCollection()
{
title = "";
year = 0;
length = 0;
}
DVDCollection::DVDCollection(string t, int y, int l)
{
title = t;
year = y;
length = l;
}
void DVDCollection::setTitle(string t)
{
title = t;
}
void DVDCollection::setLength(int l)
{
length = l;
}
void DVDCollection::setYear(int y)
{
year = y;
}
void DVDCollection::setCharInfo(string aName, string cName)
{
Actor.push_back(aName);
CharName.push_back(cName);
}
string DVDCollection::getTitle() const
{
return title;
}
int DVDCollection::getYear() const
{
return year;
}
int DVDCollection::getLength() const
{
return length;
}
string DVDCollection::getCharInfo() const
{
string temp;
for (auto iter = CharName.begin(); iter != CharName.end(); iter++)
{
temp.append(*iter);
temp.append(" ");
}
return temp;
}
Main.cpp
#include "DVDCollection.h"
#include
#include
#include
#include
#include
using namespace std;
map
void removeDVD(string);
void updateDVD(string);
void showDVDs(vector
int main()
{
DVDCollection myDVDs;
int selection;
int numActors;
string aName;
string cName;
string title;
int length;
int year;
cout << "This program will allow you to keep track of all your favorite ";
cout << "DVDs. ";
cout << endl;
do
{
cout << "\t\t" << "1 = Add a DVD ";
cout << "\t\t" << "2 = Remove a DVD ";
cout << "\t\t" << "3 = Update a DVD ";
cout << "\t\t" << "4 = Show all DVDs ";
cout << "\t\t" << "5 = Exit program ";
cout << endl;
cout << "What would you like to do? ";
cin >> selection;
while (selection < 1 || selection > 5)
{
cout << "Please enter the number of your choice. ";
cin >> selection;
}
switch (selection)
{
case 1:
cout << "You have choosen to Add a DVD. ";
cout << "I will need the following information: ";
cin.ignore();
cout << "Movie title: ";
getline(cin, title);
cout << "Year movie was released: ";
cin >> year;
cout << "Length of movie (in minutes): ";
cin >> length;
cout << "Number of major Actors/Actresses in the movie: ";
cin >> numActors;
cin.ignore();
myDVDs.setTitle(title);
myDVDs.setYear(year);
myDVDs.setLength(length);
collection.insert(make_pair(title, myDVDs));
for (int count = 0; count < numActors; count++)
{
cout << "Actor/Actress #" << (count + 1) << "'s name: ";
getline(cin, aName);
cout << "Name of their character: ";
getline(cin, cName);
myDVDs.setCharInfo(aName, cName);
}
break;
case 2:
cout << "You have chosen to remove a DVD. ";
//removeDVD();
break;
case 3:
cout << "You have chosen to update a DVD. ";
// updateDVD();
break;
case 4:
cout << "You have chosen to view all DVDs in the collection. ";
showDVDs(myDVDs.Actor, myDVDs.CharName, &myDVDs);
break;
}
} while (selection != 5);
cout << endl;
cout << "See you at the movies! ";
system("pause");
return 0;
}
void showDVDs(vector
{
cout << setw(10) << " Movie Title: " << setw(10) << "Year Released: "
<< setw(10) << "Length: " << setw(10) << "Actors/Actresses: "
<< setw(10) << "Characters: ";
cout << "-----------------------------------------------------------";
cout << endl;
for (auto count = 0; count < vectorActor.size(); count++)
{
if (count < 1)
{
if (myDVDs[count].getLength() != 0)
{
cout << setw(10) << right << myDVDs[count].getTitle() << setw(10)
<< myDVDs[count].getYear() << setw(10) << myDVDs[count].getLength();
}
else
{
cout << setw(10) << right << myDVDs[count].getTitle();
}
}
if (count < 1)
{
cout << "\t" << vectorActor[count] << " " <<
vectorCharName[count] << endl;
}
else
{
cout << "\t\t\t\t\t" << vectorActor[count] << " " <<
vectorCharName[count] << endl;
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started