-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcasting.cpp
77 lines (77 loc) · 1.13 KB
/
casting.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<iostream>
using namespace std;
class relactional
{
int num,den;
public:
relactional(int x = 0,int y = 1)
{
num = x;
den = y;
}
void output()
{
cout << num << "/" << den << endl;
}
operator float()
{
return float(num)/den;
}
};
class complex
{
int real,img;
public:
complex(int x = 0,int y = 0)
{
real = x;
img = y;
}
operator relactional()
{
return relactional(real,img);
}
void output()
{
cout << real << "+i" << img << endl;
}
};
void user_to_user()
{
complex A(12,98);
relactional a;
a = relactional(A);
a.output();
}
void user_to_inbuild()
{
relactional A(43,56);
float a;
a = A;
cout << endl << a << endl << endl ;
a = float(A);
cout << endl << a << endl << endl ;
}
void inbuild_to_user()
{
int a = 90;
relactional A;
A = a;
a = 98;
A.output();
A = relactional(a);
A.output();
}
void inbuild_to_inbuild()
{
int a = 23 , b = 3;
float c;
c = a/b;
cout << "Value before casting :"<< c;
c = float(a)/b;
cout << endl << "Value after casting :"<< c << endl;
}
main()
{
user_to_user();
}