Question

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

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 \n from the keyboard buffer
cout << "\n\nMOVIE TITLE: ";
cin.getline(tempString, 100);
title = createText(tempString);
cout << "\nMOVIE LENGTH (in minutes): ";
cin >> length;
cout << "\nMOVIE YEAR: ";
cin >> year;
cin.ignore();
cout << "\nMOVIE GENRE: ";
cin.getline(tempString, 100);
genre = createText(tempString);
cout << "\nMOVIE RATING: ";
cin.getline(tempString, 100);
rating = createText(tempString);
cout << "\nNUMBER OF OSCARS WON: ";
cin >> numOscars;
cout << "\nSTAR 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.\n";
}
else
{
cout << "\n\nChoose from the following movies to remove:\n";
displayMovieTitles();
cout << "\nChoose a movie to remove between 1 & " << numMovies << ": ";
cin >> movieChoice;
while (movieChoice < 1 || movieChoice > numMovies)
{
cout << "\nOops! 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 << "\n\nThe movie \"";
displayText(movieTitle);
cout << "\" has been successfully deleted.\n";
}
}
void Movies::editMovieInArray()
{
int movieChoice;
cout << "\n\nChoose from the following movies to edit:\n";
displayMovieTitles();
cout << "\nChoose a movie to remove between 1 & " << numMovies << ": ";
cin >> movieChoice;
while (movieChoice < 1 || movieChoice > numMovies)
{
cout << "\nOops! 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 << "\nThere are no movies in your library yet.";
}
void Movies::displayMovieTitles()
{
Text *movieTitle;
for (int x = 0; x < (numMovies); x++)
{
cout << "\nMOVIE " << (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 \n 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 \n 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!\n";
inFile.getline(temp, 100); //read in the next movie title if there is one
numMoviesReadFromFile++;
}
cout << "\n\n"
<< numMoviesReadFromFile << " movies were read from the file and added to your movie library.\n\n";
}
else
{
cout << "\n\nSorry, I was unable to open the file.\n";
}
}
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 << "\n\nAll 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 <iostream>
using namespace std;

int main()
{
int menuChoice;
int maxMovies;
char filename[25];

cout << "\n\nWhat is the maximum number of movies you can have in your library?\n";
cin >> maxMovies;
while(maxMovies <= 0)
{
  cout << "\n\nYou have to have at least one movie in your library.\n";
  cout << "What is the maximum number of movies you can have in your library.\n";
  cin >> maxMovies;
}
Movies* movieLibrary = createMovies(maxMovies);

do
{
  cout << "\n\nWhat would you like to do?\n";
  cout << "1. Read movies from file.\n";
  cout << "2. Save movies to a file.\n";
  cout << "3. Add a movie.\n";
  cout << "4. Delete a movie.\n";
  cout << "5. Edit a movie.\n";
  cout << "6. Print all movies.\n";
  cout << "7. Delete ALL movies and end the program.\n";
  cout << "CHOOSE 1-7: ";
  cin >> menuChoice;
  while(menuChoice < 1 || menuChoice > 7)
  {
   cout << "That is not a valid choice.\n";
   cout << "CHOOSE 1-7: ";
   cin >> menuChoice;
  }
  
  switch(menuChoice)
  {
   case 1: cout << "\n\nWhat is the name of the file? (example.txt): ";
     cin >> filename;
     readMoviesFromFile(filename, movieLibrary); //function is in Movies.cpp
     break;
     
   case 2: cout << "\n\nWhat 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 << "\n\nGOODBYE!\n\n";

return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#ifndef MOVIES_H

#define MOVIES_H

#include "Movie.h"

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

class Movies

{

public:

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();

/*

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

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 \n from the keyboard buffer

cout << "\n\nMOVIE TITLE: ";

cin.getline(tempString, 100);

title = createText(tempString);

cout << "\nMOVIE LENGTH (in minutes): ";

cin >> length;

cout << "\nMOVIE YEAR: ";

cin >> year;

cin.ignore();

cout << "\nMOVIE GENRE: ";

cin.getline(tempString, 100);

genre = createText(tempString);

cout << "\nMOVIE RATING: ";

cin.getline(tempString, 100);

rating = createText(tempString);

cout << "\nNUMBER OF OSCARS WON: ";

cin >> numOscars;

cout << "\nSTAR 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.\n";

}

else

{

cout << "\n\nChoose from the following movies to remove:\n";

displayMovieTitles();

cout << "\nChoose a movie to remove between 1 & " << numMovies << ": ";

cin >> movieChoice;

while (movieChoice < 1 || movieChoice > numMovies)

{

cout << "\nOops! 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 << "\n\nThe movie \"";

displayText(movieTitle);

cout << "\" has been successfully deleted.\n";

}

}

void Movies::editMovieInArray()

{

int movieChoice;

cout << "\n\nChoose from the following movies to edit:\n";

displayMovieTitles();

cout << "\nChoose a movie to remove between 1 & " << numMovies << ": ";

cin >> movieChoice;

while (movieChoice < 1 || movieChoice > numMovies)

{

cout << "\nOops! 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 << "\nThere are no movies in your library yet.";

}

void Movies::displayMovieTitles()

{

Text *movieTitle;

for (int x = 0; x < (numMovies); x++)

{

cout << "\nMOVIE " << (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 \n 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 \n 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!\n";

inFile.getline(temp, 100); //read in the next movie title if there is one

numMoviesReadFromFile++;

}

cout << "\n\n"

<< numMoviesReadFromFile << " movies were read from the file and added to your movie library.\n\n";

}

else

{

cout << "\n\nSorry, I was unable to open the file.\n";

}

}

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 << "\n\nAll movies in your library have been printed to " << filename << endl;

}

Add a comment
Know the answer?
Add Answer to:
WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Coding in c++

    I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it. main.cpp #include <iostream> #include <vector> #include <string> #include "functions.h" int main() {    char option;    vector<movie> movies;     while (true)     {         printMenu();         cin >> option;         cin.ignore();         switch (option)         {            case 'A':            {                string nm;                int year;                string genre;                cout << "Movie Name: ";                getline(cin, nm);                cout << "Year: ";                cin >> year;                cout << "Genre: ";                cin >> genre;                               //call you addMovie() here                addMovie(nm, year, genre, &movies);                cout << "Added " << nm << " to the catalog" << endl;                break;            }            case 'R':            {                   string mn;                cout << "Movie Name:";                getline(cin, mn);                bool found;                //call you removeMovie() here                found = removeMovie(mn, &movies);                if (found == false)                    cout << "Cannot find " << mn << endl;                else                    cout << "Removed " << mn << " from catalog" << endl;                break;            }            case 'O':            {                string mn;                cout << "Movie Name: ";                getline(cin, mn);                cout << endl;                //call you movieInfo function here                movieInfo(mn, movies);                break;            }            case 'C':            {                cout << "There are " << movies.size() << " movies in the catalog" << endl;                 // Call the printCatalog function here                 printCatalog(movies);                break;            }            case 'F':            {                string inputFile;                bool isOpen;                cin >> inputFile;                cout << "Reading catalog info from " << inputFile << endl;                //call you readFromFile() in here                isOpen = readFile(inputFile, &movies);                if (isOpen == false)                    cout << "File not found" << endl;...

  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

  • Help! Not sure how to create this java program to run efficiently. Current code and assignment...

    Help! Not sure how to create this java program to run efficiently. Current code and assignment attached. Assignment :Write a class Movies.java that reads in a movie list file (movies.txt). The file must contain the following fields: name, genre, and time. Provide the user with the options to sort on each field. Allow the user to continue to sort the list until they enter the exit option. ---------------------------------------------------------- import java.util.*; import java.io.*; public class Movies { String movieTitle; String movieGenre;...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

  • Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director,...

    Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...

  • Need this in C++ Goals: Your task is to implement a binary search tree of linked...

    Need this in C++ Goals: Your task is to implement a binary search tree of linked lists of movies. Tree nodes will contain a letter of the alphabet and a linked list. The linked list will be an alphabetically sorted list of movies which start with that letter. MovieTree() ➔ Constructor: Initialize any member variables of the class to default ~MovieTree() ➔ Destructor: Free all memory that was allocated void printMovieInventory() ➔ Print every movie in the data structure in...

  • Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU...

    Need help for C program. Thx #include <stdio.h> #include <string.h> #include <ctype.h> // READ BEFORE YOU START: // This homework is built on homework 06. The given program is an updated version of hw06 solution. It begins by displaying a menu to the user // with the add() function from the last homework, as well as some new options: add an actor/actress to a movie, display a list of movies for // an actor/actress, delete all movies, display all movies,...

  • PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class...

    PLEASE COMPLETE THE CODES. package javaprogram; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; /** * Movie class definition. * * @author David Brown * @version 2019-01-22 */ public class Movie implements Comparable { // Constants public static final int FIRST_YEAR = 1888; public static final String[] GENRES = { "science fiction", "fantasy", "drama", "romance", "comedy", "zombie", "action", "historical", "horror", "war" }; public static final int MAX_RATING = 10; public static final int MIN_RATING = 0; /** * Converts a string of...

  • c++, I am having trouble getting my program to compile, any help would be appreciated. #include...

    c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...

  • Write a cpp program Server.h #ifndef SERVER_H #define SERVER_H #include #include #include #include using namespace std;...

    Write a cpp program Server.h #ifndef SERVER_H #define SERVER_H #include #include #include #include using namespace std; class Server { public:    Server();    Server(string, int);    ~Server();    string getPiece(int); private:    string *ascii;    mutex access; }; #endif -------------------------------------------------------------------------------------------------------------------------- Server.cpp #include "Server.h" #include #include Server::Server(){} Server::Server(string filename, int threads) {    vector loaded;    ascii = new string[threads];    ifstream in;    string line;    in.open(filename);    if (!in.is_open())    {        cout << "Could not open file...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT