14_4.cpp
Upload User: puke2000
Upload Date: 2022-07-25
Package Size: 912k
Code Size: 1k
Category:

CSharp

Development Platform:

Visual C++

  1. //14_4
  2. #include <iostream.h>
  3. class CAT{
  4. public:
  5.   CAT();
  6.   CAT(const CAT&);
  7.   ~CAT();
  8.   int GetAge() const { return *itsAge; }
  9.   void SetAge(int age){ *itsAge=age; }
  10. protected:
  11.   int* itsAge;
  12. };
  13. CAT::CAT()
  14. {
  15.   itsAge=new int;
  16.   *itsAge =5;
  17. }
  18. CAT::CAT(const CAT& c)
  19. {
  20.   itsAge = new int;
  21.   *itsAge = *(c.itsAge);
  22. }
  23. CAT::~CAT()
  24. {
  25.   delete itsAge;
  26.   itsAge =0;
  27. }
  28. void main()
  29. {
  30.   CAT frisky;
  31.   cout <<"frisky's age:" <<frisky.GetAge() <<endl;   cout <<"Setting frisky to 6...n";
  32.   frisky.SetAge(6);
  33.   cout <<"Creating boots from friskyn";
  34.   CAT boots(frisky);
  35.   cout <<"frisky's age:" <<frisky.GetAge() <<endl;   cout <<"boots'age:" <<boots.GetAge() <<endl;
  36.   cout <<"setting frisky to 7...n";
  37.   frisky.SetAge(7);
  38.   cout <<"frisky's age:" <<frisky.GetAge() <<endl;   cout <<"boots'age:" <<boots.GetAge() <<endl; }