-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_5.cpp
99 lines (95 loc) · 2.61 KB
/
7_5.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*#include <iostream>
using namespace std;
class Fahrenheit; // Forward declaration
class Celsius {
private:
float temperature;
public:
// Constructor
Celsius(float temp = 0.0f) : temperature(temp) {}
// Type conversion from Celsius to Fahrenheit
operator Fahrenheit();
// Getter function for temperature
float getTemperature() const {
return temperature;
}
};
class Fahrenheit {
private:
float temperature;
public:
// Constructor
Fahrenheit(float temp = 0.0f) : temperature(temp) {}
// Type conversion from Fahrenheit to Celsius
operator Celsius() {
return Celsius((temperature - 32) * 5 / 9);
}
// Getter function for temperature
float getTemperature() const {
return temperature;
}
};
// Type conversion from Celsius to Fahrenheit
Celsius::operator Fahrenheit() {
return Fahrenheit((temperature * 9 / 5) + 32);
}
int main() {
Celsius C1;
Celsius C2 = 5.0;
Fahrenheit F1;
Fahrenheit F2;
F1 = C2; // Celsius to Fahrenheit conversion
C1 = F2; // Fahrenheit to Celsius conversion
cout << "C1 temperature: " << C1.getTemperature() << " degrees Celsius\n";
cout << "F1 temperature: " << F1.getTemperature() << " degrees Fahrenheit\n";
cout << "This program is performed by 22CS051_DARSH";
return 0;
}
*/
#include <iostream>
using namespace std;
class Celsius; // Forward declaration
class Fahrenheit {
private:
float temperature;
public:
// Constructor
Fahrenheit(float temp = 0.0f) : temperature(temp) {}
// Type conversion from Fahrenheit to Celsius
operator Celsius();
// Getter function for temperature
float getTemperature() const {
return temperature;
}
};
class Celsius {
private:
float temperature;
public:
// Constructor
Celsius(float temp = 0.0f) : temperature(temp) {}
// Type conversion from Celsius to Fahrenheit
operator Fahrenheit() {
return Fahrenheit((temperature * 9 / 5) + 32);
}
// Getter function for temperature
float getTemperature() const {
return temperature;
}
};
// Type conversion from Fahrenheit to Celsius
Fahrenheit::operator Celsius() {
return Celsius((temperature - 32) * 5 / 9);
}
int main() {
Celsius C1;
Celsius C2 = 5.0;
Fahrenheit F1;
Fahrenheit F2;
F1 = C2; // Celsius to Fahrenheit conversion
C1 = F2; // Fahrenheit to Celsius conversion
cout << "C1 temperature: " << C1.getTemperature() << " degrees Celsius\n";
cout << "F1 temperature: " << F1.getTemperature() << " degrees Fahrenheit\n";
cout << "This program is performed by 22CS051_DARSH";
return 0;
}