Advertisement
P22DX

MyFirstOopOn.cpp

Apr 28th, 2020
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Species {
  5.     protected:
  6.         std::string speciesName;
  7.  
  8.     public:
  9.         int population = 1;
  10.        
  11.         void setSpecies(std::string str)
  12.         {
  13.             this->speciesName = str;
  14.         }
  15.  
  16.         std::string getSpeciesName()
  17.         {
  18.             return this->speciesName;
  19.         }
  20. };
  21.  
  22. int main()
  23. {
  24.     Species firstSpecies;
  25.     Species secondSpecies;
  26.  
  27.     firstSpecies.setSpecies("Bird");
  28.     secondSpecies.setSpecies("Ant");
  29.     secondSpecies.population = 100;
  30.  
  31.     std::cout
  32.         << "I have "
  33.         << firstSpecies.getSpeciesName()
  34.         << " = "
  35.         << firstSpecies.population
  36.         << " and "
  37.         << secondSpecies.getSpeciesName()
  38.         << " = "
  39.         << secondSpecies.population
  40.         << std::endl;
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement