example,
Catwoman, 120:34, 2004, Halle Berry, Catwoman
------------------------------Benjamin Bratt, Tom Lone
------------------------------Alex Borstein, Sally
The actors and actors' character need to run in parallel.
lines 68-77 I'm trying to return the parallel vectors but I get the error shown on 73-77.
lines 126 I believe I need to use getline(cin,name[index]) but I can't without quantity being initialized to a constant
lines 119 I want the user to enter how many characters so that index will only go that far.
lines 139 I'm having trouble storing users input in addActor
Any suggestions?
#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; // To hold movie title
double length; // To hold movie length
int year; // To hold release date
public:
// Constructors
vector<string> actor; // To hold actor/actress name
vector<string> 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 32
int main()
{
int quantity; // To hold number of 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
// 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;
// How can I make this work with addActor
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);
mydvd.addActor(name, charName); // Is this right?

New Topic/Question
Reply


MultiQuote



|