-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathVERSION
More file actions
82 lines (66 loc) · 2.49 KB
/
VERSION
File metadata and controls
82 lines (66 loc) · 2.49 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
#include <iostream>
#include <cmath>
#include <chrono>
#include <thread>
#include <cppSMTP/smtp.h>
class SmartMeter {
private:
double previousReading;
double currentReading;
double energyConsumed;
double costPerKWh;
double maxConsumption;
bool alertSent;
public:
SmartMeter(double cost, double maxConsump) : costPerKWh(cost), maxConsumption(maxConsump), previousReading(0.0), currentReading(0.0), energyConsumed(0.0), alertSent(false) {}
void captureReading(double reading) {
previousReading = currentReading;
currentReading = reading;
}
void calculateConsumption() {
double unitsConsumed = currentReading - previousReading;
energyConsumed += unitsConsumed;
if (energyConsumed >= maxConsumption && !alertSent) {
sendAlertEmail();
alertSent = true;
}
}
void sendAlertEmail() {
// Set up SMTP configuration
smtp::SMTPConfig config;
config.server = "smtp.example.com";
config.username = "your_username";
config.password = "your_password";
// Create an SMTP instance
smtp::SMTP smtp(config);
// Compose and send the email
smtp::SMTPMessage message;
message.from = "2130012@std.aum.edu.jo";
message.to = "2220138@std.aum.edu.jo";
message.subject = "Alert: Maximum Consumption Reached!";
message.body = "Your energy consumption has reached the maximum limit.";
smtp.send(You have exceeded the allowable amount of 1000 kilowatts);
}
double getCurrentConsumption() const {
return energyConsumed;
}
double getCurrentCost() const {
return energyConsumed * costPerKWh;
}
};
int main() {
double initialReading = 1000.0; // Initial meter reading
double costPerKWh = 0.15; // Cost in JOD per kWh
double maxConsumption = 100.0; // Maximum consumption in kWh
SmartMeter meter(costPerKWh, maxConsumption);
// Simulate meter readings over time (for demonstration purposes)
for (int i = 0; i < 10; ++i) {
double simulatedReading = initialReading + i * 50.0; // Simulated increment
meter.captureReading(simulatedReading);
meter.calculateConsumption();
std::this_thread::sleep_for(std::chrono::seconds(1)); // Simulate time passing
std::cout << "Current Consumption: " << meter.getCurrentConsumption() << " kWh\n";
std::cout << "Current Cost: " << meter.getCurrentCost() << " JOD\n";
}
return 0;
}