I need to write a program that uses structure movieData to store the release date, duration, director and title name of the movie. One movie needs to be statically allocated (all 4 fields) and the other dynamically (all 4 fields). And finally two functions to call to display what is stored.My question is how do I get the function to display the results? And also how to i us the same structure but for two different movies? This is what i have so far. If you see any other errors or styling mistakes please let me know. Thank you for your help in advance!
//Chapter 11 Program 1: Movie Data
//Written by
#include <iostream>
#include <string>
usingnamespace std;
struct movieData
{
string title;
string director;
int releaseDate;
int runTime;
};
movieData *m = nullptr;
movieData movie1, movie2;
//*********************************************************************************************************
//Function for getting movie data *
//*********************************************************************************************************
void getMovieData(movieData *m)
{
//Get movie title
cout << " What is the title of the movie?\n";
getline(cin, m->title);
//Get director's name
cout << " Who directed the movie?\n";
cin >> (cin, m->director);
//Get movie release date
cout << " When was this movie released?\n";
cin >> m->releaseDate;
//Get movie runtime
cout << " How long is the movie?\n";
cin >> m->runTime;
}
int main()
{
cout << " Hi, today we will create a structure called movieData and store information\n into it.\n ";
getMovieData(*m)
}
Ive gotten further and now i need to know how to display each movie data. I know im suppose to displayMovie(movie1) but im not sure how to go about this. This is what i have so far. Instead of movie1.title i had moviedata.title but i kept getting an error. Also it is not letting me statically allocate the 4 fields in movieData.
//Chapter 11 Program 1: Movie Data
//Written by
#include <iostream>
#include <string>
usingnamespace std;
struct movieData
{
string title;
string director;
int releaseDate;
int runTime;
};
movieData *m = nullptr;
movieData movie1, movie2;
//*********************************************************************************************************
//Function for getting movie data *
//*********************************************************************************************************
void getMovieData(movieData *m)
{
//Get movie title
cout << " What is the title of the movie?\n";
getline(cin, m->title);
//Get director's name
cout << " Who directed the movie?\n";
cin >> (cin, m->director);
//Get movie release date
cout << " When was this movie released?\n";
cin >> m->releaseDate;
//Get movie runtime
cout << " How long is the movie in minutes?\n";
cin >> m->runTime;
};
//******************************************************************************************
//Function to display what is in the struct *
//******************************************************************************************
void displayMovie1()
{
cout << " Movie: " << movie1.title <<endl;
cout << " Director: " << movie1.director << endl;
cout << " Release date: " << movie1.releaseDate << endl;
cout << " Run time: " << movie1.runTime << endl;
}
int main()
{
movieData movie2
(
"District 9",
"Neil BlomKamp",
2009,
112
);
cout << " Hi, today we will create a structure called movieData and store information\n into it.\n ";
getMovieData(&movie1);
displayMovie1();
}
}
int main()
{
movieData movie1, movie2, badMovie, goodMovie, scaryMovie;
//fill up each of these movie objects with data, might I suggest
//your handy getMovieData function that you already have?
//after each movie has data, you can call the same function
//to display each movie
displayMovie(movie1);
displayMovie(goodMovie);
displayMovie(badMovie);
displayMovie(movie2);
displayMovie(scaryMovie);
}
EDIT: Notice that you're already using a function with a parameter (getMovieData takes a pointer to a movieData object as its parameter).
//Chapter 11 Program 1: Movie Data
//Written by
#include <iostream>
#include <string>
usingnamespace std;
struct movieData
{
string title;
string director;
int releaseDate;
int runTime;
};
movieData *m = nullptr;
movieData movie1, movie2;
//*********************************************************************************************************
//Function for getting movie data *
//*********************************************************************************************************
void getMovieData(movieData *m)
{
//Get movie title
cout << " What is the title of the movie?\n";
getline(cin, m->title);
//Get director's name
cout << " Who directed the movie?\n";
cin >> (cin, m->director);
//Get movie release date
cout << " When was this movie released?\n";
cin >> m->releaseDate;
//Get movie runtime
cout << " How long is the movie in minutes?\n";
cin >> m->runTime;
};
//******************************************************************************************
//Function to display what is in struct *
//******************************************************************************************
void displayMovie(movieData movieP)
{
cout << " Movie: " << movieP.title <<endl;
cout << " Director: " << movieP.director << endl;
cout << " Release date: " << movieP.releaseDate << endl;
cout << " Run time: " << movieP.runTime << endl;
}
int main()
{
movie2 ("District 9", "Neil BlomKamp", 2009, 112);
cout << " Hi, today we will create a structure called movieData and store information\n into it.\n ";
getMovieData(&movie1);
displayMovie(movie1);
displayMovie(movie2);
return 0;
}
Is this is the error message?
Error 1 error C2064: term does not evaluate to a function taking 4 arguments
and also one that says:
2 IntelliSense: call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type
I figured it out! Thanks for everyone's help!!! I am curious how to dynamically allocate one of the movie structures and then im completely done. This is what i have completed so far
//Chapter 11 Program 1: Movie Data
//Written by
#include <iostream>
#include <string>
usingnamespace std;
struct movieData
{
string title;
string director;
int releaseDate;
int runTime;
};
movieData *m = nullptr;
movieData movie1, movie2;
//*********************************************************************************************************
//Function for getting movie data *
//*********************************************************************************************************
void getMovieData(movieData *m)
{
//Get movie title
cout << " What is the title of the movie?\n";
getline(cin, m->title);
//Get director's name
cout << " Who directed the movie?\n";
getline(cin, m->director);
//Get movie release date
cout << " When was this movie released?\n";
cin >> m->releaseDate;
//Get movie runtime
cout << " How long is the movie in minutes?\n";
cin >> m->runTime;
};
//******************************************************************************************
//Function to display what is in struct *
//******************************************************************************************
void displayMovie(movieData movieP)
{
cout << " Movie: " << movieP.title <<endl;
cout << " Director: " << movieP.director << endl;
cout << " Release date: " << movieP.releaseDate << endl;
cout << " Run time: " << movieP.runTime << endl;
}
int main()
{
movie2.title = "District 9";
movie2.director = "Neil BlomKamp";
movie2.releaseDate = 2009;
movie2.runTime = 112;
cout << " Hi, today we will create a structure called movieData and store information\n into it.\n ";
getMovieData(&movie1);
displayMovie(movie1);
displayMovie(movie2);
return 0;
}