Help with CD/DVD program

I'm trying to figure out what is wrong and how to fix it. This is what I have so far. Here is the question for the problem. If you can help me fix it thank you.

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. The data will be stored in a file. The data from the file will be stored in a 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.

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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
 #include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

// Function Prototype
void showList(string, double, int, string, string);
void showMenu();

class DVD
{
private:
string movie;   
double length;   
int year;   

public: // Constructors
   vector<string> actor; //To hold actors name
vector<string> charName; //To hold name of the 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;
   }
};

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 << "Enter the movie title, length, and year released.\n"
<< "Hit [ENTER] after each input: ";
getline(cin, title);
cin >> movieLength;
cin >> yearReleased;

//Here I would like to ask the user "How many actors
// Do you wish to enter...
cout << "How many actors? ";
cin >> 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; index < quantity; index++)
{
cout << "Enter actor #" << (index+1) << ": ";
getline(cin, name); //Is this right or should it be
// getline(cin, name[index]);
cin.ignore();
cout << "Enter the name of the character portrayed "
<< "by actor #" << (index+1) << ": ";
getline(cin, charName); //Same here?
cin.ignore();
}
cout << endl;
// Store the DVD details
mydvd.setMovie(title);
mydvd.setLength(movieLength);
mydvd.setYear(yearReleased);

/**
* Adds an actor name and his character name to the DVD object
*/
void DVD::addActor(string actorName, string characterName)
{
name.push_back(actorName); // push_back method adds next item to a vector
charName .push_back(characterName);
}
string DVD::getActor(unsigned int index)
{
if(index >= name.size())
return "no data";
return name[index];
}
void main(){
DVD mydvd;
mydvd.setMovie("The Godfather");
mydvd.addActor("Marlon B", "The mumbling guy");
mydvd.addActor("Al Pacino", "The crybaby");
cout << mydvd.getActor(0); // outputs "Marlon B" to the console
}
Since actorName and charName is public, I think you don't need an accessor for that

And oh yeah you're trying to acess name which is never declared, and the function prototype is different with its actual function
Last edited on
Topic archived. No new replies allowed.