-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (62 loc) · 2.26 KB
/
Copy pathmain.cpp
File metadata and controls
76 lines (62 loc) · 2.26 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
// Copyright (c) 2025 Adithya Balachandra
// This software is licensed under the MIT License. See the LICENSE file for
// details.
/**
* @file main.cpp
* @brief Demonstration program showcasing the AB Modules functionality.
*
* This program demonstrates the usage of Calculator, Logger, and Notifier
* components working together to perform arithmetic operations with logging
* and notification capabilities.
*/
#include <ab/calculator/Calculator.h>
#include <ab/logger/Logger.h>
#include <ab/notifier/Notifier.h>
#include <iostream>
#include <stdexcept>
int main() {
std::cout << "=== AB Modules Demo ===" << std::endl;
try {
// Initialize components
ab::calculator::Calculator calc;
ab::logger::Logger logger;
constexpr int notification_threshold = 100;
ab::notifier::Notifier notifier(
notification_threshold); // Notify if result > 100
// Perform calculations with logging
logger.log("Starting calculations");
constexpr int first_number = 15;
constexpr int second_number = 8;
std::cout << "Computing: " << first_number << " + " << second_number
<< std::endl;
int result = calc.add(first_number, second_number);
logger.log("Addition completed");
std::cout << "Result: " << result << std::endl;
// Check for notifications
notifier.checkAndNotify(result);
if (notifier.wasNotified()) {
std::cout << "Notification: Result exceeded threshold!" << std::endl;
}
// Demonstrate multiplication
std::cout << "\nComputing: " << first_number << " * " << second_number
<< std::endl;
result = calc.multiply(first_number, second_number);
logger.log("Multiplication completed");
std::cout << "Result: " << result << std::endl;
notifier.checkAndNotify(result);
if (notifier.wasNotified()) {
std::cout << "Notification: Result exceeded threshold!" << std::endl;
}
// Display all logs
std::cout << "\n=== Operation Log ===" << std::endl;
const auto &logs = logger.getLogs();
for (const auto &log : logs) {
std::cout << "- " << log << std::endl;
}
std::cout << "\n=== Demo Complete ===" << std::endl;
} catch (const std::exception &e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}
return 0;
}