forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex7_15.cpp
60 lines (47 loc) · 1.03 KB
/
ex7_15.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
//! @Alan
//!
//! Exercise 7.15:
//! Add appropriate constructors to your Person class.
//!
#include <iostream>
#include <string>
struct Person
{
//!
//! @brief Exercise 7.15
//!
Person() =default;
Person(const std::string &nm, const std::string &add) {this->name = nm; this->address = add;}
Person(std::istream &);
std::string name;
std::string address;
std::string getName(void) const {return this->name;}
std::string getAddress(void) const {return this->address;}
};
std::istream &read(std::istream &is, Person &p);
std::ostream &print(std::ostream &os, const Person &p);
//!
//! @brief Exercise 7.15
//!
Person::Person(std::istream &is)
{
read(is, *this);
}
int main()
{
//Person p;
//Person p("Alan","dd zz aa");
Person p(std::cin);
print(std::cout,p);
return 0;
}
std::ostream &print(std::ostream &os, const Person &p)
{
os<<p.getName()<<" "<<p.address;
return os;
}
std::istream &read(std::istream &is, Person &p)
{
is>>p.name>>p.address;
return is;
}