// Example about structures be used in a function

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct movies_t {
  string title;
  int    year;
} mine, yours;

void printmovie (movies_t movie);

int main ()
{
    string mystr;

    mine.title = "Braveheart";
    mine.year  = 1995;

    cout << "Enter title: ";
    getline (cin,yours.title);
    cout << "Enter year: ";
    getline (cin,mystr);
    stringstream(mystr) >> yours.year;

    cout << "My favorite movie is:\n ";
    printmovie (mine);
    cout << "And yours is:\n ";
    printmovie (yours);

    std::cin.get();
    return (0);   
}

void printmovie (movies_t movie)
{
  cout << movie.title;
  cout << " (" << movie.year << ")\n";
}
/*
The example shows how we can use the members of an object as regular variables. 
For example, the member yours.year is a valid variable of type int, and mine.title 
is a valid variable of type string.

The objects mine and yours can also be treated as valid variables of type movies_t, 
for example we have passed them to the function printmovie as we would have done with 
regular variables. Therefore, one of the most important advantages of data structures 
is that we can either refer to their members individually or to the entire structure 
as a block with only one identifier.
*/
