Sinux1

PS9Q2.cpp

May 12th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6. struct Movie
  7. {
  8.     string name;
  9.     string year;
  10.     string genre;
  11. };
  12.  
  13. void find_movies_time_frame(string first, string last, string arg)
  14. {
  15.     Movie instance1;
  16.  
  17.     //step1
  18.     ifstream data_store;
  19.  
  20.     //step2
  21.     data_store.open("movie_database.txt");
  22.     if (!data_store)
  23.     {
  24.         cout << "Error loading file\n";
  25.         exit(0);
  26.     }
  27.     else
  28.     {
  29.  
  30.         //step3
  31.         while (!data_store.eof())
  32.         {
  33.            getline(data_store, instance1.name);
  34.            getline(data_store, instance1.year);
  35.            getline(data_store, instance1.genre);
  36.  
  37.             if (instance1.genre == arg && instance1.year >= first && instance1.year <= last)
  38.             {
  39.                 cout << instance1.name << " " << instance1.year << endl;
  40.             }
  41.  
  42.  
  43.         }
  44.  
  45.     }
  46.     //step4
  47.     data_store.close();
  48.     return;
  49. }
  50.  
  51.  
  52.  
  53. int main()
  54. {
  55.     const string genre = "Comedy";
  56.  
  57.     string year1, year2;
  58.  
  59.     cout << genre << " Movie Finder\n";
  60.     cout << "Enter beginning year\n";
  61.     cin >> year1;
  62.     cout << "Enter ending year\n";
  63.     cin >> year2;
  64.  
  65.  
  66.     find_movies_time_frame(year1, year2, genre);
  67.  
  68.  
  69.     return 0;
  70. }
Add Comment
Please, Sign In to add comment