-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cat.cpp
66 lines (59 loc) · 1.12 KB
/
Cat.cpp
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
#include "Cat.h"
Cat::Cat(const char * name, const char *color,ushort weight,ushort Age)
{
this->name = nullptr;
this->color = nullptr;
this->weight = 0;
this->Age = 0;
SetName(name);
SetColor(color);
Setweight(weight);
SetAge(Age);
}
Cat::~Cat()
{
delete[] this->name;
delete[] this->color;
}
void Cat::SetName(const char * name)
{
int len = strlen(name) + 1;
if (this->name)
delete[] this->name;
this->name = new char[len];
strcpy_s(this->name, len, name);
}
char * Cat::GetName() const
{
int len = strlen(this->name) + 1;
char * Cat_name = new char[len];
strcpy_s(Cat_name, len, this->name);
return Cat_name;
}
void Cat::SetColor(const char * color)
{
int len = strlen(color) + 1;
if (this->color)
delete[] this->color;
this->color = new char[len];
strcpy_s(this->color, len, color);
}
char * Cat::GetColor() const
{
int len = strlen(this->color) + 1;
char * Cat_color = new char[len];
strcpy_s(Cat_color, len, this->color);
return Cat_color;
}
void Cat::Setweight(ushort weight)
{
this->weight = weight;
}
void Cat::SetAge(ushort Age)
{
this->Age = Age;
}
char * Cat::Voice() const
{
return " Meow ";
}