-
Notifications
You must be signed in to change notification settings - Fork 0
/
inheritance.cpp
81 lines (63 loc) · 1.45 KB
/
inheritance.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <memory>
#include <string>
#include <iostream>
using namespace std;
class Animal
{
protected:
string m_name;
string m_kind;
public:
Animal();
Animal(string name, string kind):m_name(name), m_kind(kind){}
~Animal();
void animal_sleep(bool isSleeping);
virtual void display_animal()=0;
};
class Dog: public Animal
{
public:
Dog(string name, string kind):Animal(name, kind){}
void display_animal() override;
};
class Cat : public Animal
{
public:
Cat(string name, string kind):Animal(name, kind){}
void display_animal() override;
};
int main(int argc, char *argv[])
{
Dog some_dog={"doggo","shepherd"};
Cat some_cat={"kitty", "persian"};
some_dog.display_animal();
some_dog.animal_sleep(true);
some_cat.display_animal();
some_cat.animal_sleep(false);
return 0;
}
Animal::Animal()
{
}
Animal::~Animal()
{
}
void Animal::display_animal()
{
cout<<"animal is: "<<m_kind<<" named: "<<m_name<<"\n";
}
void Animal::animal_sleep(bool isSleeping)
{
if (isSleeping)
cout<<"animal is sleeping..."<<"\n";
else
cout<<"animal is not sleeping..."<<"\n";
}
void Dog::display_animal()
{
cout<<"dog is: "<<m_kind<<" named: "<<m_name<<"\n";
}
void Cat::display_animal()
{
cout<<"cat is: "<<m_kind<<" named: "<<m_name<<"\n";
}