Question: IN C++ Write a program that provides information about popular classic movies. An input file contains up to 20 lines. A typical line in the

IN C++

Write a program that provides information about popular classic movies.

An input file contains up to 20 lines. A typical line in the input file looks like this:

1936 1 6 San Francisco 

representing respectively: year, awards, nominations, and movie title. You may assume that the data in the input file are sorted by title. Display "Popular Classic Movies" on the first line as a title. Prompt the user to enter the input file's name. Read the list of movies into an array of Movie structures. Display the array of structures as shown below:

==> Movies Sorted by Title: 1937 Lost Horizon 1936 San Francisco 1939 The Wizard of Oz 

Change the binarySearch() function to search an array of structures. Change the searchTestDriver() function to call binarySearch() in a loop: prompt the user to enter a movie title such as San Francisco, then call binarySearch() to search for San Francisco. If found, display its related data as shown below:

San Francisco, 1936, 1, 6 

otherwise display an error message:

San Francisco not found! 

Change the improved version of the insertion sort algorithm to sort the array of Movie structures in descending order by year. When done sorting, show the sorted array to the screen as shown below

==> Movies Sorted by Year: 1939 The Wizard of Oz 1937 Lost Horizon 1936 San Francisco 

Sample Output:

Popular Classic Movies ==> Enter input file name: classic_movies.txt ==> Movies Sorted by Title: 1937 Lost Horizon 1936 San Francisco 1939 The Wizard of Oz ==> Search Movies: What movie are you looking for? San Francisco Found: San Francisco, 1936, 1, 6 Would you like to look up another movie(Y/N)? y What movie are you looking for? Titanic Titanic not found! Would you like to look up another movie(Y/N)? n ==> Movies Sorted by Year: 1939 The Wizard of Oz 1937 Lost Horizon 1936 San Francisco 

If the file size exceeds the array capacity display the file name and an error message as shown below, then terminate the program:

test.txt is too large. 

It the file name is incorrect, display the file name and an error message as shown below, then terminate the program:

Error opening abc.txt for reading.

Starting Code:

#include

using namespace std;

struct Movie { int year; int awards; int nominations; string title; };

// constants definitions const int MOVIES = 20; // maximum size of array

// function declaration void readMovies(string filename, Movie (&list)[MOVIES], const int MOVIES, int &noMovies); void printMovies(const Movie (&list)[MOVIES], int noMovies); void searchTestDriver(const Movie (&list)[MOVIES], int noMovies); void insertSort(Movie (&list)[MOVIES], int noMovies);

int main() { // array definition Movie list[MOVIES];

// other variables int noMovies; // actual size of array string filename;

// function calls cout << "Popular Classic Movies" << endl; cout << " ==> Enter input file name: "; getline(cin, filename); readMovies(filename, list, MOVIES, noMovies); cout << " ==> Movies Sorted by Title:" << endl; printMovies(list, noMovies); cout << " ==> Search Movies:" << endl; searchTestDriver(list, noMovies); insertSort(list, noMovies); cout << " ==> Movies Sorted by Year:" << endl; printMovies(list, noMovies); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!