-
Notifications
You must be signed in to change notification settings - Fork 0
/
7_4.cpp
58 lines (55 loc) · 940 Bytes
/
7_4.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
#include "iostream"
using namespace std;
class celsius
{
float temp;
public:
celsius()
{
temp = 30.3;
}
celsius(float a)
{
temp = a;
}
celsius(const celsius &c)
{
temp = c.temp;
}
celsius operator=(float a)
{
temp = a;
return *this;
}
operator float()
{
float c1 = temp;
return c1;
}
void put();
};
void celsius::put()
{
cout << temp;
}
int main()
{
// basic to class type conversion right to left through constructor
float temperature = 30.7;
// celsius c1;
celsius c1 = temperature;
celsius c3(temperature);
celsius c4;
c4 = temperature;
c1.put();
// float c2 = c1; // c2.operator = (c1)
// class to basic type
celsius c6(temperature);
float t = 300.50;
c6.put();
cout << endl
<< t << endl;
t = c6;
cout << t << endl;
return 0;
}