Question: write C++ a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures. Use the

write C++ a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures. Use the "Sample program that processes the file" provided to help you. It is a simple program that reads the content of the file and prints it on the screen. The purpose is for you to see how to define a structure, a vector of structures and populate it with the data from a file. Please, note that the sample program is using a single structure variable m, but in your lab you will need a vector of structures to hold all the movies in memory. In lab1, you defined a vector of , now you need to replace int with the structure name.

It is ok to define the structure in the global scope. Remember that the structure is a type and you will need that type in the functions' parameters, but all variables should be local.

As you read each line from the file into a structure variable, add the data to the vector by calling function push_back.

After the program reads the data from the file, have your program give the user options to see the movies on the screen sorted by one of the options: title, director, year released, genre or running time. Also add an option to quit.

Use the sort function (#include ) to sort the requested data.

sort (myMovies.begin(), myMovies.end(), compareByTitle);

sort will use the function that you provide to sort the data. You will need five different compare functions, because there are five different fields. If the user asks to see the information sorted by title, you need to call sort passing compareByTitle. If he/she asks for the movies sorted by director, you will need to call sort passing compareByDirector, and so forth. Define one compare function for each option.

This is how function compareByTitle should look like:

bool compareByTitle(Movie m1, Movie m2) { return m1.title < m2.title) }

It will sort the vector by comparing the titles of each two elements in the vector.

After sorting, you should display all the information of each movie in table format. No matter how the data is sorted, you should print all the fields. It is best to define a function that prints the whole vector. Print a header like the following and then all the data that is in the vector, one movie per line.

Title Director Genre Year Released Duration

------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------

Structure of your program:

Open file and read data into vector of structures

repeat {

display menu of options

sort the data according to option chosen by user

print sorted vector

} until the user wants to quit.

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!