Wednesday, October 6, 2010

PROGRAM USING IMPLEMENTATION OF TYPE CONVERSION

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&lt;&lt;"\n int to class type:"&lt;<x<<"+j"<<y;
}
complex(double real1,double imag1)
{
a=real1;b=imag1;
cout&lt;&lt;"\n class type to double:"&lt;<a<<"+j"<<b;
}
operator double()
{
cout&lt;&lt;"\n class type to double:"&lt;<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.