Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class CAT //sazdava se klas
- {
- public: //funkciq za dostup
- CAT(); // constructor
- CAT (const CAT &); // kopirasht constructor
- ~CAT(); // destructor
- int GetAge() const { return *itsAge; } //funkciq GetAge vrashta promenlivata kum koqto sochi itsAge
- int GetWeight() const { return *itsWeight; } //funkciq GetWeight vrashta promenlivata kum koqto sochi itsWeight
- void SetAge(int age) { *itsAge = age; } // funkciq SetAge
- private: //funkciq za dostup
- int *itsAge;
- int *itsWeight; }; // inicializirane na promenlivite
- CAT::CAT() {
- itsAge = new int; // zadavane na promenlivite v dinamichnata pamet
- itsWeight = new int;
- *itsAge = 5; //zadavat se stoinisti na promenlivite koito sochat kum itsAge i itsWeight
- *itsWeight = 9; }
- CAT::CAT(const CAT & rhs) { // sashtoto neshto za kopirashtiq konstruktor
- itsAge = new int;
- itsWeight = new int;
- *itsAge = rhs.GetAge();
- *itsWeight = rhs.GetWeight();}
- CAT::~CAT(){ // nulirane na stoinstite na promenlivite
- delete itsAge;
- itsAge = 0;
- delete itsWeight;
- itsWeight = 0; }
- int main(){ // glavnata funkciq
- CAT frisky; // frisky e obekt na klas CAT
- cout << "frisky's age: " << frisky.GetAge() << endl; //funkciq getAge izvazhda stoinstta 0
- cout << "Setting frisky to 6...\n"; // teksta na tva otdolu
- frisky.SetAge(6); // zadavane na stoinost na SetAge - 6
- cout << "Creating boots from frisky\n"; // kopirashtiq konstruktor sazdava obekt boots ot frisky
- CAT boots(frisky); //klas boots
- cout << "frisky's age: " << frisky.GetAge() << endl; // izkarvane na zadadenata po-gore stoinost 6
- cout << "boots' age: " << boots.GetAge() << endl; // izkarvane na zadadenata po-gore stoinost 6
- cout << "setting frisky to 7...\n"; // tekst - zadavane na stoinostta na frisky ot 6 na 7
- frisky.SetAge(7); //zadavane na stoinostta na frisky ot 6 na 7
- cout << "frisky's age: " << frisky.GetAge() << endl; //tva izkarva stoinost 7 shtoto po-gore mu se zadade
- cout << "boot's age: " << boots.GetAge() << endl; // tva izkarva 6 zashtoto e kopie na frisky ot predi malko
- return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement