#include <iostream>
using namespace std;
class DeviceCounter {
private:
int count;
public:
DeviceCounter(int c = 0) : count(c) {}
DeviceCounter& operator++() {
++count;
return *this;
}
int getCount() const {
return count;
}
};
int main() {
int n;
cin >> n;
DeviceCounter counter;
for (int i = 0; i < n; i++) {
++counter;
}
cout << "Final count=" << counter.getCount();
return 0;
}
Explanation & Logic Summary:
operator++()count variable by 1main() repeatedly applies ++counter, resulting in n total incrementsFirmware Relevance & Real-World Context:
Counters are fundamental in firmware development for tracking:
Overloading the prefix ++ operator allows such counters to behave naturally, improving code readability and maintainability in embedded C++ systems.
Input
3
Expected Output
Final count=3