Structures

I have an assignment for school that I need help with. I've written some code and just need to know if I have done what is asked. This is the assignment. Any input would be greatly appreciated.

Write a program that uses a structure named MovieData to store the following information about a movie:
Title
Director
Year Released
Running Time(in minutes)
Include a constructor that allows all four of these member data values to be specified at the time a MovieData variable is created. The Program should create two MovieData variables and pass each one in turn to a function that displays the information about the movie in a clearly formatted manner.

Here is my code. Thank You.

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
45
46
47
48
49
50

#include <iostream>
#include <string>

using namespace std;

struct MovieData
{
	string title;
	string direct;
	string yearR;
	string runningT;
};
void getData(MovieData &);
void showData(const MovieData &);

int main()
{
	MovieData part;

	getData(part);
	showData(part);
	return 0;
}

void getData(MovieData &movie)
{
	cout<<"Enter title of movie:"<<endl;
	cin>>movie.title;

	cout<<"Enter the Director of movie:"<<endl;
	cin.ignore();
	getline(cin, movie.direct);

	cout<<"Enter the year movie was released:"<<endl;
	cin>>movie.yearR;

	cout<<"Enter how long the movie is in minutes:"<<endl;
	cin>>movie.runningT;
}

void showData(const MovieData &movie)

{
	cout<<"\nHere is the Movie Data:\n";
	cout<<"Title:         "<<movie.title<<endl;
	cout<<"Director:      "<<movie.direct<<endl;
	cout<<"Year Released: "<<movie.yearR<<endl;
	cout<<"Running Time:  "<<movie.runningT<<endl;
}
Last edited on
I didn't see you create a constructor or call a function to print the results. Also your instructor asked for 2 movies.

This is what I believe your instructor is asking for.

I'm a noob also so don't take my word on it!

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>

using namespace std;

struct MovieData
{
 string m, n, o, p;
 MovieData (string, string, string, string);
};
//Make a constructor
MovieData::MovieData (string a, string b, string c, string d) {
    m = a;
    n = b;
    o = c;
    p = d;
}

void printinfo (MovieData Q)
{
  	cout<<"\nHere is the Movie Data:\n";
	cout<<"Title:         "<<Q.m<<endl;
	cout<<"Director:      "<<Q.n<<endl;
	cout<<"Year Released: "<<Q.o<<endl;
	cout<<"Running Time:  "<<Q.p<<endl;
}

int main()
{
    string title;
	string direct;
	string yearR;
	string runningT;

	//getmovie data
	cout<<"Enter title of movie:"<<endl;
	cin>>title;

	cout<<"Enter the Director of movie:"<<endl;
	cin.ignore();
	getline(cin, direct);

	cout<<"Enter the year movie was released:"<<endl;
	cin>>yearR;

	cout<<"Enter how long the movie is in minutes:"<<endl;
	cin>>runningT;

	MovieData moviea(title, direct, yearR, runningT); //defines variables at moment of creation

    cout<<"Enter title of movie:"<<endl;
	cin>>title;

	cout<<"Enter the Director of movie:"<<endl;
	cin.ignore();
	getline(cin, direct);

	cout<<"Enter the year movie was released:"<<endl;
	cin>>yearR;

	cout<<"Enter how long the movie is in minutes:"<<endl;
	cin>>runningT;

	MovieData movieb(title, direct, yearR, runningT);

	//Call function to Display the results.
	printinfo (moviea);
	printinfo (movieb);

	return 0;
}
Last edited on
Topic archived. No new replies allowed.