In: Computer Science
I am struggling with c++ and I could use some guidance getting through this project. Below are my directions.
The objective of this project is to be able to incorporate structures in a program. The program will have the user enter the information for two movies (details below) and then display a list of recommended movies that have 4 or more stars.
1. You will need to create a structure named MovieInfo that contains the following information about a movie:
2. The main program will create two MovieInfo variables, for example movie1 and movie2.
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();
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:
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.
5. Your project must contain documentation (comments)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
This is the code I have started and am stuck. Am I on the right track?
include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct MovieInfo
{
string title- title of the movie ; //
string release date ; //
string mpaa rating - G, PG13, PG, R, NC17 ; //
double number of stars (1 out of 5) ; //
};
int main()
{
MovieInfo movie1 = {"title", "release date", "mpaa
rating", "number of stars"};
MovieInfo movie2 = {"title", "release date", "mpaa
rating", "number of stars"};
}
void movieTitle (title)
cout << "Enter the title of the Movie : "
<< endl;
cin >> title >> endl;
cin.get();
}
Please let me know if you need more information:-
=====================================
#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);
}
==
==
==============================
Enter the title of movie : Avengers
Enter the release date of movie : 03/05/2018
Enter the mpaa rating of movie : NC17
Enter the number of stars the movie received : 4.8
Enter the title of movie : 300 Men
Enter the release date of movie : 06/07/2016
Enter the mpaa rating of movie : PG13
Enter the number of stars the movie received : 4.25
*******************************
Movie Recommendations
*******************************
Avengers 4.8
300 Men 4.2
==
===
Thanks