Question: need a movies.h and movies.cpp program fomr a structure program converted to a class program titled moviesh and movies.cpp here is the .h structure file

need a movies.h and movies.cpp program fomr a structure program converted to a class program titled moviesh and movies.cpp

here is the .h structure file

#ifndef MOVIES_H #define MOVIES_H

#include "Movie.h" #include #include #include

using namespace std;

struct Movies { Movie** moviesArray; //an array of pointers - each pointer points to a single Movie int maxMovies; //maximum number of elements in the array int numMovies; //current number of movies in the array };

/* Function name: createMovies Parameters: An integer containing the maximum size of the movie library Returns: A pointer to a new Movies structure Purpose: This function should be called when the user needs to create a library of movies. The function will dynamically allocate a movies array based on the maximum size and will also set the current number of movies to zero. */ Movies* createMovies(int);

/* Function name: addMovieToArray Parameters: 1) The movies structure (which contains the movie library) Returns: none Purpose: This function should be called when you need to add a single movie to the movie library. */ void addMovieToArray(Movies*);

/* Function name: editMovieInArray Parameters: The movies structure (which contains the movie library) Returns: none Purpose: This function should be called when you need to edit a movie in the array */ void editMovieInArray(Movies*);

/* Function name: destroyMovies Parameters: 1) The movies structure (which contains the movie library) Returns: none (void) Purpose: This function should be called when you need to remove all the single movies in the movie library as well as the movie library. This releases all the dynamically allocated space in memory. */ void destroyMovies(Movies*);

/* Function name: displayMovies Parameters: 1) The movies structure (which contains the movie library) Returns: none (void) Purpose: This function should be called when the user wants to have all the movies in the library printed to the screen. */ void displayMovies(Movies*);

/* Function name: displayMovieTitles Parameters: 1) The movies structure (which contains the movie library) Returns: none (void) Purpose: This function should be called when you want to print only the movie titles out of the movie library */ void displayMovieTitles(Movies*);

/* Function name: readMoviesFromFile Parameters: 1) A pointer to a character (c-string or string literal argument) containing the filename 2) The movies structure (which contains the movie library) Returns: none (void) Purpose: This function should be called when the user wants to read movie data from a file and add the movies to the movie library. The file must have data in the following order: title, length, year, genre, rating, num oscars won, star rating */ void readMoviesFromFile(char* filename, Movies* myMovies);

/* Function name: removeMovieFromArray Parameters: The movies structure (which contains the movie library) Returns: none (void) Purpose: This function should be called when the user wants to remove one single movie from the movie library. The function will list all the movie names and allow the user to select the movie that they wish to remove. Then this function removes the movie. */ void removeMovieFromArray(Movies* myMovies);

/* Function name: saveToFile Parameters: 1) A pointer to a character (c-string or string literal argument) containing the filename 2) The movies structure (which contains the movie library) Returns: none (void) Purpose: This function should be called when the user wants to print all the movie data from the movie library to a file. The data is printed in the following order (one piece of data per line): title, length, year, genre, rating, num oscars won, star rating */ void saveToFile(char *filename, Movies* myMovies);

/* Function name: resizeMovieArray Parameters: The movies structure (which contains the movie library) Returns: none (void) Purpose: This function is called by addMovieToArray when the array size is not big enough to hold a new movie that needs to be added. The function makes the array twice as big as it currently is and then moves all the movie pointers to this new array. */ void resizeMovieArray(Movies* myMovies);

#endif

here is the structure .cpp file

#include "Movies.h" #include "Movie.h"

Movies* createMovies(int max) { //dynamically create a new Movies structure Movies* myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie*[max]; return myMovies; }

void resizeMovieArray(Movies* myMovies) { int max = myMovies->maxMovies * 2; //increase size by 2 //make an array that is twice as big as the one I've currently got Movie** newMoviesArray = new Movie*[max]; for(int x = 0; x < myMovies->numMovies; x++) { newMoviesArray[x] = myMovies->moviesArray[x]; } //delete the original array from memory delete [] myMovies->moviesArray; myMovies->moviesArray = newMoviesArray; myMovies->maxMovies = max; }

void addMovieToArray(Movies* myMovies) { char tempString[100]; int length, year, numOscars; double numStars; Text* title; Text* genre; Text* rating; //get movie data from the user cin.ignore(); //remove the from the keyboard buffer cout << " MOVIE TITLE: "; cin.getline(tempString, 100); title = createText(tempString); cout << " MOVIE LENGTH (in minutes): "; cin >> length; cout << " MOVIE YEAR: "; cin >> year; cin.ignore(); cout << " MOVIE GENRE: "; cin.getline(tempString, 100); genre = createText(tempString); cout << " MOVIE RATING: "; cin.getline(tempString, 100); rating = createText(tempString); cout << " NUMBER OF OSCARS WON: "; cin >> numOscars; cout << " STAR RATING (out of 10): "; cin >> numStars; //create the movie Movie* oneMovie = createMovie(title, length, year, genre, rating, numOscars, numStars); //add the movie to the library if(myMovies->numMovies == myMovies->maxMovies) resizeMovieArray(myMovies); //increase size by 2

myMovies->moviesArray[myMovies->numMovies] = oneMovie;

(myMovies->numMovies)++; }

void removeMovieFromArray(Movies* myMovies) { int movieChoice; cout << myMovies->numMovies << endl << endl; //delete a movie if there is more than one movie in the library. if((myMovies->numMovies) <= 1) { cout << endl << "There must always be at least one movie in your library. You can\'t"; cout << " remove any movies right now or you will have no movies in your library. "; } else { cout << " Choose from the following movies to remove: "; displayMovieTitles(myMovies); cout << " Choose a movie to remove between 1 & " << myMovies->numMovies << ": "; cin >> movieChoice; while(movieChoice < 1 || movieChoice > myMovies->numMovies) { cout << " Oops! You must enter a number between 1 & " << myMovies->numMovies << ": "; cin >> movieChoice; } int movieIndexToBeRemoved = movieChoice-1; Text* movieTitle; movieTitle = myMovies->moviesArray[movieIndexToBeRemoved]->movieTitle; //destroy this movie destroyMovie(myMovies->moviesArray[movieIndexToBeRemoved]); int numElementsToMoveBack = (myMovies->numMovies) - 1; for(int x = movieIndexToBeRemoved; x < numElementsToMoveBack; x++) { myMovies->moviesArray[x] = myMovies->moviesArray[x+1]; //move array elements! } //set the last movie to a null pointer myMovies->moviesArray[numElementsToMoveBack] = NULL; //decrement the current number of movies (myMovies->numMovies)--; cout << " The movie \""; displayText(movieTitle); cout << "\" has been successfully deleted. "; } }

void editMovieInArray(Movies* myMovies) { int movieChoice; cout << " Choose from the following movies to edit: "; displayMovieTitles(myMovies); cout << " Choose a movie to remove between 1 & " << myMovies->numMovies << ": "; cin >> movieChoice; while(movieChoice < 1 || movieChoice > myMovies->numMovies) { cout << " Oops! You must enter a number between 1 & " << myMovies->numMovies << ": "; cin >> movieChoice; } Movie* oneMovie = myMovies->moviesArray[movieChoice-1]; editMovie(oneMovie); }

void destroyMovies(Movies* myMovies) { //delete each movie for(int x=0; x< myMovies->numMovies; x++) { //delete myMovies->moviesArray[x]; destroyMovie(myMovies->moviesArray[x]); } //delete movies array delete [] myMovies->moviesArray; //delete myMovies delete myMovies; }

void displayMovies(Movies* myMovies) { if(myMovies->numMovies > 0) { for(int x=0; x < (myMovies->numMovies); x++) { cout << endl << right << setw(50) << "----------MOVIE " << (x+1) << "----------"; printMovieDetails(myMovies->moviesArray[x]); //function is in Movie.cpp } } else cout << " There are no movies in your library yet."; }

void displayMovieTitles(Movies* myMovies) { Text* movieTitle; for(int x=0; x < (myMovies->numMovies); x++) { cout << " MOVIE " << (x+1) <<": "; movieTitle = myMovies->moviesArray[x]->movieTitle; displayText(movieTitle); } }

void readMoviesFromFile(char *filename, Movies* myMovies) { int numMoviesReadFromFile = 0; ifstream inFile; char temp[100]; Text* title; Text* genre; Text* rating; Movie* oneMovie; int movieLength; //length of movie in minutes int movieYear; //year released int movieOscars; //number of oscars won float movieNumStars; //from IMDB out of 10 stars inFile.open(filename); if(inFile.good()) { inFile.getline(temp, 100); while(!inFile.eof()) { title = createText(temp);//create a text for the movie title inFile >> movieLength; inFile >> movieYear; inFile.ignore(); //get rid of in the inFile buffer inFile.getline(temp, 100); //read in genre genre = createText(temp); //create a text for genre inFile.getline(temp, 100); //read in rating rating = createText(temp); //create a text for rating inFile >> movieOscars; inFile >> movieNumStars; inFile.ignore(); //get rid of in the inFile buffer //one movie has been read from the file. Now create a movie object oneMovie = createMovie(title, movieLength, movieYear, genre, rating, movieOscars, movieNumStars); //now add this movie to the library if(myMovies->numMovies == myMovies->maxMovies) resizeMovieArray(myMovies); //increase size by 2 myMovies->moviesArray[myMovies->numMovies] = oneMovie; (myMovies->numMovies)++; //confirm addition to the user cout << endl; displayText(title); cout << " was added to the movie library! "; inFile.getline(temp, 100); //read in the next movie title if there is one numMoviesReadFromFile++; } cout << " " << numMoviesReadFromFile << " movies were read from the file and added to your movie library. "; } else { cout << " Sorry, I was unable to open the file. "; } }

void saveToFile(char *filename, Movies* myMovies) { ofstream outFile; outFile.open(filename); for(int x=0; x < (myMovies->numMovies); x++) { printMovieDetailsToFile(myMovies->moviesArray[x], outFile); //function in Movies.cpp } outFile.close(); cout << " All movies in your library have been printed to " << filename << endl; }

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!