daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Assignment: 3
  2. //Version: 1
  3. //Name: Jeremy Pequeno
  4. //Instructor: Patricia Carando
  5.  
  6. #include <algorithm>
  7. #include <cstdlib>
  8. #include <iostream>
  9. #include <fstream>
  10. #include <vector>
  11.  
  12. using namespace std;
  13.  
  14. const int FILM_RATING_G       = 0;
  15.  
  16. const int FILM_RATING_PG      = 1;
  17.  
  18. const int FILM_RATING_PG_13   = 2;
  19.  
  20. const int FILM_RATING_R       = 3;
  21.  
  22. const int FILM_RATING_NC_17   = 4;
  23.  
  24. const int FILM_RATING_UNRATED = 5;
  25.  
  26. const int SIZE = 10;
  27.  
  28.    
  29. struct Film {
  30.  
  31.      int id;                      // the unique id of the film
  32.  
  33.      string name;            // the film's name
  34.  
  35.      string description;   // the film's description
  36.  
  37.      int runningTime;      // the film's running time in minutes <= 180
  38.  
  39.      int rating;                // the film's rating, from the const decls
  40.  
  41. };
  42.  
  43. string filmRatingToString(int rating);
  44. vector <Film> addFilms (vector <Film> &films);
  45. vector <Film> findFilmsByRating ( int rating, vector <Film> &films);
  46. vector <Film> findFilmsByRatingAndRunningTime ( int rating, int runningTime, vector <Film> &films);
  47. vector <Film> selectionSort (vector <Film> &films);
  48. void printFilm(Film films);
  49. void printFilms(vector<Film> films);
  50.  
  51.  
  52. int main(){
  53.     vector <Film> films (SIZE);
  54.     cout << "***** Films added ***** \n" << endl;
  55.     addFilms(films);
  56.     printFilms(films);
  57.    
  58.     cout << "\n***** Films in sorted order by their run time ***** \n" << endl;
  59.     printFilms(selectionSort(films));
  60.    
  61.     cout << "\n*****Films rated PG-13 or less***** \n" << endl;
  62.     findFilmsByRating(FILM_RATING_PG_13, films);
  63.    
  64.     cout << "\n*****Films rated PG-13 or less and less than 90 minutes long***** \n" << endl;
  65.     findFilmsByRatingAndRunningTime(FILM_RATING_PG_13, 90, films);
  66.    
  67.     return 0;
  68. }
  69.  
  70. string filmRatingToString(int rating){
  71.     string filmRating;
  72.    
  73.     if(rating == 0){
  74.         filmRating = "G";
  75.     }
  76.     if(rating == 1){
  77.         filmRating = "PG";
  78.     }
  79.     if(rating == 2){
  80.         filmRating = "PG-13";
  81.     }
  82.     if(rating == 3){
  83.         filmRating = "R";
  84.     }
  85.     if(rating == 4){
  86.         filmRating = "NC-17";
  87.     }
  88.     if(rating == 5){
  89.         filmRating = "Unrated";
  90.     }
  91.     return filmRating;
  92. }
  93.  
  94. //innitialize values in the vector films
  95. vector <Film> addFilms (vector <Film> &films)
  96. {
  97.     films[0].id = 0;
  98.     films[0].name = "Willy Wonka & the Chocolate Factory";
  99.     films[0].description = "Children take a tour of a candy factory from the most famous of all candy producers.";
  100.     films[0].runningTime = 100;
  101.     films[0].rating = FILM_RATING_G;
  102.    
  103.     films[1].id = 1;
  104.     films[1].name = "It (2017)";
  105.     films[1].description = "In the summer of 1989, a group of bullied kids band together to destroy a shapeshifting monster, which disguises itself as a clown and preys on the children of Derry, their small Maine town.";
  106.     films[1].runningTime = 135;
  107.     films[1].rating = FILM_RATING_R;
  108.    
  109.     films[2].id = 2;
  110.     films[2].name = "Toy Story";
  111.     films[2].description = "A cowboy doll is profoundly threatened and jealous when a new spaceman figure supplants him as top toy.";
  112.     films[2].runningTime = 81;
  113.     films[2].rating = FILM_RATING_G;
  114.    
  115.     films[3].id = 3;
  116.     films[3].name = "Silent Hill";
  117.     films[3].description = "A woman, Rose, goes in search for her adopted daughter within the confines of a strange, desolate town called Silent Hill.";
  118.     films[3].runningTime = 132;
  119.     films[3].rating = FILM_RATING_R;
  120.    
  121.     films[4].id = 4;
  122.     films[4].name = "Avatar";
  123.     films[4].description = "A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.";
  124.     films[4].runningTime = 162;
  125.     films[4].rating = FILM_RATING_PG_13;
  126.    
  127.     films[5].id = 5;
  128.     films[5].name = "The Incredibles";
  129.     films[5].description = "A family of undercover superheroes, while trying to live the quiet suburban life, are forced into action to save the world.";
  130.     films[5].runningTime = 116;
  131.     films[5].rating = FILM_RATING_PG;
  132.    
  133.     films[6].id = 6;
  134.     films[6].name = "Up";
  135.     films[6].description = "Seventy-eight year old Carl Fredricksen travels to Paradise Falls in his home equipped with balloons, inadvertently taking a young stowaway.";
  136.     films[6].runningTime = 96;
  137.     films[6].rating = FILM_RATING_PG;
  138.    
  139.     films[7].id = 7;
  140.     films[7].name = "Forrest Gump";
  141.     films[7].description = "The presidencies of Kennedy and Johnson, Vietnam, Watergate, and other history unfold through the perspective of an Alabama man with an IQ of 75.";
  142.     films[7].runningTime = 142;
  143.     films[7].rating = FILM_RATING_PG_13;
  144.    
  145.     films[8].id = 8;
  146.     films[8].name = "Jurassic Park";
  147.     films[8].description = "During a preview tour, a theme park suffers a major power breakdown that allows its cloned dinosaur exhibits to run amok.";
  148.     films[8].runningTime = 127;
  149.     films[8].rating = FILM_RATING_PG_13;
  150.    
  151.     films[9].id = 9;
  152.     films[9].name = "The Lion King";
  153.     films[9].description = "Lion cub and future king Simba searches for his identity. His eagerness to please others and penchant for testing his boundaries sometimes gets him into trouble.";
  154.     films[9].runningTime = 88;
  155.     films[9].rating = FILM_RATING_G;
  156.    
  157.     return films;
  158. }
  159.  
  160. //Sorts movies based on their run time
  161. vector <Film> selectionSort (vector <Film> &films){
  162.     int minIndex, minValue;
  163.    
  164.     for(int i = 0; i < SIZE-1; i++){
  165.         minIndex = i;
  166.         minValue = films[i].runningTime;
  167.         for(int j = i +1; j < SIZE; j++){
  168.             if (films[j].runningTime < films[i].runningTime){
  169.                 minValue = films[j].runningTime;
  170.                 minIndex = j;
  171.             }
  172.         }
  173.         swap(films[minIndex], films[i]);
  174.     }
  175.     return films;
  176. }
  177.  
  178. //returns the set of films that have a rating of the specified rating or less
  179. vector <Film> findFilmsByRating (int rating, vector <Film> &films){
  180.     int index = 0; //subscript to search vector
  181.    
  182.     while(index < SIZE){
  183.         if (films[index].rating <= rating){
  184.             printFilm(films[index]);
  185.         }
  186.         index++;
  187.     }
  188.     return films;
  189. }
  190.  
  191. //returns the set of films that have a rating of the specified rating or less and the specified running time or less
  192. vector <Film> findFilmsByRatingAndRunningTime (int rating, int runningTime, vector <Film> &films){
  193.     int index = 0; //subscript to search vector
  194.    
  195.     while(index < SIZE){
  196.         if (films[index].rating <= rating && films[index].runningTime <= runningTime){
  197.             printFilm(films[index]);
  198.         }
  199.         index++;
  200.     }
  201.     return films;
  202.    
  203. }
  204.  
  205. //prints the struct Film in a readable forma
  206. void printFilm(Film film){
  207.    
  208.     cout << "Film title          : " << film.name << endl;
  209.     cout << "Film description    : " << film.description << endl;
  210.     cout << "Film running time   : " << film.runningTime <<" minutes" << endl;
  211.     cout << "Film rating         : " << filmRatingToString(film.rating) << "\n"<< endl;
  212.    
  213. }
  214.  
  215. //prints a vector of structs in a readable format
  216. void printFilms(vector<Film> films){
  217.     for (int i = 0; i < SIZE; i++){
  218.         printFilm(films[i]);
  219.     }
  220.  
  221. }
RAW Paste Data
Top