Question: WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include movies.h #include Movie.h Movies

WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM

MOVIES.CPP

#include "movies.h"

#include "Movie.h"

Movies *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 Movies::resizeMovieArray() { int max = 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 < numMovies; x++) { newMoviesArray[x] = moviesArray[x]; } //delete the original array from memory delete[] moviesArray; moviesArray = newMoviesArray; maxMovies = max; } void Movies::addMovieToArray() { 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 (numMovies == maxMovies) resizeMovieArray(); //increase size by 2 moviesArray[numMovies] = oneMovie; numMovies++; } void Movies::removeMovieFromArray() { int movieChoice; cout << numMovies << endl << endl; //delete a movie if there is more than one movie in the library. if (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(); cout << " Choose a movie to remove between 1 & " << numMovies << ": "; cin >> movieChoice; while (movieChoice < 1 || movieChoice > numMovies) { cout << " Oops! You must enter a number between 1 & " << numMovies << ": "; cin >> movieChoice; } int movieIndexToBeRemoved = movieChoice - 1; Text *movieTitle; movieTitle = moviesArray[movieIndexToBeRemoved]->movieTitle; //destroy this movie destroyMovie(moviesArray[movieIndexToBeRemoved]); int numElementsToMoveBack = numMovies - 1; for (int x = movieIndexToBeRemoved; x < numElementsToMoveBack; x++) { moviesArray[x] = moviesArray[x + 1]; //move array elements! } //set the last movie to a null pointer moviesArray[numElementsToMoveBack] = NULL; //decrement the current number of movies (numMovies)--; cout << " The movie \""; displayText(movieTitle); cout << "\" has been successfully deleted. "; } } void Movies::editMovieInArray() { int movieChoice; cout << " Choose from the following movies to edit: "; displayMovieTitles(); cout << " Choose a movie to remove between 1 & " << numMovies << ": "; cin >> movieChoice; while (movieChoice < 1 || movieChoice > numMovies) { cout << " Oops! You must enter a number between 1 & " << numMovies << ": "; cin >> movieChoice; } Movie *oneMovie = moviesArray[movieChoice - 1]; editMovie(); } void Movies::destroyMovies() { //delete each movie for (int x = 0; x < numMovies; x++) { //delete myMovies->moviesArray[x]; destroyMovie(moviesArray[x]); } //delete movies array delete[] moviesArray; //delete myMovies delete myMovies; } void Movies::displayMovies() { if (numMovies > 0) { for (int x = 0; x < (numMovies); x++) { cout << endl << right << setw(50) << "----------MOVIE " << (x + 1) << "----------"; printMovieDetails(moviesArray[x]); //function is in Movie.cpp } } else cout << " There are no movies in your library yet."; } void Movies::displayMovieTitles() { Text *movieTitle; for (int x = 0; x < (numMovies); x++) { cout << " MOVIE " << (x + 1) << ": "; movieTitle = moviesArray[x]->movieTitle; displayText(movieTitle); } } void Movies::readMoviesFromFile(char *filename) { 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 (numMovies == maxMovies) resizeMovieArray(); //increase size by 2 moviesArray[numMovies] = oneMovie; 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 Movies::saveToFile(char *filename) { ofstream outFile; outFile.open(filename); for (int x = 0; x < (numMovies); x++) { printMovieDetailsToFile(moviesArray[x], outFile); //function in Movies.cpp } outFile.close(); cout << " All movies in your library have been printed to " << filename << endl; }

MOVIES.H

#ifndef MOVIES_H #define MOVIES_H #include "Movie.h" #include #include #include using namespace std; class Movies { private: 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 public: /* 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(); /* 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(); /* 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(); /* 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(); /* 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(); /* 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); /* 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(); /* 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); /* 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(); }; #endif

MOVIE.H

