You are on page 1of 1

1.

using namespace std;


2.
3. class Animal {
4. private:
5. int age;
6. public:
7. Animal(int a = 1){
8. age = a;
9. };
10. int getAge() const {return age;}
11. void setAge(int a = 9){
12. age = a;
13. }
14. };
15.
16. class Dog:public Animal { };
17.
18. class Cat:public Animal {
19. private:
20. float weight;
21. public:
22. Cat(int a = 2, float w = 3.2):Animal(a){
23. weight = w;
24. }
25. float getWeight() const {return weight;}
26. };
27.
28. int main(){
29. Dog mastin;
30. cout << "____DOG____" << endl;
31. cout << "Before: " << mastin.getAge() << endl;
32. mastin.setAge(2);
33. cout << "After: " << mastin.getAge() << endl;
34. Cat miau(3, 4.1);
35. cout << "____CAT____" << endl;
36. cout << miau.getAge() << " " << miau.getWeight() << endl;
37. }

You might also like