Class Movie...error undeclared identifier

Thread Solved
Reply

Join Date: Jan 2008
Posts: 20
Reputation: blcase is an unknown quantity at this point 
Solved Threads: 0
blcase blcase is offline Offline
Newbie Poster

Class Movie...error undeclared identifier

 
0
  #1
Jan 22nd, 2008
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Movie {
  6. private:
  7. string director, title, genre, cast, rating, release;
  8. int length;
  9. public:
  10. Movie(){
  11. cout<<"constructor w/ no parameters called"<<endl;
  12. length=0;}
  13. Movie(string d, string t, string g, int l, string c, string r, string re){
  14. director=d;title=d;genre=g;length=l;cast=c;rating=r;release=re;}
  15. string getDirector();
  16. string getTitle();
  17. string getGenre();
  18. int getLength();
  19. string getCast();
  20. string getRating();
  21. string getRelease();
  22. void setDirector(string d);
  23. void setTitle(string t);
  24. void setGenre(string g);
  25. void setLength(int l);
  26. void setRating(string r);
  27. void setRelease(string re);
  28. };
  29. void Movie::setDirector(string d){
  30. director=d;}
  31. void Movie::setTitle(string t){
  32. title=t;}
  33. void Movie::setGenre(string g){
  34. genre=g;}
  35. void Movie::setLength(int l){
  36. length=l;}
  37. void Movie::setRating(string r){
  38. rating=r;}
  39. void Movie::setRelease(string re){
  40. release=re;}
  41. string Movie::getDirector(){
  42. return director;}
  43. string Movie::getTitle(){
  44. return title;}
  45. string Movie::getGenre(){
  46. return genre;}
  47. int Movie::getLength(){
  48. return length;}
  49. string Movie::getCast(){
  50. return cast;}
  51. string Movie::getRating(){
  52. return rating;}
  53. string Movie::getRelease(){
  54. return release;}
  55. int main(){
  56. cout<<"My Movies are: The Departed, The Matrix, Cloverfield"<<endl;
  57. Movie a(Scorcese, the Departed, Drama, 151, Leonardo diCaprio, 5 Stars, 2006);
  58. Movie b(Wachowski Brothers, The Matrix, SciFi, 136, Keanu Reeves, 4.5 Stars, 1999);
  59. Movie c(Reeves, Cloverfield, SciFi, 84, TJ Miller, 4.5 Stars, 2007);
  60. 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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 20
Reputation: blcase is an unknown quantity at this point 
Solved Threads: 0
blcase blcase is offline Offline
Newbie Poster

Re: Class Movie...error undeclared identifier

 
0
  #2
Jan 22nd, 2008
also i know all my definitions are outside of the class it was a requirement
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Class Movie...error undeclared identifier

 
0
  #3
Jan 22nd, 2008
An identifier and a string are different because a string is surrounded by double-quotes.
  1. Movie a(
  2. "Scorcese",
  3. "the Departed",
  4. "Drama",
  5. 151,
  6. "Leonardo diCaprio",
  7. "5 Stars",
  8. "2006"
  9. );
Formatted for readability...

Have fun!
Last edited by Duoas; Jan 22nd, 2008 at 4:33 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 20
Reputation: blcase is an unknown quantity at this point 
Solved Threads: 0
blcase blcase is offline Offline
Newbie Poster

Re: Class Movie...error undeclared identifier

 
0
  #4
Jan 22nd, 2008
thank you very much i knew i was just missing something...its been 2 years since i have had c++
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 20
Reputation: blcase is an unknown quantity at this point 
Solved Threads: 0
blcase blcase is offline Offline
Newbie Poster

Re: Class Movie...error undeclared identifier

 
0
  #5
Jan 22nd, 2008
  1. string Movie::show(){
  2. string s1;
  3. s1=getTitle();
  4. return s1;}
  5. int Movie::showtime(){
  6. int time1;
  7. time1=getLength()/60;
  8. return time1;}
  9. int Movie::showtimem(){
  10. int time2;
  11. time2=getLength()%60;
  12. 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?"
Last edited by blcase; Jan 22nd, 2008 at 5:21 pm. Reason: typo
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Class Movie...error undeclared identifier

 
0
  #6
Jan 22nd, 2008
Yes. The easiest way would be to use reference parameters.
  1. void Movie::getstuff( std::string &name, int &hours, int &minutes ) {
  2. name = getTitle();
  3. hours = getLength() /60;
  4. minutes = getLength() %60;
  5. }

Then you would call it like
  1. std::string title;
  2. int hour, min;
  3. a.getstuff( title, hour, min );
  4. std::cout << '"' << title << "\" has a runtime of "
  5. << hour << ':' << min << std::endl;


That said, the better way is to keep it separate like you have it.
  1. std::cout << '"' << a.getTitle() << "\" has a runtime of "
  2. << a.showtime() << ':' << a.showtimem() << std::endl;

Good luck.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC