-
Notifications
You must be signed in to change notification settings - Fork 246
/
7.50.cpp
42 lines (34 loc) · 900 Bytes
/
7.50.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
#include <string>
#include <iostream>
class Person {
friend std::istream &read(std::istream &, Person &);
//friend std::ostream &print(std::ostream &, const Person &);
public:
Person() = default;
explicit Person(const std::string &n) : name(n) {}
Person(const std::string &n, const std::string &a)
: name(n), address(a) {}
explicit Person(std::istream &);
std::string getName() const { return name; }
std::string getAddress() const { return address; }
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() {
Person p;
read(std::cin, p);
print(std::cout, p);
return 0;
}