#include <iostream>
#include <string>
using namespace std;

class Movie {
private:
        string director, title, genre, cast, rating, release;
        int length;
public:
        Movie(){
                cout<<"constructor w/ no parameters called"<<endl;
                length=0;}
        Movie(string d, string t, string g, int l, string c, string r, string re){
                director=d;title=d;genre=g;length=l;cast=c;rating=r;release=re;}
        string getDirector();                
        string getTitle();
        string getGenre();
        int getLength();
        string getCast();
        string getRating();
        string getRelease();
        void setDirector(string d);
        void setTitle(string t);
        void setGenre(string g);
        void setLength(int l);
        void setRating(string r);
        void setRelease(string re);
};
void Movie::setDirector(string d){
        director=d;}
void Movie::setTitle(string t){
        title=t;}
void Movie::setGenre(string g){
        genre=g;}
void Movie::setLength(int l){
        length=l;}
void Movie::setRating(string r){
        rating=r;}
void Movie::setRelease(string re){
        release=re;}
string Movie::getDirector(){
        return director;}
string Movie::getTitle(){
        return title;}
string Movie::getGenre(){
        return genre;}
int Movie::getLength(){
        return length;}
string Movie::getCast(){
        return cast;}
string Movie::getRating(){
        return rating;}
string Movie::getRelease(){
        return release;}
int main(){
        cout<<"My Movies are: The Departed, The Matrix, Cloverfield"<<endl;
        Movie a(Scorcese, the Departed, Drama, 151, Leonardo diCaprio, 5 Stars, 2006);
        Movie b(Wachowski Brothers, The Matrix, SciFi, 136, Keanu Reeves, 4.5 Stars, 1999);
        Movie c(Reeves, Cloverfield, SciFi, 84, TJ Miller, 4.5 Stars, 2007);
        return 0;}

I am trying to create a class movie. When i enter in the Movie a,b,etc. it gives me the error undeclared identifier. I don't understand this error i was under the impression that by syntaxing it in that way it would call upon the constructor and enter it as that. any help?

Recommended Answers

All 5 Replies

also i know all my definitions are outside of the class it was a requirement

An identifier and a string are different because a string is surrounded by double-quotes.

Movie a(
  "Scorcese",
  "the Departed",
  "Drama",
  151,
  "Leonardo diCaprio",
  "5 Stars",
  "2006"
  );

Formatted for readability...

Have fun!

thank you very much i knew i was just missing something...its been 2 years since i have had c++

string Movie::show(){
	string s1;
	s1=getTitle();
	return s1;}
int Movie::showtime(){
	int time1;
	time1=getLength()/60;
	return time1;}
int Movie::showtimem(){
	int time2;
	time2=getLength()%60;
	return time2;}

is it possible to bring these three into one operation...i guess my real question is "is it possible to return more than one value and if yes then more than one value of more than one type?"

Yes. The easiest way would be to use reference parameters.

void Movie::getstuff( std::string &name, int &hours, int &minutes ) {
  name    = getTitle();
  hours   = getLength() /60;
  minutes = getLength() %60;
  }

Then you would call it like

std::string title;
int hour, min;
a.getstuff( title, hour, min );
std::cout << '"' << title << "\" has a runtime of "
  << hour << ':' << min << std::endl;

That said, the better way is to keep it separate like you have it.

std::cout << '"' << a.getTitle() << "\" has a runtime of "
  << a.showtime() << ':' << a.showtimem() << std::endl;

Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.