-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.cpp
More file actions
70 lines (52 loc) · 888 Bytes
/
Person.cpp
File metadata and controls
70 lines (52 loc) · 888 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
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
#include <iostream>
#include <cstring>
class Person
{
private:
int age;
char* name;
public:
Person(int age, char* name);
~Person();
void ShowName();
void ShowAge();
void ShowAll();
};
Person::Person(int age, char* name)
{
this->age = age;
this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
}
Person::~Person()
{
delete []name;
}
void Person::ShowName()
{
std::cout << name << std::endl;
}
void Person::ShowAge()
{
std::cout << age << std::endl;
}
void Person::ShowAll()
{
Person::ShowName();
Person::ShowAge();
}
int main()
{
Person p1(14, "Àå°æÇõ");
Person p2(32, "·ÖÁ¤ÀÎ");
p1.ShowAge();
p1.ShowName();
std::cout << std::endl;
p2.ShowName();
p2.ShowAge();
std::cout << std::endl;
p1.ShowAll();
std::cout << std::endl;
p2.ShowAll();
return 0;
}