-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData Structures 3_5.cpp
97 lines (77 loc) · 1.81 KB
/
Data Structures 3_5.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#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 = "Miracle";
// mine.year = 2004;
// 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);
// return 0;
//}
//void printmovie (movies_t movie) // Note how only Mine/Yours is passed, compare that to (movies_t movie)
//{
//cout << movie.title;
// cout << " (" << movie.year << ")\n";
//}
//struct movies_t {
// string title;
// int year;
//} films [3];
//void printmovie (movies_t movie);
//int main ()
//{
// string mystr;
// int n;
// for (n=0; n<3; n++)
// {
// cout << "Enter title: ";
// getline (cin,films[n].title);
// cout << "Enter year: ";
// getline (cin,mystr);
// stringstream(mystr) >> films[n].year;
// }
// cout << "\nYou have entered these movies:\n";
// for (n=0; n<3; n++)
// printmovie (films[n]);
// return 0;
//}
//void printmovie (movies_t movie)
//{
// cout << movie.title;
// cout << " (" << movie.year << ")\n";
//}
struct movies_t {
string title;
int year;
};
int main ()
{
string mystr;
movies_t amovie;
movies_t * pmovie; // Set up pointer
pmovie = &amovie; // Address pointer
cout << "Enter title: ";
getline (cin, pmovie->title); // This arrow can onl be used with pointers to objects with members
cout << "Enter year: ";
getline (cin, mystr);
(stringstream) mystr >> pmovie->year;
cout << "\nYou have entered:\n";
cout << pmovie->title;
cout << " (" << pmovie->year << ")\n";
return 0;
}