-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtypeConversion.cpp
More file actions
141 lines (135 loc) · 1.35 KB
/
typeConversion.cpp
File metadata and controls
141 lines (135 loc) · 1.35 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//type conversion
//1.basic to class
//2.class to basic
//3.class to class
//class to base
#include<string.h>
#include<cstring>
#include<sstream>
#include<math.h>
#include<cmath>
using namespace std;
#include<iostream>
/*
class A
{
int m,km;
public:
A()
{
m=0;
km=0;
}
void getdata()
{
cin>>km>>m;
}
operator int()
{
int temp;
temp=km*1000+m;
return temp;
}
operator float()
{
float temp;
temp=m+(float)km/1000;
return temp;
}
};
int main()
{
A ob;
ob.getdata();
int metres;
metres=ob;
float kilo;
kilo=ob;
cout<<kilo<<endl<<metres;
return 0;
}
*/
//base to class
/*
class A
{
int km,m;
public:
A()
{
km=m=0;
}
A(int a)
{
km=a;
}
void show()
{
m=km*1000;
cout<<m<<endl;
}
};
int main()
{
int dist;
cin>>dist;
A ob(dist);
ob.show();
return 0;
}
*/
class circle;
class rectangle
{
float area;
int l,b;
public:
rectangle()
{
l=b=0;
}
rectangle(float v)
{
l=b=v;
}
int ar()
{
return area;
}
void calculate()
{
area=l*b;
}
};
class circle
{
float carea,r;
public:
circle()
{
r=0;
}
void operator=(rectangle r1)
{
carea=r1.ar();
}
operator float()
{
float rad=sqrt(carea/3.14);
return rad;
}
};
int main()
{
circle c;
rectangle r;
float radius;
int value;
cin>>value;
r=value;//base to class type
r.calculate();
c=r;//class to class type
radius=c;//class to base type
cout<<radius;
return 0;
}