C++ Program for Time class with Constructor & Destructor: This CPP code can add two time variables with an use of constructor and destructor functions. “This” keyword also used to display an instance address of a particular variable. In this C++ program we have used the variables like minutes as minz and hours as hrz. That’s it all about the source code. An example tutorial is given below.
- C++ Program: Addition of 2 Complex Numbers using Friend function
- C++ Call by Reference using Pointer
CPP Constructor & Destructor Code:
[Useful: C Program Tutorials] & [IT Companies Details]
// Header files section
#include<iostream.h>
#include<conio.h>
// Class Definition
class time
{
int minz,hrz,x;
static int s;
public:
time(int x) // Constructor with One parameter
{
this->x=hrz=x;
this->x+=5;
minz=s++; // increment
cout<<"\n Object's Address : "<<this;
cout<<"\n An actual Address of S : "<<&s;
// © http://students3k.com - Karthikh Venkat
cout<<"\n x= "<<this->x<<"\t"<<x;
getch();
}
~time() // Destructor Method
{
cout<<"\n \t"<<hrz<<" : "<<minz;
getch();
}
};
int time::s;
void main()
{
clrscr();
time t5(20),t4(10);
}