C++ program using the concept of Constructor, Destructor and Constructor overloading
Aim:
To show the working of constructor, destructor and constructor overloading.
Algorithm:
Step 1: Start
Step 2: Declare a class num with data members.
Step 3: Define constructors and destructor in the class num.
Step 4: Create objects o1,o2 and o3 for the class num.
Step 5: Stop
Program code:
#include<iostream.h>
#include<conio.h>
class num
{
int a,b,c,d,e,f;
public:
num()
{
cout<<"Constructor Called\n";
}
num(int a,int b)
{
cout<<"\n"<<a<<"+"<<b<<"+"<<e<<"="<<c+d+e<<"\n";
}
~num()
{
cout<<"Distructor Called\n";
}
};
void main()
{
clrscre();
num 01;
{
num 02(5,7);
}
{
num o3(5,9,1);
}
getch();
}
Output:
Enter radius : 5
Area of circle = 78.5
Enter length an breadth : 3 4
Area of rectangle = 12
Tagged in: Algorithms, Programs