The readMovies() function will fill an array of Movie objects. Note this is a standalone function rather than a class member function.

This function should:

  • Have four parameters in this order:

    • string fileName: the name of the file to be read.

    • Movie movies[]: array of Movie objects.

    • int numMoviesStored: the number of movies currently stored in the array. You should assume this is the correct number of actual elements in the array.

    • int movieArrSize: capacity of the movie array. The default value for this is 100.

  • Use ifstream and getline to read data from the file, creating a new Movie object for each line, and placing the object into the Movie array.

  • Empty lines should not be added to the array. Assume that movie titles can have spaces in them.

  • Hint: You can use the split() function from Homework 5 with a comma (,) as the delimiter.

  • The function behavior should match the following scenarios:

    • If numMoviesStored is equal to movieArrSize, return -2.
    • If the file is not opened successfully, return -1.
      • The priority of the return code -2 is higher than -1, i.e., in cases when numMoviesStored is equal to movieArrSize and the file cannot be opened, the function should return -2.
    • While numMoviesStored is smaller than movieArrSize, keep the existing elements in the movies array, then read data from the file and add (append) the data to the array. The number of movies stored in the array cannot exceed the size of the array.
    • Returns the total number of movies in the system, as an integer.

Public Answer

T4SAPY The First Answerer