#ifndef MOVIE_H #define MOVIE_H #include "Text.h" #include #include #include #include using namespace std; class Movie { private: Text *movieTitle; //title of movie int movieLength; //length of movie in minutes int movieYear; //year released Text *movieGenre; //comedy, horror, sci-fi, fantasy, romance, thriller, drama, action, biography Text *movieRating; //G, PG, PG-13, R, MA int movieOscars; //number of oscars won float movieNumStars; //taken from IMDB on 10 star scale public: /* Function name: createMovie (overloaded function) Parameters: 1) A pointer to a Text variable, containing a c-string and the length of the string. 2) An integer containing the length of the movie Returns: A pointer to a new Movie structure Purpose: This function should be called when only the title of the movie and the length of the movie is known and it will create a new movie with this information. */ Movie *createMovie(Text *, int); /* Function name: createMovie (overloaded function) Parameters: 1) A pointer to a Text variable, containing the title of the movie 2) An integer containing the length of the movie 3) An integer containing the year the movie was released 4) A pointer to a Text variable, containing the genre of the movie 5) A pointer to a Text variable, containing the rating of the movie 6) An integer containing the number of oscars the movie won 7) A float containing the IMDB rating of the movie (out of 10 stars) Returns: A pointer to a new Movie structure Purpose: This function should be called when all movie information is known and it will create a new movie with this information. */ Movie *createMovie(Text *, int, int, Text *, Text *, int, float); /* Function name: editMovie Parameters: A pointer to a movie structure Returns: nothing (void) Purpose: This function should be called when the user wants to edit a single movie's data */ void editMovie(); /* Function name: destroyMovie Parameters: A pointer to a movie structure Returns: nothing (void) Purpose: This function should be called when there is no longer need for the movie in the database (like when removing or deleting a movie). */ void destroyMovie(); /* Function name: printMovieDetails Parameters: A pointer to a movie structure Returns: nothing (void) Purpose: This function should be called when the user wants to print ALL the movie information to the screen. */ void printMovieDetails(); /* Function name: printMovieDetailsToFile Parameters: A pointer to a movie structure, a file stream object (sent by reference) Returns: nothing (void) Purpose: This function should be called when the user wants to print ALL the movie information to the file. */ void printMovieDetailsToFile(ofstream &outFile); void printMovieDetailsToFile(ofstream &outFile); void setMovieNumStars(float stars); void setMovieOscars(int oscars); void setMovieRating(Text *rating); void setMovieGenre(Text *genre); void setMovieYear(int year); void setMovieLength(int length); void setMovieTitle(Text *title); float getMovieNumStars(); int getMovieOscars(); Text getMovieRating(); Text * getMovieGenre(); Text *getMovieTitle(); int getMovieLength(); int getMovieYear(); }; #endif

TEXT.H #ifndef TEXT_H

#define TEXT_H

#include #include #include using namespace std;

struct Text { const char* textArray; int textLength; }

/* Function Name: createText() Parameters: Send a pointer to a constant character array or a string literal to this function Returns: A pointer to a new Text variable, which contains the c-string & the length of the string Purpose: To create a new Text variable */ Text* createText(const char*);

/* Function Name: destroyText() Parameters: Send a pointer to a Text variable, which contains a c-string & length of the string Returns: nothing (void) Purpose: release dynamically allocated memory that the pointer is pointing to. */ void destroyText(Text*);

/* Function Name: displayText() Parameters: Send a pointer to a Text variable, which contains a c-string & length of the string Returns: nothing (void) Purpose: prints out the string (character array) */ void displayText(Text*);

/* Function Name: getText() Parameters: Send a pointer to a Text variable, which contains a c-string & length of the string Returns: pointer to a constant character array */ const char* getText(Text*);

/* Function Name: getLength() Parameters: Send a pointer to a Text variable, which contains a c-string & length of the string Returns: the length of the string */ int getLength(Text*);

#endif

DRIVER.CPP

#include "Movies.h" #include "Movie.h" #include "Text.h" #include using namespace std;

int main() { int menuChoice; int maxMovies; char filename[25]; cout << " What is the maximum number of movies you can have in your library? "; cin >> maxMovies; while(maxMovies <= 0) { cout << " You have to have at least one movie in your library. "; cout << "What is the maximum number of movies you can have in your library. "; cin >> maxMovies; } Movies* movieLibrary = createMovies(maxMovies); do { cout << " What would you like to do? "; cout << "1. Read movies from file. "; cout << "2. Save movies to a file. "; cout << "3. Add a movie. "; cout << "4. Delete a movie. "; cout << "5. Edit a movie. "; cout << "6. Print all movies. "; cout << "7. Delete ALL movies and end the program. "; cout << "CHOOSE 1-7: "; cin >> menuChoice; while(menuChoice < 1 || menuChoice > 7) { cout << "That is not a valid choice. "; cout << "CHOOSE 1-7: "; cin >> menuChoice; } switch(menuChoice) { case 1: cout << " What is the name of the file? (example.txt): "; cin >> filename; readMoviesFromFile(filename, movieLibrary); //function is in Movies.cpp break; case 2: cout << " What do you want to name the file? (example.txt): "; cin >> filename; saveToFile(filename, movieLibrary); //function is in Movies.cpp break; case 3: //add a movie addMovieToArray(movieLibrary); break; case 4: //remove a movie removeMovieFromArray(movieLibrary); break; case 5: //edit a movie editMovieInArray(movieLibrary); break; case 6: //print all movies displayMovies(movieLibrary); break; case 7: //delete all movies destroyMovies(movieLibrary); break; } } while(menuChoice != 7); cout << " GOODBYE! "; 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!