storing actors in a movie class

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1074 Views - Last Post: 19 February 2013 - 04:27 AM Rate Topic: -----

#16 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3622
  • View blog
  • Posts: 11,290
  • Joined: 05-May 12

Re: storing actors in a movie class

Posted 18 February 2013 - 06:23 PM

Then just like baavgai said in post #7, it's simply a parse issue. In psuedo code:
while(not end of line)
{
    name = collect characters until the semicolon or end of line
    movie.actors.push_back(name)
}



jayburn00, I think you are over thinking the problem just like in the other thread about building a tree. Just put together a small program that adds strings into a vector of strings so that you can experiment. Then apply what you've learned back into this assignment.
Was This Post Helpful? 0
  • +
  • -

#17 jayburn00  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 129
  • Joined: 05-July 12

Re: storing actors in a movie class

Posted 18 February 2013 - 07:37 PM

View Postjayburn00, on 18 February 2013 - 04:51 PM, said:

View PostSkydiver, on 18 February 2013 - 04:29 PM, said:

If you knew that you could declare:
vector<movie> movies;



Then you can also have member in your movie class:
class movie
{
    :

    vector<actor> actors;
};



I don't understand what all the hand wringing is about. My only point of concern is it seems that your input file is semi-colon delimited. I think you'll need to figure out how to delimit when the actors start and end.


All I know is that everything is delimitted by semicolon, that is simply how the file is. The end of the actors is the end of the record (actors are always the last entities listed in the file. Title is first, then so and so forth.) So, with that in mind, how would I set it up?

Ok, I just tried the above code with common sense additions since it obviously has more to it than simply adding the vector code given above, but I can't seem to be able to put it in properly. When I put it in, actor is raised as an error, saying actor is not a type. I had tried declaring actor as string: string actor, the way I declared every other string, but that didn't fix it either. I guess what I'm trying to say is that, I can't even read actors into a vector until I figure out how to create the vector to begin with. The parsing thing won't be an issue until I have a vector to actually read data into. I also can now display each movie, but without any actors.
Was This Post Helpful? 0
  • +
  • -

#18 jimblumberg  Icon User is online

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: storing actors in a movie class

Posted 18 February 2013 - 09:07 PM

Show the code where you tried to implement the vector and post all the error/warning messages exactly as they appear in your development environment.


Jim
Was This Post Helpful? 0
  • +
  • -

#19 jayburn00  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 129
  • Joined: 05-July 12

Re: storing actors in a movie class

Posted 18 February 2013 - 09:56 PM

Here is what I have, it gives me an error about movie::actor is not a type name, and that actor is undefined.
class movie
{
public:
	movie()//default constructor
	{
		this->title="";
		this->runningTime=0;//Movie length in minutes or hours, depends on file.
		this->genre="";
		this->description="";
		this->year=0;
		this->director="";
		this->actor="";
		//this->actor=don't know how this part is implemented.
	}
	movie(string title, int runningTime, string genre, string description, int year, string director, vector<actor> Actors)
	{
		this->title = title;
		this->runningTime= runningTime;
		this->genre= genre;
		this->description= description;
		this->year= year;
		this->director= director;
		this->Actors=Actors;
		//this->actor and what ever I do with actor.
	}

	void showRecord()
	{
		cout<<"Title:  "<<this->title<<endl;
		cout<<"Running Time:  "<<this->runningTime<<endl;
		cout<<"Genre:  "<<this->genre<<endl;
		cout<<"Description:  "<<this->description<<endl;
		cout<<"Year:  "<<this->year<<endl;
		cout<<"Director:  "<<this->director<<endl;
		/*actor portion*/
	}

private:
	string title, genre, description, director, actor; //actor also
	int runningTime, year;
	vector <actor> Actors;
};

Was This Post Helpful? 0
  • +
  • -

#20 jimblumberg  Icon User is online

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: storing actors in a movie class

Posted 18 February 2013 - 10:09 PM

And what include files are you including? And how are you scoping the std:: namespace?

Jim
Was This Post Helpful? 0
  • +
  • -

#21 jayburn00  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 129
  • Joined: 05-July 12

Re: storing actors in a movie class

Posted 19 February 2013 - 01:13 AM

View Postjimblumberg, on 18 February 2013 - 10:09 PM, said:

And what include files are you including? And how are you scoping the std:: namespace?

Jim

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cstdio>
#include <fstream>
#include <cstdlib>
I used "using namespace std;"

View Postjimblumberg, on 18 February 2013 - 10:09 PM, said:

And what include files are you including? And how are you scoping the std:: namespace?

Jim

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cstdio>
#include <fstream>
#include <cstdlib>
I used "using namespace std;"
Was This Post Helpful? 0
  • +
  • -

#22 jimblumberg  Icon User is online

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: storing actors in a movie class

Posted 19 February 2013 - 04:27 AM

In your constructor:
    movie(string title, int runningTime, string genre, string description, int year, string director, vector<actor> Actors)

Where is the struct/class actor defined? You either mean to define the vector as a vector<string> Actor or define a class named actor that holds the information about an actor.

Also it is considered bad practice to use the "using namespace std;" clause in a header file. You should use the scope operator:: to properly scope things in the std namespace.


Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2