Question: I need help finishing the below code in C++. There are 3 parts in the following program Labled FIXME which I need help on. All
I need help finishing the below code in C++. There are 3 parts in the following program Labled FIXME which I need help on. All the headers and the 3 FIXME's are in bold print. One is under Movie.h and the other two are under Movies.h. Thank you in advance for helping me.



/*
Title: Driver.cpp
Author:
Date: 12/04/2017
Purpose: To demonstrate the Movies, Movie, and Text structure code working
by allowing the user to add, save, delete, and edit movies to/from a library.
*/
#include "Movies.h"
#include "Movie.h"
#include "Text.h"
#include
using namespace std;
int main()
{
int menuChoice;
int movieChoice;
int maxMovies;
char filename[25];
//variables needed for adding a movie
int length, year, numOscars;
double numStars;
char tempString[100];
Text* title;
Text* genre;
Text* rating;
Movie* oneMovie;
cout
cin >> maxMovies;
while(maxMovies
{
cout
cin >> maxMovies;
}
Movies* movieLibrary = createMovies(maxMovies);
do
{
cout
cout
cout
cout
cout
cout
cout
cout
cout
cin >> menuChoice;
while(menuChoice 7)
{
cout
cout
cin >> menuChoice;
}
switch(menuChoice)
{
case 1: cout
cin >> filename;
readMoviesFromFile(filename, movieLibrary); //function is in Movies.cpp
break;
case 2: cout
cin >> filename;
saveToFile(filename, movieLibrary); //function is in Movies.cpp
break;
case 3: //add a movie
cin.ignore(); //remove the from the keyboard buffer
cout
cin.getline(tempString, 100);
title = createText(tempString);
cout
cin >> length;
cout
cin >> year;
cin.ignore();
cout
cin.getline(tempString, 100);
genre = createText(tempString);
cout
cin.getline(tempString, 100);
rating = createText(tempString);
cout
cin >> numOscars;
cout
cin >> numStars;
//create the movie
oneMovie = createMovie(title, length, year, genre, rating, numOscars, numStars);
//add the movie to the library
addMovieToArray(movieLibrary, oneMovie);
break;
case 4: //delete a movie
cout
displayMovieTitles(movieLibrary);
cout numMovies
cin >> movieChoice;
while(movieChoice movieLibrary->numMovies)
{
cout numMovies
cin >> movieChoice;
}
removeMovieFromArray(movieLibrary, movieChoice);
break;
case 5: //edit a movie
cout
displayMovieTitles(movieLibrary);
cout numMovies
cin >> movieChoice;
while(movieChoice movieLibrary->numMovies)
{
cout numMovies
cin >> movieChoice;
}
oneMovie = movieLibrary->moviesArray[movieChoice-1];
editMovie(oneMovie);
break;
case 6: //print all movies
if(movieLibrary->numMovies > 0)
displayMovies(movieLibrary);
else
cout
break;
case 7: //delete all movies
destroyMovies(movieLibrary);
break;
}
} while(menuChoice != 7);
cout
return 0;
}
/*
Title: Movie.cpp
Author:
Date: 12/04/2017
Purpose: Be able to create, manage, print & delete a single movie.
*/
#include "Movie.h"
#include "Text.h"
//FIXME Completed: add the overloaded createMovie function!****************************************************************
//FIXME Completed: add the editMovie function!*****************************************************************************
Movie* createMovie(Text* title, int length, int year, Text* genre, Text* rating, int oscarsWon, float imdbRating)
{
//dynamically allocate a new Movie
Movie* myMovie = new Movie;
//assign parameter data to structure memebers
myMovie->movieTitle = title;
myMovie->movieLength = length;
myMovie->movieYear = year;
myMovie->movieGenre = genre;
myMovie->movieRating = rating;
myMovie->movieOscars = oscarsWon;
myMovie->movieNumStars = imdbRating;
return myMovie;
}
void editMovie(Movie* myMovie)
{
int menuChoice;
do
{
cout
cout
cout
cout
cout
cout
cout
cout
cout
cin >> menuChoice;
switch (menuChoice)
{
case 1:
{
char *newTitle = new char;
cout movieTitle)->textArray;
cout
cin >> newTitle;
myMovie->movieTitle = createText(newTitle);
cout movieTitle)->textArray;
break;
}
case 2:
{
cout movieLength;
cout
cin >> myMovie->movieLength;
cout movieLength;
break;
}
case 3:
{
cout movieYear;
cout
cin >> myMovie->movieYear;
cout movieYear;
break;
}
case 4:
{
char *movieGenre = new char;
cout movieGenre)->textArray;
cout
cin >> movieGenre;
myMovie->movieGenre = createText(movieGenre);
cout movieGenre)->textArray;
break;
}
case 5:
{
char *rating = new char;
cout movieRating)->textArray;
cout
cin >> rating;
myMovie->movieRating = createText(rating);
cout movieRating)->textArray;
break;
}
case 6:
{
cout movieOscars;
cout
cin >> myMovie->movieOscars;
cout movieOscars;
break;
}
case 7:
{
cout movieNumStars;
cout
cin >> myMovie->movieNumStars;
cout movieNumStars;
break;
}
default:
{
cout
cout
cin >> menuChoice;
}
}
}
while (menuChoice 8);
}
void destroyMovie(Movie* myMovie)
{
destroyText(myMovie->movieTitle);
destroyText(myMovie->movieGenre);
destroyText(myMovie->movieRating);
delete myMovie;
}
void printMovieDetails(Movie* myMovie)
{
cout
cout
displayText(myMovie->movieTitle);
cout
cout movieLength
cout movieYear
cout
displayText(myMovie->movieGenre);
cout
cout
displayText(myMovie->movieRating);
cout
cout movieOscars
cout movieNumStars
}
void printMovieDetailsToFile(Movie* myMovie, ofstream &outFile)
{
char temp[1000];
strncpy(temp, getText(myMovie->movieTitle), 1000);
outFile
outFile movieLength
outFile movieYear
strncpy(temp, getText(myMovie->movieGenre), 1000);
outFile
strncpy(temp, getText(myMovie->movieRating), 1000);
outFile
outFile movieOscars
outFile movieNumStars
}
Text* getMovieTitle(Movie* myMovie)
{
return myMovie->movieTitle;
}
int getMovieLength(Movie* myMovie)
{
return myMovie->movieLength;
}
int getMovieYear(Movie* myMovie)
{
return myMovie->movieYear;
}
Text* getMovieGenre(Movie* myMovie)
{
return myMovie->movieGenre;
}
Text* getMovieRating(Movie* myMovie)
{
return myMovie->movieRating;
}
int getMovieOscars(Movie* myMovie)
{
return myMovie->movieOscars;
}
float getMovieNumStars(Movie* myMovie)
{
return myMovie->movieNumStars;
}
void setMovieTitle(Movie* myMovie, Text* title)
{
myMovie->movieTitle = title;
}
void setMovieLength(Movie* myMovie, int length)
{
myMovie->movieLength = length;
}
void setMovieYear(Movie* myMovie, int year)
{
myMovie->movieYear = year;
}
void setMovieGenre(Movie* myMovie, Text* genre)
{
myMovie->movieGenre = genre;
}
void setMovieRating(Movie* myMovie, Text* rating)
{
myMovie->movieRating = rating;
}
void setMovieOscars(Movie* myMovie, int oscars)
{
myMovie->movieOscars = oscars;
}
void setMovieNumStars(Movie* myMovie, int stars)
{
myMovie->movieNumStars = stars;
}
/*
Title: Movie.h
Author:
Date: 12/04/2017
Purpose: Be able to create, manage, print & delete a single movie.
*/
#ifndef MOVIE_H
#define MOVIE_H
#include "Text.h"
#include
#include
#include
#include
using namespace std;
struct Movie
{
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; /umber of oscars won (not nominations)
float movieNumStars; //taken from IMDB on 10 star scale
};
/*
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 dynamically create a new movie, assign parameter data to the structure,
and then return the pointer to the newly created Movie
*/
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 movie data. It
will show a menu that asks the user which piece of information they wish
to edit. Then displays the current value. Then, allows the user to enter
in a new value to overwrite the old value. Then it will show the menu again
until the user choose #8, which means they are done editing.
*/
void editMovie(Movie* myMovie);
/*
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(Movie*);
/*
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(Movie*);
/*
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.
*/
//FIXME: add function prototype of printMovieDetailsToFile here!!***********************************************
//function prototypes to get the information out of the structure variable
Text* getMovieTitle(Movie*);
int getMovieLength(Movie*);
int getMovieYear(Movie*);
Text* getMovieGenre(Movie*);
Text* getMovieRating(Movie*);
int getMovieOscars(Movie*);
float getMovieNumStars(Movie*);
//function prototypes to set or change the information in the structure variable
void setMovieTitle(Movie*, Text*);
void setMovieLength(Movie*, int);
void setMovieYear(Movie*, int);
void setMovieGenre(Movie*, Text*);
void setMovieRating(Movie*, Text*);
void setMovieOscars(Movie*, int);
void setMovieNumStars(Movie*, int);
#endif
/*
Title: Movies.cpp
Author:
Date: 12/04/2017
Purpose: Be able to create, manage, print, save & delete a movie library
*/
#include "Movies.h"
#include "Movie.h"
//FIXME Completed : add the removeMovieFromArray function!****************************************************************
void removeMovieFromArray(Movies* myMovies, int movieElementToBeRemoved)
{
Movie *movieToBeRemoved = myMovies->moviesArray[movieElementToBeRemoved - 1];
for (int i = movieElementToBeRemoved - 1; i numMovies - 1 ; i++)
{
myMovies->moviesArray[i] = myMovies->moviesArray[i+1];
}
if (movieElementToBeRemoved == 1)
myMovies->moviesArray += 1;
free(movieToBeRemoved);
myMovies->numMovies--;
}
//FIXME Completed: add the displayMovieTitles function!******************************************************************
void displayMovieTitles(Movies* movies)
{
for (int i = 0; i numMovies; i++)
{
cout moviesArray[i]->movieTitle)->textArray
}
}
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 numMovies; x++)
{
newMoviesArray[x] = myMovies->moviesArray[x];
}
myMovies->moviesArray = newMoviesArray;
myMovies->maxMovies = max;
}
bool addMovieToArray(Movies* myMovies, Movie* oneMovie)
{
bool wasAbleToAddMovie = false;
if(myMovies->numMovies == myMovies->maxMovies)
resizeMovieArray(myMovies); //increase size by 2
myMovies->moviesArray[myMovies->numMovies] = oneMovie;
wasAbleToAddMovie = true;
(myMovies->numMovies)++;
return wasAbleToAddMovie;
}
void destroyMovies(Movies* myMovies)
{
//delete each movie
for(int x=0; xnumMovies; x++)
{
//delete myMovies->moviesArray[x];
destroyMovie(myMovies->moviesArray[x]);
}
//delete movies array
delete [] myMovies->moviesArray;
//delete myMovies
delete myMovies;
}
void displayMovies(Movies* myMovies)
{
for(int x=0; x numMovies); x++)
{
cout
printMovieDetails(myMovies->moviesArray[x]); //function is in Movie.cpp
}
}
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; /umber 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);
/ow add this movie to the library
if(addMovieToArray(myMovies, oneMovie))
{
cout
displayText(title);
cout
}
else
{
cout
cout
displayText(title);
cout
}
inFile.getline(temp, 100); //read in the next movie title if there is one
numMoviesReadFromFile++;
}
cout
}
else
{
cout
}
}
void saveToFile(char *filename, Movies* myMovies)
{
ofstream outFile;
outFile.open(filename);
for(int x=0; x numMovies); x++)
{
printMovieDetailsToFile(myMovies->moviesArray[x], outFile); //function in Movies.cpp
}
outFile.close();
cout
}
/*
Title: Movies.h
Author:
Date: 12/04/2017
Purpose: Be able to create, manage, print, save & delete a movie library
*/
#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)
2) The single movie that needs to be added to the library
Returns: A boolean indicating if the movie was able to be added or not
Purpose: This function should be called when you need to add a single movie to the
movie library.
*/
//FIXME: put the function prototype for addMovieToArray here!!***************************************************
/*
Function name: destroyMovies
Parameters: 1) The movies structure (which contains the movie library)
Returns: nothing (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: nothing (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: nothing (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: nothing (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
*/
//FIXME: Put the function prototype of readMoviesFromFile here!**************************************************
/*
Function name: removeMovieFromArray
Parameters: 1) The movies structure (which contains the movie library)
2) The array element of the movie that needs to be removed
Returns: nothing (void)
Purpose: This function should be called when the user wants to remove one single movie
from the movie library. The movie to be removed must be identified before
calling this function because this function eeds the element number (not
the subscript/index number) of the movie to be removed.
*/
void removeMovieFromArray(Movies* myMovies, int movieElementToBeRemoved);
/*
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: nothing (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);
#endif
/*
Title: Text.cpp
Author:
Date: 11/7/2017
About: A structure version of the C++ string class
*/
#include "Text.h"
using namespace std;
Text* createText(const char* text)
{
//dynamically allocate a new Text
Text* myText = new Text;
//get the length of the string passed to this function
myText->textLength = strlen(text);
//dynamically allocate a new character array
//the line below wont work because I need textArray to be const but I can't dynamically allocate a const char array
//myText->textArray = new char[(myText->textLength)+1];
char* tempTextArray = new char[(myText->textLength)+1];
/*
Now put text inside of tempTextArray
I can either use the cstring function called strcpy OR
I could have created a for loop and copy one character at a time.
*/
strcpy(tempTextArray, text);
//put the text sent to this function into the newly created array
//I can do assignment because it is assigning a pointer (not a cstring)
myText->textArray = tempTextArray;
return myText;
}
void destroyText(Text* myText)
{
//create a temporary c-string to make the syntax easier to delete the array
const char* tempTextArray = myText->textArray;
//delete the character array (c-string), which is inside the structure
delete [] tempTextArray;
//delete the entire structure
delete myText;
}
void displayText(Text* myText)
{
//print out the c-string
cout textArray;
}
const char* getText(Text* myText)
{
return myText->textArray;
}
int getLength(Text* myText)
{
return myText->textLength;
}
/*
Title: Text.h
Author:
Date: 12/04/2017
About: A structure version of the C++ string class
*/
#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
DESCRIPTION: You are completing a program for people who love movies and who own many of them. You are helping these people by organizing their movies in a movie database. Users should be able to read movie data from a file, save movies to a file, add a movie, delete a movie, edit a movie, print all movies, and delete all movies. WHAT'S NEW IN PROGRAM 4 The biggest difference with this program besides working with pointers is that I am providing most of the code for you. This is a humongous program and there is no way that most students could write the entire program from scratch in this little amount of time. Therefore, you will have to understand the code I give you and then add the code that I specify in this document. You should not modify my code AT ALL unless specified in this document. It is an important programming skill to be able to take someone else's code and understand it and expand on it. MULTIPLE FILES This program contains multiple files as described below Text.h header file for a structure version of the C++ String Class [do not modify this code] Text.cpp source file containing function definitions required for the structure version of the C++ String Class [do not modify this code] Movie.h - header file for a Movie structure and functions that can be performed with the Movie structure Movie.cpp source file containing the function definitions required for the Movie structure Movies.h - header file for a Movies structure and functions that can be performed with the Movies structure Movies.cpp source file containing the function definitions required for the Movies structure. Makefile provided for you [if you do not have Windows you will not be able to use this] runProgram.bat provided for you [if you do not have Windows you will not be able to use this] crockett-movie-data.txt-text file containing data on several movies that you can use to test your program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
