Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will extend your lab 1 to work with the whole movie information, not just the title. Your program will use the same input file,

You will extend your lab 1 to work with the whole movie information, not just the title. Your program will use the same input file, but this time you will define a structure to receive the title, director, genre, year released and running time. You can use the same method that you learned to strip the movie title to get the other parts. Instead of just a vector of strings (title), you will now need a vector of structures. Each element in the vector will have the movie's title, director, genre, year released and running time. Your program needs to be able to sort the vector by author, director or genre, and print the movies from a specific year. For example, I must be able to ask your program to print all the movies from 2000 sorted by genre.

Detailed specifications:

  • Define a structure with fields to store each part of the movie information: title, director, genre, year released, running time. The structure can be defined in the global scope as it is not a variable. A structure is a type.
  • Declare a variable, whose type is the structure, to receive the movie info, and also a vector of structures that will store all the movies. Remember that variables should not be global.
  • Read the each line of the file the same way you did before, making it a string stream, but now you will need to call getline on the stringstream repeatedly to get each part following the title. After populating the structure variable with the movie info, push it into the vector.
  • Design an interface to let the user of your program choose which field they want to see the movies sorted by (title, author or genre). Therefore you will need to define three different compare functions to pass to sort. Here are examples of how you would call sort with different compare functions:

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

sort (movies.begin(), movie.end(), compareByDirector);

sort (movies.begin(), movie.end(), compareByGenre);

sort will use the function that you provide to sort the data.

This is how function compareByTitle should look like, assuming Movie is the name of your structure:

bool compareByTitle(Movie movie1, Movie movie2) { return movie1.title < movie2.title) }

Display the movies sorted by the field that the user chooses and filtered by a specific year. You should display ALL fields no matter how the data is sorted.

I expect that you split your program in several functions, instead of having one big main function. Define separate functions to:

  • Read the data from the file and populate the vector. Notice that vectors are not arrays and need to be passed by reference.
  • Have an interface with the user asking which fields should be used for sorting and call sort with the appropriate compare function.
  • Print the movie info on the screen filtered by a specific year.

Include your program's output as a comment at the end of your source code.

Step by Step Solution

3.46 Rating (169 Votes )

There are 3 Steps involved in it

Step: 1

C program to create a structure of movies and create a vector of movies populated from a file and so... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Financial Management

Authors: Cheol S. Eun, Bruce G.Resnick

6th Edition

71316973, 978-0071316972, 78034655, 978-0078034657

More Books

Students also viewed these Finance questions

Question

Differentiate the function. y = tan[ln(ax + b)]

Answered: 1 week ago