-
Notifications
You must be signed in to change notification settings - Fork 0
/
12_2.cpp
45 lines (36 loc) · 840 Bytes
/
12_2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//array of structures
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define N_MOVIES 3
struct movies_t {
string title;
int year;
} films[N_MOVIES];
void printmovie(movies_t movie);
int main()
{
string mystr;
int n;
for (n = 0; n < N_MOVIES; n++)
{
cout << "Enter title: ";
getline(cin, films[n].title);
cout << "Enter year: ";
getline(cin, mystr);
stringstream(mystr) >> films[n].year;
}
cout << endl << "You have entered these movies:" << endl;
for (n = 0; n < N_MOVIES; n++)
{
printmovie(films[n]);
}
getchar();
return 0;
}
void printmovie(movies_t movie)
{
cout << movie.title;
cout << " (" << movie.year << ")\n";
}