| | |
Class Movie...error undeclared identifier
Thread Solved
![]() |
•
•
Join Date: Jan 2008
Posts: 20
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#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;}
An identifier and a string are different because a string is surrounded by double-quotes.
Formatted for readability...
Have fun!
C++ Syntax (Toggle Plain Text)
Movie a( "Scorcese", "the Departed", "Drama", 151, "Leonardo diCaprio", "5 Stars", "2006" );
Have fun!
Last edited by Duoas; Jan 22nd, 2008 at 4:33 pm.
•
•
Join Date: Jan 2008
Posts: 20
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
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;}
Last edited by blcase; Jan 22nd, 2008 at 5:21 pm. Reason: typo
Yes. The easiest way would be to use reference parameters.
Then you would call it like
That said, the better way is to keep it separate like you have it.
Good luck.
C++ Syntax (Toggle Plain Text)
void Movie::getstuff( std::string &name, int &hours, int &minutes ) { name = getTitle(); hours = getLength() /60; minutes = getLength() %60; }
Then you would call it like
C++ Syntax (Toggle Plain Text)
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.
C++ Syntax (Toggle Plain Text)
std::cout << '"' << a.getTitle() << "\" has a runtime of " << a.showtime() << ':' << a.showtimem() << std::endl;
Good luck.
![]() |
Other Threads in the C++ Forum
- Previous Thread: editor same as C
- Next Thread: mouse functions for DOS
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph guess gui homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






