This program will allow the user to keep track of both a CD and a DVD collection
ID: 3796323 • Letter: T
Question
This program will allow the user to keep track of both a CD and a DVD collection. The program needs to work for both CDs and DVDs. There should be a base class that maintains the common information between a CD and a DVD. Each CD/DVD in the collection will be represented as a class, so you will have one class that will be a CD and another that will be a DVD. The program will then has a base class called Media. Both the CD and DVD classes will inherit from the same base class. The base class will have one data member that will hold the CD Name or Movie Title and another data member for the length of the total CD or the length of the movie. The CD class will use a linked list to keep track of the titles of the songs on the CD; this will allow each CD to have a different number of songs. It should also maintain the length of each song, thus the class will use a structure which will have the song title and its length. Each song will be an instance of this structure and will be stored in the linked list. The class will also have a data member for the artist name. The DVD class will have data members for the year the movie was released. The class will have a linked list for storage of the name of the actors and actresses in the movie. The class will also maintain the character names that the actors/actresses played in the movie. The actors/ actresses and characters information will be stored in a structure which will be stored in the linked list. The program will then maintain two lists, one for the CDs and another for DVDs. The program will use linked lists to maintain the two different lists. 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. NOTE: There must be only one linked list class (template) that will be used for each of the lists needed in this program. Derived classes of the linked list can be added to expend the functionality of the linked list to be specific for each class. 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. Artist CD Name Length of CD Song Title Song Length NOTE: The artist name, CD name and length of CD should only appear once while the song title and length will have several lines. So the other columns must be displayed with blanks.
Explanation / Answer
#include #include #include #include #include using namespace std; // Function Prototype void showList(string, double, int, string, string); void showMenu(); class DVD { private: string movie; // To hold movie title double length; // To hold movie length int year; // To hold release date public: // Constructors vector actor; // To hold actor/actress name vector charName; // To hold name of character void setMovie(string); void setLength(double); void setYear(int); void addActor(string, string); string getMovie() const; double getLength() const; int getYear()const; string getActor() const; DVD() { movie = ""; length = 0; year = 0; } DVD(string m, double l, int y) { movie = m; length = l; year = y; } }; // Mutators void DVD::setMovie(string m) { movie = m; } void DVD::setLength(double l) { length = l; } void DVD:: setYear(int y) { year = y; } void DVD::addActor(string actorName, string characterName) { actor.push_back(actorName); charName.push_back(characterName); } // Accessors string DVD::getMovie() const { return movie; } double DVD::getLength() const { return length; } int DVD::getYear() const { return year; } // I am having trouble here. How do I return both // actor and charName in parallel?? // string DVD::getActor(unsigned int index) { if(index >= name.size()) //Error name is undefined return "no data"; return name[index]; }//Error: declaration incompatible with //std::string DVD::getActor() const declared at line 34 int main() { int quantity; // To hold number actors/actresses string name; // To hold actor/actress name string charName; // To hold name of character string title; // To hold movie title double movieLength; // Local variable for length int yearReleased; // Local variable for release date fstream nameFile; // Fstream file object int choice; // For menu choice // Constants for menu choices const int SHOW_LIST = 1, ADD_DVD = 2, REMOVE_DVD = 3, UPDATE_DVD = 4, QUIT_CHOICE = 5; // Access Vector DVD mydvd; //I want to ask the user to enter the details // of the DVD so the info will be stored in the variables // Ask the user to enter the details of DVD cout movieLength; cin >> yearReleased; //Here I would like to ask the user "How many actors // Do you wish to enter... cout > quantity; // Here is one of my problems. I only want index to go no higher // than quantity. But then I can't use getline(cin,name[index]) // because name is not name[quantity]. Any suggestions? for (int index = 0; indexRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.