forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.19.cpp
37 lines (30 loc) · 887 Bytes
/
7.19.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
#include <string>
#include <iostream>
struct Person {
// Constructors which are part of interface should be public
Person() = default;
Person(const std::string &n) : name(n) {}
Person(const std::string &n, const std::string &a)
: name(n), address(a) {}
Person(std::istream &);
// member methods which are part of interface should be public
std::string getName() const { return name; }
std::string getAddress() const { return address; }
// data members which are part of implementation shoule be private
std::string name;
std::string address;
};
std::istream &read(std::istream &is, Person &rhs) {
is >> rhs.name >> rhs.address;
return is;
}
std::ostream &print(std::ostream &os, const Person &rhs) {
os << rhs.getName() << " " << rhs.getAddress();
return os;
}
Person::Person(std::istream &is) {
read(is, *this);
}
int main() {
return 0;
}