Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <iostream>
  2. //using namespace std;
  3.  
  4.  
  5. class Animal{
  6. public:
  7.     // zamiast tego std::* możesz odkomentować to wyżej choć jest to niedobrą praktyką, ale dla początkującego może być
  8.     // wtedy nie piszesz wszędzie std::
  9.     // nie do końca czaję o co mu chodzi ja bym zrobił przez string
  10.     std::string type_;
  11.     // tu to samo
  12.     std::string food_;
  13.     int age_;
  14.     std::string name_;
  15.  
  16.     // konstruktor
  17.     Animal(const std::string &type, const std::string &food, int age, const std::string &name)
  18.     {
  19.         this->type_ = type;
  20.         this->food_ = food;
  21.         this->age_ = age;
  22.         this->name_ = name;
  23.     }
  24.  
  25.     void printType()
  26.     {
  27.         std::cout << this->type_ << std::endl;
  28.     }
  29.  
  30.     void printData()
  31.     {
  32.         std::cout << this->name_ << ", " << this->food_ << " " << this->age_ << std::endl;
  33.     }
  34. };
  35.  
  36. int main() {
  37.     Animal animal1("Plazince", "owady", 12, "Seba");
  38.  
  39.     animal1.printType();
  40.     animal1.printData();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement