0

Come up with a program that prompts the user to enter three movies and display the entered information using your understanding of data strucures.

// Structures3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<string>
#include<sstream>

using namespace std;
# define N_movies 3

struct movies_t{

    string title;
    int year;
}
films[N_movies];// array of object films

void printmovie(movies_t movies);

int main(int argc, char* argv[])
{
    string mystr;int n;

    for(n=0;n<N_movies;n++)
    {
        cout<<"Enter Title";
        getline(cin,films[n].title);cin.ignore(100,'\n');
        cout<<"Enter year ";getline(cin,mystr);cin.ignore(100,'\n');
        stringstream(mystr)>>films[n].year;
    }
    cout<<"You have entered these movies";
    for(n=0;n<N_movies;n++)
    {
        printmovie(films[n]);
    }
    return 0;
    }
    void printmovie(movies_t movie){
        cout<<movie.title<<"\t";
        cout<<movie.year<<"\t"<<"\n";
    }
2
Contributors
1
Reply
13
Views
3 Years
Discussion Span
Last Post by JasonHippy
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.