-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoopsinheritance2.cpp
More file actions
69 lines (57 loc) · 1.12 KB
/
oopsinheritance2.cpp
File metadata and controls
69 lines (57 loc) · 1.12 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
#include <iostream>
using namespace std;
class Animal
{
public:
Animal();
Animal(string name, int age, int numb_limbs);
string Name;
int Age;
int NumberOfLimbs;
void Report();
};
class Dog : public Animal
{
// c++ HAS A DEFAULT CONSTRUCTOR BUT ALSO CALLS PARENT CLASS CONSTRUCTOR
public:
Dog();
Dog(string name, int age, int numb_limbs);
};
int main() {
//Animal animal;
//animal.Report();
//Animal animal2("cheetah", 7, 8);
/*animal2.Report(); */
Dog dog("spot",4,5);
}
Animal::Animal()
{
cout << "An Animal is born! \n";
NumberOfLimbs = 4;
Name = "Default";
Age = 2;
//Report();
}
//Animal::Animal(string name, int age, int numb_limbs)
//{
// Name=name;
// Age = age;
// NumberOfLimbs = numb_limbs;
//}
Animal::Animal(string name, int age, int numb_limbs) :
Name(name), Age(age), NumberOfLimbs(numb_limbs)
{
Report();
}
void Animal::Report() {
cout << "Name: " << Name << endl;
cout << " Age: " << Age << endl;
cout << "Number of Limbs " << NumberOfLimbs << endl;
}
Dog::Dog() {
cout << " A dog is born" << endl;
}
Dog::Dog(string name, int age, int numb_limbs)
{
Animal(name, age, numb_limbs);
}