-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path09-person1.cpp
More file actions
26 lines (22 loc) · 739 Bytes
/
09-person1.cpp
File metadata and controls
26 lines (22 loc) · 739 Bytes
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
// 09-person1.cpp : model Person as a class with constructor
#include <chrono>
#include <iostream>
#include <string>
#include <string_view>
using namespace std;
using namespace std::chrono;
class Person {
public:
Person(const year_month_day& dob, string_view familyname, string_view firstname)
: dob{ dob }, familyname{ familyname }, firstname{ firstname }
{}
string getName() const { return firstname + ' ' + familyname; }
const year_month_day& getDob() const { return dob; }
private:
const year_month_day dob;
string familyname, firstname;
};
int main() {
Person genius{ { 1879y, March, 14d }, "Einstein", "Albert" };
cout << genius.getName() << " was born " << genius.getDob() << '\n';
}