Structures

I am so confused in what I am doing wrong and how can I fix it. The main problem is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <string>

using namespace std;

struct MovieInfo
{
	string title, director;
	int year, time;
	MovieInfo(string t, string d, int y, int t2)
	{
	string title1, director1;
	int year1, time1; 
	}
	MovieInfo(string t, string d, int y, int t2)//Here I am supposed to use this MovieInfo three times but how can I do it.
	{
		string title2, director2;
		int year2, time2;
	}
	
};
void DisplayMovieInfo(MovieInfo &md);

int main()
{
	MovieInfo movie1("War of the Worlds", "Byron Haskin", 1953, 88),
		movie2("War of the Worlds", "Stephen Spielberg", 2005, 118),
		movie3("War of the Worlds", "Stephen Spielberg", 2005, 118);

	DisplayMovieInfo(movie1);
	DisplayMovieInfo(movie2);
	DisplayMovieInfo(movie3);


	return 0;
}


void DisplayMovieInfo(MovieInfo &md)
{

	cout << "The movie " << md.title << " was directed by " << md.director << " and released in " << md.year << " with a run time of " << md.time << " minutes " << endl;
	
}


Last edited on
I am so confused in what I am doing wrong and how can I fix it. The main problem is

What is your main problem?
Line 15, I am supposed to make three MovieInfo variables and FILL them with the movie information, I am confused in that
Have a read here, specifically the constructors section:
http://www.cplusplus.com/doc/tutorial/classes/
I am not on classes yet, I have only studied structures and Header files.
I am supposed to make three MovieInfo variables

use arrays

FILL them with the movie information

if its default use constructor, if its user defined use functions, also read the article given by integralfx it will help you with that

http://www.cplusplus.com/doc/tutorial/structures/
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>

using namespace std;

struct MovieInfo
{
	string title, director;
	int year, time;
	MovieInfo(string t, string d, int y, int t2) : title(t), director(d), year(y), time(t2) { }
        MovieInfo() : title("none"), director("none"), year(0), time(0) { }
};

void DisplayMovieInfo(MovieInfo &md);

int main()
{
	MovieInfo movie1("War of the Worlds", "Byron Haskin", 1953, 88),
		  movie2("War of the Worlds", "Stephen Spielberg", 2005, 118),
		  movie3("War of the Worlds", "Stephen Spielberg", 2005, 118);

	DisplayMovieInfo(movie1);
	DisplayMovieInfo(movie2);
	DisplayMovieInfo(movie3);


	return 0;
}


void DisplayMovieInfo(MovieInfo &md)
{

	cout << "The movie " << md.title << " was directed by " << md.director <<
        " and released in " << md.year << " with a run time of " << md.time <<
        " minutes " << endl;
	
}
Last edited on
Topic archived. No new replies allowed.