Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- struct Movie
- {
- string name;
- int year;
- string genre;
- };
- void find_sim_movies(string title, Movie arr[],int size)
- {
- for (int subscript = 0; subscript < size; subscript++)
- {
- if (arr[subscript].name == title)
- {
- cout << "The movies just before " << title << " are:\n";
- cout << arr[subscript - 3].name << endl;
- cout << arr[subscript - 2].name << endl;
- cout << arr[subscript - 1].name << endl;
- }
- }
- return;
- }
- void load_movie_list(Movie arr[])
- {
- //step1
- ifstream data_store;
- //step2
- data_store.open("movie_database.txt");
- if (!data_store)
- {
- cout << "Error loading file\n";
- exit(0);
- }
- else
- {
- int subscript = 0;
- //step3
- while (!data_store.eof())
- {
- string name, year, genre;
- getline(data_store, name);
- getline(data_store, year);
- getline(data_store, genre);
- arr[subscript].name = name;
- arr[subscript].year = atoi(year.c_str());
- arr[subscript].genre = genre;
- subscript++;
- }
- }
- //step4
- data_store.close();
- return;
- }
- int main()
- {
- int NUM_MOVIES = 85134;
- string movie_name;
- Movie movie_list[NUM_MOVIES];
- cout << "Similar Title Finder\n";
- cout << "Enter a movie name\n";
- getline(cin, movie_name);
- load_movie_list(movie_list);
- find_sim_movies(movie_name, movie_list, NUM_MOVIES);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement