/* Movie Data - This program uses a structure named MovieData to store the
following information about a movie:
* Title
* Director
* Year Released
* Running Time (in minutes)
The program creates two MovieData variables, stores values in their
members, and pass each one, in turn, to a function that displays the
information about the movie in a clearly formatted manner. */
#include "Utility.h"
struct MovieData
{
string title; /* The movie's title */
string director; /* The movie director's name */
int releaseYear; /* The year the movie was released */
int runningTime; /* The movie length in minutes */
};
void getMovieData(MovieData &);
void repeatInput(MovieData &);
void showMovieData(const MovieData &);
int main()
{
/* Structure variable definitions */
MovieData movieOne;
MovieData movieTwo;
cout << "\n\tFavorite Movie Database\n\n";
getMovieData(movieOne);
repeatInput(movieOne);
getMovieData(movieTwo);
repeatInput(movieTwo);
cout << "\n\tThese movies are now stored in your database:\n";
showMovieData(movieOne);
showMovieData(movieTwo);
pauseSystem();
return 0;
}
/* **********************************************************
Definition: repeatInput
This function uses a structure reference variable as its
argument. It asks the user to confirm his or her input. If
the displayed information is incorrect, the user is asked
to repeat the input. If the user finds that the input is
correct, a message is displayed, telling the user that the
movie info has been added.
********************************************************** */
void repeatInput(MovieData &movieInfo)
{
char again = ' ';
do
{
showMovieData(movieInfo);
cout << "\tIs the data you entered correct? (Y/N): ";
cin >> again;
cin.ignore();
if (toupper(again) == 'Y')
{
cout << "\n\tThe following movie info has been added:\n";
showMovieData(movieInfo);
}
else
{
cout << "\n\n\tPlease repeat your input:\n";
getMovieData(movieInfo);
}
} while (toupper(again) == 'N' || toupper(again) != 'Y');
}
/* **********************************************************
Definition: getMovieData
This function uses a structure reference variable as its
argument. It asks the user for data about his or her two
favorite movies. This data is stored in the structure.
********************************************************** */
void getMovieData(MovieData &movieInfo)
{
cout << "\n\tEnter the name of your favorite movie: ";
getline(cin, movieInfo.title);
cout << "\tEnter the name of the movie's director: ";
getline(cin, movieInfo.director);
cout << "\tEnter the year the movie was released: ";
cin >> movieInfo.releaseYear;
cout << "\tEnter the running time (in minutes): ";
cin >> movieInfo.runningTime;
cin.ignore();
}
/* **********************************************************
Definition: showMovieData
This function accepts a constant reference to a structure
variable as argument. It displays the movie data.
********************************************************** */
void showMovieData(const MovieData &mData)
{
cout << "\n\tMovie Title: " << mData.title << "\n"
<< "\tDirector: " << mData.director << "\n"
<< "\tRelease Year: " << mData.releaseYear << "\n"
<< "\tRunning Time: " << mData.runningTime << " minutes\n\n";
}
Monday, May 22, 2017
Programming Challenge 11.1 - Movie Data
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment