Ex No.2b PROGRAM USING IMPLEMENTATION OF TYPE CONVERSION
18-8-10
AIM:
To write a c++ program to perform type conversion from basic type to class type and class type to basic type.
ALGORTHIM:
Step 1: Start the program.
Step 2: Use constructor to convert basic type to class type.
Step 3: Use conversion function to convert class type to basic type.
Step 4: Display the result.
Step 5: Stop the program.
PROGRAM:
#include<iostream.h>
#include<conio.h>
class complex
{
int x,y;
double a,b;
public:
complex(int real,int imag)
{
x=real;y=imag;
cout<<"\n int to class type:"<<x<<"+j"<<y;
}
complex(double real1,double imag1)
{
a=real1;b=imag1;
cout<<"\n class type to double:"<<a<<"+j"<<b;
}
operator double()
{
cout<<"\n class type to double:"<<a+b;
return 0;
}
};
void main()
{
clrscr();
complex c(3.5);
complex c1(5.5,6.3);
double num =c1;
getch();
}
RESULT:
Thus a c++ program for performing type conversion is wrritten,executed and output verified successfully.