SHARE
TWEET

Untitled

a guest Dec 8th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Dog{
  7.  
  8.     friend class Person;
  9.  
  10.     string name;
  11.     bool hungry;
  12. public:
  13.     Dog(string imiePsa);
  14.     string getName();
  15.     bool isHungry();
  16.     void zmianaCzyGlodny();
  17. };
  18.  
  19. Dog::Dog(string imiePsa){
  20.     name = imiePsa;
  21.     hungry = true;
  22. };
  23. string Dog::getName() {
  24.     return name;
  25. };
  26. bool Dog::isHungry() {
  27.     return hungry;
  28. };
  29. void Dog::zmianaCzyGlodny() {
  30.     hungry=false;
  31. }
  32.  
  33.  
  34. class Person{
  35.     string name;
  36.     Dog *dogs[5];
  37.     int ileMamPsow;
  38. public:
  39.     Person(string imieOsoba);
  40.     void feedDog(int idPsa);
  41.     void feedAllDogs();
  42.     void addDog(Dog * wskPies);
  43.     void removeDog(int idPsa);
  44.     Dog *getDog(int idPsa);
  45.     void printDogNames();
  46. };
  47.  
  48. Person::Person(string imieOsoba) {
  49.     name = imieOsoba;
  50.     ileMamPsow=0;
  51. };
  52. void Person::feedDog(int idPsa) {
  53.     dogs[idPsa]->zmianaCzyGlodny();
  54. }
  55. void Person::feedAllDogs() {
  56.     for(int i=0; i<ileMamPsow; i++){
  57.         dogs[i]->zmianaCzyGlodny();
  58.     }
  59. }
  60. void Person::addDog(Dog *wskPies) {
  61.     dogs[ileMamPsow]=wskPies;
  62.     ileMamPsow++;
  63. }
  64. void Person::removeDog(int idPsa) {
  65.  
  66.     dogs[idPsa]=NULL;
  67.  
  68.     for(int i=idPsa; i<=ileMamPsow; i++){
  69.         if(i==5){
  70.             dogs[4]= dogs[5];
  71.             dogs[5]=NULL;
  72.         }else{
  73.             dogs[i]=dogs[i+1];
  74.         }
  75.  
  76.     }
  77.     ileMamPsow--;
  78. }
  79.  
  80. Dog* Person::getDog(int idPsa) {
  81.     return dogs[idPsa];
  82. }
  83. void Person::printDogNames() {
  84.     for(int i =0; i<ileMamPsow; i++) {
  85.         cout << dogs[i]->getName();
  86.     }
  87. }
  88.  
  89. int main() {
  90.    
  91.     return 0;
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top