-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_4.cpp
More file actions
116 lines (92 loc) · 2.51 KB
/
5_4.cpp
File metadata and controls
116 lines (92 loc) · 2.51 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
#include <iostream>
#include <queue>
using namespace std;
class Fahrenheit;
class Celsius {
private:
double tempC;
public:
Celsius(double c = 0.0) : tempC(c) {}
double getTemp() const {
return tempC;
}
operator Fahrenheit();
bool operator==(const Fahrenheit& f);
};
class Fahrenheit {
private:
double tempF;
public:
Fahrenheit(double f = 32.0) : tempF(f) {}
double getTemp() const {
return tempF;
}
operator Celsius() {
return Celsius((tempF - 32) * 5 / 9);
}
bool operator==(const Celsius& c) {
return c.getTemp() == ((tempF - 32) * 5 / 9);
}
};
Celsius::operator Fahrenheit() {
return Fahrenheit(tempC * 9 / 5 + 32);
}
bool Celsius::operator==(const Fahrenheit& f) {
return tempC == ((f.getTemp() - 32) * 5 / 9);
}
void storeUsingQueue() {
queue<Celsius> tempQueue;
int n;
cout << "\nEnter number of temperatures(Queue) ";
cin >> n;
for (int i = 0; i < n; ++i) {
double temp;
cout << "Enter Celsius temperature :";
cin >> temp;
tempQueue.push(Celsius(temp));
}
cout << "\nQueue (FIFO):\n";
while (!tempQueue.empty()) {
Celsius c = tempQueue.front();
Fahrenheit f = c;
cout << c.getTemp() << "C = " << f.getTemp() << "F\n";
tempQueue.pop();
}
}
void storeUsingArray() {
int n;
cout << "\nEnter number of temperatures(Array) :";
cin >> n;
if (n > 100) n = 100;
Celsius tempArray[100];
for (int i = 0; i < n; ++i) {
double temp;
cout << "Enter Celsius temperature : ";
cin >> temp;
tempArray[i] = Celsius(temp);
}
cout << "\nArray (Static Storage):\n";
for (int i = 0; i < n; ++i) {
Fahrenheit f = tempArray[i];
cout << tempArray[i].getTemp() << "C = " << f.getTemp() << "F\n";
}
}
int main() {
double cTemp, fTemp;
cout << "Enter a Celsius temperature to convert and compare: ";
cin >> cTemp;
Celsius c(cTemp);
Fahrenheit f = c;
cout << "Converted: " << c.getTemp() << "C = " << f.getTemp() << "F\n";
cout << "Enter a Fahrenheit temperature to compare: ";
cin >> fTemp;
Fahrenheit f2(fTemp);
if (c == f2)
cout << "Temperatures are equal!\n";
else
cout << "Temperatures are not equal.\n";
storeUsingQueue();
storeUsingArray();
cout<<"24CE052_pushti kansara";
return 0;
}