Answer:
Complete code is given and the output is attached also
Step-by-step explanation:
#include <iostream>
#include <iomanip>
#include <list>
#include <iterator>
using namespace std;
/*
1. You will need to create a structure named MovieInfo that contains the following information about a movie:
title (string) - title of the movie
release date (string)
mpaa rating (string) - G, PG13, PG, R, NC17
number of stars (double) - out of 5
*/
struct MovieInfo
{
string title; //- title of the movie
string releaseDate ; //
string mpaaRating; // rating - G, PG13, PG, R, NC17
double numberOfStars; // of stars (1 out of 5)
};
/*
3. Write a function to prompt the user to enter the information for one movie (title, release date, mpaa rating and number of stars). This function should then return the movie information back to main. You should call this function twice, once for each of the MovieInfo variables in main.
Note: After you read the number of stars, you will need to use cin.get() or cin.ignore() to get rid of the end of line character prior to the next call to getline in your program
cout << "Enter the number of stars the movie received : ";
cin >> movie.numberOfStars;
cin.get();
*/
MovieInfo promptForMovieInformationAndReturn(){
MovieInfo movie;
cout<<"Enter the title of movie : ";
getline (cin,movie.title);
cout<<"Enter the release date of movie : ";
getline (cin,movie.releaseDate);
cout<<"Enter the mpaa rating of movie : ";
getline (cin,movie.mpaaRating);
cout << "Enter the number of stars the movie received : ";
cin >> movie.numberOfStars;
cin.get();
cout<<endl;
return movie;
}
/*
4. Write a function to display a list of movie recommendations that contains only the movies with 4 or more stars. The list of recommendations should include:
a title - Movie Recommendations
movie name
number of stars (formatted so you have 1 place after the decimal point)
You will need to use an if .. else if statement to display either both movies, one movie, or a message that you have no recommendations.
*/
void displayListOfMovieRecommendations(list<MovieInfo> movies){
list <MovieInfo> :: iterator it;
cout<<setw(16)<<left<<"*******************************"<<endl;
cout<<setw(16)<<left<<" Movie Recommendations "<<endl;
cout<<setw(16)<<left<<"*******************************"<<endl;
for(it = movies.begin(); it != movies.end(); ++it) {
if(it->numberOfStars >= 4 ){
cout <<setw(16)<<left<< it->title<<setw(16)<<left<<setprecision(2)<< it-> numberOfStars <<endl;
}
}
}
int main() {
/*
2. The main program will create two MovieInfo variables, for example movie1 and movie2.
*/
MovieInfo movie1;
MovieInfo movie2;
movie1 = promptForMovieInformationAndReturn();
movie2 = promptForMovieInformationAndReturn();
list <MovieInfo> movies;
movies.push_back(movie1);
movies.push_back(movie2);
displayListOfMovieRecommendations(movies);
}