-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchild.cpp
More file actions
69 lines (69 loc) · 1.86 KB
/
Copy pathchild.cpp
File metadata and controls
69 lines (69 loc) · 1.86 KB
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
#include "child.h"
// Constructors
Child::Child() {
age_ = 0;
}
Child::Child(string first_name, string last_name, int age) {
first_name_ = first_name;
last_name_ = last_name;
age_ = age;
}
Child::Child(string first_name, string last_name) {
first_name_ = first_name;
last_name_ = last_name;
age_ = 0;
}
string Child::name() const {
return (first_name_ + last_name_);
}
int Child::age() const {
return age_;
}
void Child::set_first_name(const string& name) {
first_name_ = name;
}
void Child::set_last_name(const string& name) {
last_name_ = name;
}
// Operator Overloads
bool Child::operator==(const Child& child) const {
return ((first_name_ == child.first_name_) &&
(last_name_ == child.last_name_) &&
(age_ == child.age_));
}
bool Child::operator!=(const Child& child) const {
return !(*this == child);
}
bool Child::operator<(const Child& child) const {
// Compare last names, then first names, then age.
if (last_name_ < child.last_name_) {
return true;
} else if (last_name_ > child.last_name_) {
return false;
}
if (first_name_ < child.first_name_) {
return true;
} else if (first_name_ > child.first_name_) {
return false;
}
return (age_ < child.age_);
}
bool Child::operator<=(const Child& child) const {
return ((*this == child) || (*this < child));
}
bool Child::operator>(const Child& child) const {
return !(*this <= child);
}
bool Child::operator>=(const Child& child) const {
return ((*this == child) || (*this > child));
}
ostream& operator<<(ostream& stream, const Child& child) {
stream << child.first_name_ << child.last_name_ << child.age_;
return stream;
}
istream& operator>>(istream& stream, Child& child) {
stream >> child.first_name_;
stream >> child.last_name_;
stream >> child.age_;
return stream;
}