1: // Demonstrates declaration of a constructors and 2: // destructor
for the Cat class 3: 4: #include // for cout 5: 6: class Cat // begin
declaration of the class 7: { 8: public: & // begin public section 9:
Cat(int initialAge); & // constructor 10: & ~Cat(); // destructor 11:
& int GetAge(); // accessor function 12: & void SetAge(int age); //
accessor function 13: & void Meow(); 14: private: // begin private
section 15: & int itsAge; & // member variable 16:& }; 17: 18:& //
constructor of Cat, 19:& Cat::Cat(int initialAge) 20:& { 21: & itsAge
= initialAge; 22:& } 23: 24:& Cat::~Cat() & // destructor, takes no
action 25:& { 26:& } 27: 28:& // GetAge, Public accessor function 29:&
// returns value of itsAge member 30:& int Cat::GetAge() 31:& { 32: &
return itsAge; 33:& } 34: 35:& // Definition of SetAge, public 36:& //
accessor function 37: 38:& void Cat::SetAge(int age) 39:& { 40: & //
set member variable its age to 41: & // value passed in by parameter
age 42: & itsAge = age; 43:& } 44: 45:& // definition of Meow method
46:& // returns: void 47:& // parameters: None 48:& // action: Prints
"meow" to screen 49:& void Cat::Meow() 50:& { 51: & cout
Jimmy
15.12.11, 09:03
sir please help me in this c++ program to give an example of
constructor and destructor
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
1: // Demonstrates declaration of a constructors and 2: // destructor for the Cat class 3: 4: #include // for cout 5: 6: class Cat // begin declaration of the class 7: { 8: public: & // begin public section 9: Cat(int initialAge); & // constructor 10: & ~Cat(); // destructor 11: & int GetAge(); // accessor function 12: & void SetAge(int age); // accessor function 13: & void Meow(); 14: private: // begin private section 15: & int itsAge; & // member variable 16:& }; 17: 18:& // constructor of Cat, 19:& Cat::Cat(int initialAge) 20:& { 21: & itsAge = initialAge; 22:& } 23: 24:& Cat::~Cat() & // destructor, takes no action 25:& { 26:& } 27: 28:& // GetAge, Public accessor function 29:& // returns value of itsAge member 30:& int Cat::GetAge() 31:& { 32: & return itsAge; 33:& } 34: 35:& // Definition of SetAge, public 36:& // accessor function 37: 38:& void Cat::SetAge(int age) 39:& { 40: & // set member variable its age to 41: & // value passed in by parameter age 42: & itsAge = age; 43:& } 44: 45:& // definition of Meow method 46:& // returns: void 47:& // parameters: None 48:& // action: Prints "meow" to screen 49:& void Cat::Meow() 50:& { 51: & cout
sir please help me in this c++ program to give an example of constructor and destructor