I\'m supposed to write a program to keep track of a CD or DVD collection. This c
ID: 3551857 • Letter: I
Question
I'm supposed to write a program 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. The data will be stored ina file. The data from the file will be stored ina text file as records. Each CD/DVD in the collection will be represented as a class, so you will have one class that is the CD/DVD.
The CD class will be limited to 5 songs on that CD. So the class will need to keep an array of 5 strings for the song titles. It should also maintain the length of each song and the total length of the CD. the class will also have the artist name.
The DVD class will have data members for the title of the movie, the length of the movie, the year of the movie and the names of two of the main actors in the movie.
There will be a class that maintains the list of CD/DVDs. This list can be limited to just 5 CD/DVDs. The list provides methods to add a CD/DVD, remove a CD/DVD, and update a CD/DVD.
The program should provide a menu for the user to be able to add, delete, update and display the information in a CD/DVD.
Explanation / Answer
My DVD Class
#include "DVD.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class DVD //Redefinition of 'DVD'
{
private:
string title; //Holds title of dvd
int year; //Year made
double length; //Holds length of movie
public:
vector<string> actrs; //Actors and Actresses
vector<string> charNames; //Character names
void setTitle(string);
void setLength(double);
void setYear(int);
void addActChar(string, string);
string getTitle();
double getLength();
int getYear();
DVD() //Expected member name or ';' after declaration specifiers
{
title = "";
year = 0;
length = 0;
}
};
My header file for DVD Class
#ifndef __DVD_Database__DVD__
#define __DVD_Database__DVD__
#include <iostream>
#include "DVD.cpp"
#include <vector>
#include <string>
DVD DVD;
void DVD::setTitle(string t)
{
title = t;
}
void DVD::setLength(double l)
{
length = l;
}
void DVD::setYear(int y)
{
year = y;
}
void DVD::addActChar(string actrs, string charNames)
{
actor.push_back(actrs); //Undeclared identifier 'actor'
charat.push_back(charNames); //Undeclared identifier 'charat'
//pushback character
}
#endif /* defined(__DVD_Database__DVD__) */
Main
#include "DVD.h"
#include "DVD.cpp"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int selection; //Used for menu system
int numPeep; //Holds the number of people in the movie
string title; //Holds title of dvd
int year; //Year made
double length; //Holds length of movie
string actor; //Hold actor/actress name/
string charat; //Holds character name
class DVD DVD; //DVD Object
//Menu System
cout << "*****************************************************************************************" << endl;
cout << "* *" << endl;
cout << "* DVD Collection *" << endl;
cout << "* *" << endl;
cout << "*****************************************************************************************" << endl;
cout << endl;
cout << endl;
cout << "1. Add DVD" << endl;
cout << "2. Remove DVD" << endl;
cout << "3. Update DVD" << endl;
cout << "4. Show DVDs" << endl;
cin >> selection;
switch (selection)
{
case 1:
{
cout << "To add a new DVD please enter the title, length, year release, actors and their charactors" << endl;
cout << endl;
cout << "Movie Title: ";
getline(cin, title);
cout << endl;
cout << "Length: ";
cin >> length;
cout << endl;
cout << "Year: ";
cin >> year;
cout << endl;
cout << "You entered: " << title << " " << length << " " << year << endl;
cout << endl;
cout << "How many actors/characters do you want to add?" << endl;
cout << "#: ";
cin >> numPeep;
//Loop to pull in actors/ actresses
for (int i = 0; i < numPeep; i++)
{
//Actor and Actress
cout << "Actor/Actress " << (i + 1) << "Name: ";
getline(cin, actor);
cout << endl;
//Character they play
cout << "Character they play: ";
getline(cin, charat);
}
//Store dvd information
DVD.setTitle(title);
DVD.setYear(year);
DVD.setLength(length);
DVD.addActChar(actor, charat);
}break;
}
}