-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor_monitor_v2.cpp
More file actions
44 lines (38 loc) · 981 Bytes
/
Copy pathsensor_monitor_v2.cpp
File metadata and controls
44 lines (38 loc) · 981 Bytes
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
#include <iostream>
#include <vector>
using namespace std;
struct SensorReading {
string name;
double value;
double minSafe;
double maxSafe;
};
bool isSafe(SensorReading reading) {
return reading.value >= reading.minSafe && reading.value <= reading.maxSafe;
}
int main() {
vector <SensorReading> readings;
while (true) {
SensorReading reading;cout << "Enter sensor name (or 'done' to finish): ";
cin >> reading.name;
if (reading.name == "done") {
break;
}
cout << "Enter sensor value: ";
cin >> reading.value;
cout << "Enter minimum safe value: ";
cin >> reading.minSafe;
cout << "Enter maximum safe value: ";
cin >> reading.maxSafe;
readings.push_back(reading);
}
int warningCount = 0;
for (int i = 0; i < readings.size(); i++) {
if (!isSafe(readings[i])) {
cout << "Warning: Sensor " << readings[i].name << " is out of safe range!" << endl;
warningCount++;
}
}
cout << "Total warnings: " << warningCount << endl;
return 0;
}