-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoopsinheritance1.cpp
More file actions
51 lines (41 loc) · 804 Bytes
/
oopsinheritance1.cpp
File metadata and controls
51 lines (41 loc) · 804 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
#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();
};
int main() {
Animal animal;
animal.Report();
Animal animal2("cheetah", 7, 8);
/*animal2.Report(); */
}
Animal::Animal()
{
cout << "An Animal is born! \n";
NumberOfLimbs = 4;
Name = "Default";
Age = 2;
}
//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;
}