Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //using namespace std;
- class Animal{
- public:
- // zamiast tego std::* możesz odkomentować to wyżej choć jest to niedobrą praktyką, ale dla początkującego może być
- // wtedy nie piszesz wszędzie std::
- // nie do końca czaję o co mu chodzi ja bym zrobił przez string
- std::string type_;
- // tu to samo
- std::string food_;
- int age_;
- std::string name_;
- // konstruktor
- Animal(const std::string &type, const std::string &food, int age, const std::string &name)
- {
- this->type_ = type;
- this->food_ = food;
- this->age_ = age;
- this->name_ = name;
- }
- void printType()
- {
- std::cout << this->type_ << std::endl;
- }
- void printData()
- {
- std::cout << this->name_ << ", " << this->food_ << " " << this->age_ << std::endl;
- }
- };
- int main() {
- Animal animal1("Plazince", "owady", 12, "Seba");
- animal1.printType();
- animal1.printData();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement