-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthor.cpp
More file actions
50 lines (40 loc) · 1.17 KB
/
Copy pathauthor.cpp
File metadata and controls
50 lines (40 loc) · 1.17 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
#include "author.hpp"
#include <stdexcept> // invalid_argument
// 1. реализуйте конструктор ...
Author::Author(const std::string &full_name, int age, Sex sex) {
// валидация аргументов (здесь был Рамиль)
if (age < kMinAuthorAge) {
throw std::invalid_argument("Author::age must be greater than " + std::to_string(kMinAuthorAge));
}
if (full_name.empty()) {
throw std::invalid_argument("Author::full_name must not be empty");
}
// Tip 1: инициализируйте поля
full_name_ = full_name;
age_ = age;
sex_ = sex;
}
void Author::SetAge(int age) {
if (age < kMinAuthorAge) {
throw std::invalid_argument("Author::age must be greater than " + std::to_string(kMinAuthorAge));
}
age_ = age;
}
void Author::SetSex(Sex sex) {
sex_ = sex;
}
void Author::SetFullName(const std::string &full_name) {
if (full_name.empty()) {
throw std::invalid_argument("Author::full_name must not be empty");
}
full_name_ = full_name;
}
int Author::GetAge() const {
return age_;
}
Sex Author::GetSex() const {
return sex_;
}
const std::string &Author::GetFullName() const {
return full_name_;
}