Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //animal.h
- #ifndef ANIMAL_H
- #define ANIMAL_H
- #include <string>
- class Animal
- {
- public:
- Animal(std::string animalClass_, std::string type_, unsigned age_);
- std::string getAnimalClass() {return animalClass;}
- std::string getType() {return type;}
- unsigned getAge() {return age;}
- protected:
- std::string type;
- std::string animalClass;
- unsigned age;
- };
- #endif // ANIMAL_H
- //animal.cpp
- #include "animal.h"
- Animal::Animal(std::string animalClass_, std::string type_, unsigned age_) :
- type(type_),
- animalClass(animalClass_),
- age(age_)
- {}
- //mammal.h
- #ifndef MAMMAL_H
- #define MAMMAL_H
- #include "animal.h"
- class Mammal : public Animal
- {
- public:
- Mammal(std::string type_, std::string name_, unsigned age_);
- std::string getName() {return name;}
- protected:
- std::string name;
- };
- #endif // MAMMAL_H
- //mammal.cpp
- #include "mammal.h"
- Mammal::Mammal(std::string type_, std::string name_, unsigned age_) :
- Animal("Ssaki", type_, age_),
- name(name_)
- {}
- //dog.h
- #ifndef DOG_H
- #define DOG_H
- #include "mammal.h"
- class Dog : public Mammal
- {
- public:
- Dog(std::string name_, std::string owner_, unsigned age_);
- std::string getOwnerName() {return owner;}
- private:
- std::string owner;
- };
- #endif // DOG_H
- //dog.cpp
- #include "dog.h"
- Dog::Dog(std::string name_, std::string owner_, unsigned age_) :
- Mammal ("Pies", name_, age_),
- owner(owner_)
- {}
- //main.cpp
- #include <iostream>
- #include "dog.h"
- using namespace std;
- int main()
- {
- Dog leos("Leo", "Jakub Warchol", 4);
- cout << "Gromada: " << leos.getAnimalClass() << endl;
- cout << "Gatunek: " << leos.getType() << endl;
- cout << "Imie: " << leos.getName() << endl;
- cout << "Wlasciciel: " << leos.getOwnerName() << endl;
- cout << "Wiek: " << leos.getAge() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement