-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBirthdays.cpp
More file actions
82 lines (77 loc) · 1.72 KB
/
Birthdays.cpp
File metadata and controls
82 lines (77 loc) · 1.72 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
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <string>
using namespace std;
class Person {
public:
Person(string n, int d, int m, int y);
bool isOlderThan(Person *person);
string getName();
int getDay();
int getMonth();
int getYear();
void toString();
private:
string name;
int day, month, year;
};
Person::Person(string n, int d, int m, int y) {
name = n;
day = d;
month = m;
year = y;
}
string Person::getName() {
return name;
}
int Person::getDay() {
return day;
}
int Person::getMonth() {
return month;
}
int Person::getYear() {
return year;
}
bool Person::isOlderThan(Person *person) {
if (getYear()<person->getYear())
return true;
else if (getYear() == person->getYear())
if (getMonth()<person->getMonth())
return true;
else if (getMonth() == person->getMonth())
if (getDay()<person->getDay())
return true;
else
return false;
else
return false;
else
return false;
}
void Person::toString() {
cout << name << endl;
}
int main() {
int tot = 0;
cin >> tot;
string name, day, month, year;
cin >> name >> day >> month >> year;
string old = name, young = old;
int doo = stoi(day), mo = stoi(month), yo = stoi(year);
int dy = doo, my = mo, yy = yo;
Person *oldPerson = new Person(name, doo, mo, yo);
Person *youngPerson = new Person(name, dy, my, yy);
for (int i = 1; i<tot; i++) {
string name_tmp, day_tmp, month_tmp, year_tmp;
cin >> name_tmp >> day_tmp >> month_tmp >> year_tmp;
int d = stoi(day_tmp), m = stoi(month_tmp), y = stoi(year_tmp);
Person *tmpPerson = new Person(name_tmp, d, m, y);
if (tmpPerson->isOlderThan(oldPerson))
oldPerson = tmpPerson;
else if (!tmpPerson->isOlderThan(youngPerson))
youngPerson = tmpPerson;
}
youngPerson->toString();
oldPerson->toString();
return 0;
}