DVD Collection using Classes and Vectors

I am working on a C++ class assignment creating either a CD or DVD collection program. I copied the assignment below. Right now I am just trying to store the dvd information and I am running into issues. I am using Xcode, but I could migrate to VS 10 or 12 Pro if needed. I don't quite understand how to store 1 dvd per class either.




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.






So I have my Main, DVD Class and the header file for the class. As of right now I am getting some errors that I just don't understand. One is redefinition of DVD Class by my constructor.

Here are the errors I am getting right now.

1. Header file, when storing actors and characters in my vector I received the undeclared identifier of actor and charat. I thought my header would get the information from the DVD class.

2. Redefinition of DVD in my DVD Class.

3. Expected member name or ';' after declaration.

4. Parse issue, wants me to use 'class' tag to refer to type DVD.








My DVD Class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

#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;
            
            
    
    }
    
   
    
}
Topic archived. No new replies allowed.