Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class CAT //sazdava se klas
  4. {
  5. public: //funkciq za dostup
  6. CAT(); // constructor
  7. CAT (const CAT &); // kopirasht constructor
  8. ~CAT(); // destructor
  9. int GetAge() const { return *itsAge; } //funkciq GetAge vrashta promenlivata kum koqto sochi itsAge
  10. int GetWeight() const { return *itsWeight; } //funkciq GetWeight vrashta promenlivata kum koqto sochi itsWeight
  11. void SetAge(int age) { *itsAge = age; } // funkciq SetAge
  12. private: //funkciq za dostup
  13. int *itsAge;
  14. int *itsWeight; }; // inicializirane na promenlivite
  15.  
  16. CAT::CAT() {
  17. itsAge = new int; // zadavane na promenlivite v dinamichnata pamet
  18. itsWeight = new int;
  19. *itsAge = 5; //zadavat se stoinisti na promenlivite koito sochat kum itsAge i itsWeight
  20. *itsWeight = 9; }
  21.  
  22. CAT::CAT(const CAT & rhs) { // sashtoto neshto za kopirashtiq konstruktor
  23. itsAge = new int;
  24. itsWeight = new int;
  25. *itsAge = rhs.GetAge();
  26. *itsWeight = rhs.GetWeight();}
  27.  
  28. CAT::~CAT(){ // nulirane na stoinstite na promenlivite
  29. delete itsAge;
  30. itsAge = 0;
  31. delete itsWeight;
  32. itsWeight = 0; }
  33.  
  34. int main(){ // glavnata funkciq
  35. CAT frisky; // frisky e obekt na klas CAT
  36. cout << "frisky's age: " << frisky.GetAge() << endl; //funkciq getAge izvazhda stoinstta 0
  37. cout << "Setting frisky to 6...\n"; // teksta na tva otdolu
  38. frisky.SetAge(6); // zadavane na stoinost na SetAge - 6
  39. cout << "Creating boots from frisky\n"; // kopirashtiq konstruktor sazdava obekt boots ot frisky
  40. CAT boots(frisky); //klas boots
  41. cout << "frisky's age: " << frisky.GetAge() << endl; // izkarvane na zadadenata po-gore stoinost 6
  42. cout << "boots' age: " << boots.GetAge() << endl; // izkarvane na zadadenata po-gore stoinost 6
  43. cout << "setting frisky to 7...\n"; // tekst - zadavane na stoinostta na frisky ot 6 na 7
  44. frisky.SetAge(7); //zadavane na stoinostta na frisky ot 6 na 7
  45. cout << "frisky's age: " << frisky.GetAge() << endl; //tva izkarva stoinost 7 shtoto po-gore mu se zadade
  46. cout << "boot's age: " << boots.GetAge() << endl; // tva izkarva 6 zashtoto e kopie na frisky ot predi malko
  47. return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement