Â
The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include<conio.h>
class number
{
private:
float x, y;
public:
number(float num1, float num2);
int display();
~number();
};
number::number(float num1, float num2)
{
cout << "Constructor is called.\n";
x = num1;
y = num2;
}
number::display()
{
cout << "\nEntered numbers are:-\nnum1 = " << x << "\nnum2 = " << y;
}
number::~number()
{
cout << "\n\nDESTRUCTOR is called.";
}
void main()
{
clrscr();
float x, y;
cout << "Enter 2 number:-\n";
cin >> x >> y;
number ag(x, y);
ag.display();
getch();
}
//..........Coded by YASH ALAPURIA
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
class number
{
private:
float x, y;
public:
number(float num1, float num2);
int display();
~number();
};
number::number(float num1, float num2)
{
cout << "Constructor is called.\n";
x = num1;
y = num2;
}
number::display()
{
cout << "\nEntered numbers are:-\nnum1 = " << x << "\nnum2 = " << y;
}
number::~number()
{
cout << "\n\nDESTRUCTOR is called.";
}
int main()
{
system("cls");
float x, y;
cout << "Enter 2 number:-\n";
cin >> x >> y;
number ag(x, y);
ag.display();
return 0;
}
//..........Coded by YASH ALAPURIA
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP