I am working on the following assignment but have been stuck
I am working on the following assignment but have been stuck for two days. (Not even sure if I\'m in the ballpark) C++ CD/DVD Collection 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 different—your 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 CD class will use a vector 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 another vector. The class will also keep track of the total length of the CD. The class will also have a data member for the artist name and the name of the CD. 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. Here is what I have so far and the errors.
H.file
#ifndef DVD_COLLECTION_H
#define DVD_COLLECTION_H
#include <string>
#include <vector>
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<string> actor; //Actors and Actresses
vector<string> charName; //Character names
// 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
ccp.file
#include <iostream>
#include \"DVDCollection.h\"
#include <vector>
#include <string>
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
{
return Actor;
MAIN.CCP
#include \"DVDCollection.h\"
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;
void removeDVD(string);
void updateDVD(string);
void showDVDs(vector<string>, vector<string>, DVDCollection &);
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: \";
cin >> length;
cout << \"Number of major Actors/Actresses in the movie: \";
cin >> numActors;
cin.ignore();
myDVDs.setTitle(title);
myDVDs.setYear(year);
myDVDs.setLength(length);
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);
break;
}
} while (selection != 5);
system(\"pause\");
return 0;
}
void showDVDs(vector<string> &vectorActor, vector<string> &vectorcharName, DVDCollection *myDVDs)
{
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\\t\" << vectorActor[count] << \" \" <<
vectorcharName[count] << endl;
}
else
{
cout << \"\\t\\t\\t\\t\" << vectorActor[count] << \" \" <<
vectorcharName[count] << endl;
}
}
}
}
Warning 2 warning C4018: \'<\' : signed/unsigned mismatch c:\\users\\anna\\desktop\\school\\c++ programming\\ciss_242_final_project\\ciss_242_final_project\\main.cpp 110 1 CISS_242_Final_Project 4 IntelliSense: no instance of overloaded function \"showDVDs\" matches the argument list argument types are: (DVDCollection) c:\\Users\\Anna\\Desktop\\school\\C++ Programming\\CISS_242_Final_Project\\CISS_242_Final_Project\\Main.cpp 91 4 CISS_242_Final_Project Error 1 error C2660: \'showDVDs\' : function does not take 1 arguments c:\\users\\anna\\desktop\\school\\c++ programming\\ciss_242_final_project\\ciss_242_final_project\\main.cpp 91 1 CISS_242_Final_Project Error 3 error C2065: \'Actor\' : undeclared identifier c:\\users\\anna\\desktop\\school\\c++ programming\\ciss_242_final_project\\ciss_242_final_project\\dvdcollection.cpp 58 1 CISS_242_Final_Project
Solution
The following are the updated DVDCollections.cpp and main.cpp files. I have updated by recovering the errors.
DVDCollections.cpp: Only changed getCharInfo() method
#include <iostream>
#include \"DVDCollection.h\"
#include <vector>
#include <string>
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 tmp;
for(auto iter=charName.begin();iter!=charName.end();iter++)
{
tmp.append(*iter);
tmp.append(\"\ \");
}
return tmp;
}
main.cpp: changed the definition and calling convention of showDVDs() method
#include \"DVDCollection.h\"
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;
void removeDVD(string);
void updateDVD(string);
void showDVDs(vector<string>&, vector<string>&, DVDCollection *);
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: \";
cin >> length;
cout << \"Number of major Actors/Actresses in the movie: \";
cin >> numActors;
cin.ignore();
myDVDs.setTitle(title);
myDVDs.setYear(year);
myDVDs.setLength(length);
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);
system(\"pause\");
return 0;
}
void showDVDs(vector<string> &vectorActor, vector<string> &vectorcharName, DVDCollection *myDVDs)
{
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\\t\" << vectorActor[count] << \" \" <<
vectorcharName[count] << endl;
}
else
{
cout << \"\\t\\t\\t\\t\" << vectorActor[count] << \" \" <<
vectorcharName[count] << endl;
}
}
}
DVDCollections.h: No changes
#ifndef DVD_COLLECTION_H
#define DVD_COLLECTION_H
#include <string>
#include <vector>
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<string> actor; //Actors and Actresses
vector<string> charName; //Character names
// 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
Note: I compiled your program in c++11. The following is the output
Output:
This program will allow you to keep track of all your favorite
DVDs.
1 = Add a DVD
2 = Remove a DVD
3 = Update a DVD
4 = Show all DVDs
5 = Exit program
What would you like to do? 1
You have choosen to Add a DVD.
I will need the following information:
Movie title: Transformers
Year movie was released: 2011
Length of movie: 2
Number of major Actors/Actresses in the movie: 4
Actor/Actress #1\'s name: Shia
Name of their character: Sam
Actor/Actress #2\'s name: MeghanFox
Name of their character: Love
Actor/Actress #3\'s name: Optimus
Name of their character: Prime
Actor/Actress #4\'s name: Bumblebee
Name of their character: Decepticon
1 = Add a DVD
2 = Remove a DVD
3 = Update a DVD
4 = Show all DVDs
5 = Exit program
What would you like to do? 4
You have chosen to view all DVDs in the collection.
Movie Title: Year Released: Length: Actors/Actresses: Characters:
-----------------------------------------------------------
Transformers 2011 2 Shia Sam
MeghanFox Love
Optimus Prime
Bumblebee Decepticon
1 = Add a DVD
2 = Remove a DVD
3 = Update a DVD
4 = Show all DVDs
5 = Exit program
What would you like to do? 5











