Question
Write a C++ program that will perform operations on a vector of structs. The struct is named Film and is defined as follows: struct Film
Write a C++ program that will perform operations on a vector of structs. The struct is named Film and is defined as follows:
struct Film {
int id; // the unique id of the film
string name; // the film's name
string description; // the film's description
int runningTime; // the film's running time in minutes <= 180
int rating; // the film's rating, from the const decls
};
Where runningTime is a value between 10 and 180 and rating is a value within the range of the following constants:
const int FILM_RATING_G = 0;
const int FILM_RATING_PG = 1;
const int FILM_RATING_PG_13 = 2;
const int FILM_RATING_R = 3;
const int FILM_RATING_NC_17 = 4;
const int FILM_RATING_UNRATED = 5;
Both the struct and the constants are in the global scope.
Your program should perform the following operations:
Initialize a vector of Film with at least 10 elements; use any film names, ratings, running times, and descriptions you like, real or imagined. Print the results from your original definition. See an example at the end of this document.
Using a selection sort, sort the film elements into ascending order according to their running time. Print the results, properly labeled.
The signature of your selection sort function should be
vector
Using a linear search function, findFilmsByRating, return the set of films that have a rating of the specified rating or less. Print the result, properly labeled.
For example, a call to findFilmsByRating with a parameter of FILM_RATING_PG_13 should return all films with rating PG 13, PG, and G.
The signature for your function should be
vector
Using a linear search function, findFilmsByRatingAndRunningTime, return the set of films that have a rating of the specified rating or less and the specified running time or less. Print the result, properly labeled.
For example, a call to findFilmsByRatingAndRunning time with parameters of FILM_RATING_PG_13 and 90 should return all films with rating PG 13, PG, and G and a running time of 90 minutes or less.
The signature for your function should be
vector
Define and use the following helper functions in your program
1.
2.
3.
Example: Assignment for Vector of 4 films
films[0].id = 0;
films[0].name = "Under World";
films[0].description = "Vampires vs. Werewolves";
films[0].runningTime = 134;
films[0].rating = FILM_RATING_R;
films[1].id = 1;
films[1].name = "Bambi";
films[1].description = "A young deer grows up";
films[1].runningTime = 70;
films[1].rating = FILM_RATING_G;
films[2].id = 2;
films[2].name = "Blade Runner";
films[2].description =
"A Blade Runner must pursue and try to terminate four replicants";
films[2].runningTime = 117;
films[2].rating = FILM_RATING_R;
films[3].id = 3;
films[3].name = "Limitless";
films[3].description =
"A mysterious pill helps a man use 100% of his brain";
films[3].runningTime = 105;
films[3].rating = FILM_RATING_PG_13;
Example 2: Results from Invocations of sort and search functions
******Films in sorted order by running time *****
Film title : Bambi
Film description : A young deer grows up
Film running time : 70 minutes
Film rating : G
Film title : Limitless
Film description : A mysterious pill helps a man use 100% of his brain
Film running time : 105 minutes
Film rating : PG 13
Film title : Blade Runner
Film description : A Blade Runner must pursue and try to terminate four replicants
Film running time : 117 minutes
Film rating : R
Film title : Under World
Film description : Vampires vs. Werewolves
Film running time : 134 minutes
Film rating : R
******Films rated PG 13 or less *****
Film title : Bambi
Film description : A young deer grows up
Film running time : 70 minutes
Film rating : G
Film title : Limitless
Film description : A mysterious pill helps a man use 100% of his brain
Film running time : 105 minutes
Film rating : PG 13
******Films rated PG 13 or less with running time < 90 *****
Film title : Bambi
Film description : A young deer grows up
Film running time : 70 minutes
Film rating : G
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started