Welcome, Engineer! You are one of the last veterans of the Speedywagon Foundation, a secret organization that, for decades, has been battling ancient threats like the Pillar Men. In the course of this effort, you've spent years maintaining the Foundation's technological systems, built using a mix of cutting-edge tech and aging libraries.
However, in recent times, the sensors that track Pillar Men activities are malfunctioning. The Foundation's systems are old, and the code interacts with a legacy C++ library that cannot be updated. Your task is to implement four core functions that monitor Pillar Men sensor activity using an old-fashioned pointer-based library.
As a modern C++ engineer, you’d prefer using smart pointers, but alas, legacy code demands respect for the old ways. The fate of humanity may rest on these pointers, so proceed carefully, and may the Hamon energy guide you.
As sensor readings can be huge, we supply a mockup struct that is used in the actual library. The code has already been implemented in the header file for you.
struct pillar_men_sensor {
int activity{};
std::string location{};
std::vector<int> data{};
};connection_check)Your first task is to ensure that the Pillar Men sensor is connected properly.
We can't have false alarms triggered by disconnected sensors.
You will write a function connection_check, which tests if the sensor's pointer is valid by checking for nullptr.
pillar_men_sensor struct.true if the sensor pointer is not null, and false otherwise.pillar_men_sensor* sensor{nullptr};
bool isConnected = connection_check(sensor);
// isConnected => falseactivity_counter)Pillar Men are lurking in the shadows, and we need to know if sensors have detected any activity.
You will write the activity_counter function, which takes in an array of sensors and a capacity indicating the number of sensors in the array.
pillar_men_sensor sensor_array[3] = {{0}, {101}, {22}};
int totalActivity = activity_counter(sensor_array, 3);
// totalActivity => 123alarm_control)Not every sensor should trigger an alarm unless there’s real danger.
The alarm_control function ensures that a sensor only triggers an alarm if its activity level is greater than 0.
This function should also check for null sensors to prevent system crashes.
pillar_men_sensor.nullptr sensor. If the sensor is nullptr, return false.true; otherwise, return false.pillar_men_sensor db{9008, "songokunoie", {7, 7, 7}};
bool alarm = alarm_control(&db);
// alarm => trueuv_alarm functionIn this task, you will implement the uv_alarm function to determine whether an alarm should be triggered based on UV light exposure levels and sensor activity.
The uv_alarm function should use the provided uv_light_heuristic function, which operates on a vector of data and returns a value based on certain thresholds.
This is a mockup version of the complex code that will run during production, please don't change the interface.
Define the uv_alarm function in the speedywagon namespace. It should:
pillar_men_sensor struct as its parameter.false if the sensor pointer is null.uv_light_heuristic function, passing the address of the sensor's data array.true if the value returned by uv_light_heuristic is greater than the sensor->activity level, otherwise return false.Welcome, Engineer! You are one of the last veterans of the Speedywagon Foundation, a secret organization that, for decades, has been battling ancient threats like the Pillar Men. In the course of this effort, you've spent years maintaining the Foundation's technological systems, built using a mix of cutting-edge tech and aging libraries.
However, in recent times, the sensors that track Pillar Men activities are malfunctioning. The Foundation's systems are old, and the code interacts with a legacy C++ library that cannot be updated. Your task is to implement four core functions that monitor Pillar Men sensor activity using an old-fashioned pointer-based library.
As a modern C++ engineer, you’d prefer using smart pointers, but alas, legacy code demands respect for the old ways. The fate of humanity may rest on these pointers, so proceed carefully, and may the Hamon energy guide you.
As sensor readings can be huge, we supply a mockup struct that is used in the actual library. The code has already been implemented in the header file for you.
struct pillar_men_sensor {
int activity{};
std::string location{};
std::vector<int> data{};
};connection_check)Your first task is to ensure that the Pillar Men sensor is connected properly.
We can't have false alarms triggered by disconnected sensors.
You will write a function connection_check, which tests if the sensor's pointer is valid by checking for nullptr.
pillar_men_sensor struct.true if the sensor pointer is not null, and false otherwise.pillar_men_sensor* sensor{nullptr};
bool isConnected = connection_check(sensor);
// isConnected => falseactivity_counter)Pillar Men are lurking in the shadows, and we need to know if sensors have detected any activity.
You will write the activity_counter function, which takes in an array of sensors and a capacity indicating the number of sensors in the array.
pillar_men_sensor sensor_array[3] = {{0}, {101}, {22}};
int totalActivity = activity_counter(sensor_array, 3);
// totalActivity => 123alarm_control)Not every sensor should trigger an alarm unless there’s real danger.
The alarm_control function ensures that a sensor only triggers an alarm if its activity level is greater than 0.
This function should also check for null sensors to prevent system crashes.
pillar_men_sensor.nullptr sensor. If the sensor is nullptr, return false.true; otherwise, return false.pillar_men_sensor db{9008, "songokunoie", {7, 7, 7}};
bool alarm = alarm_control(&db);
// alarm => trueuv_alarm functionIn this task, you will implement the uv_alarm function to determine whether an alarm should be triggered based on UV light exposure levels and sensor activity.
The uv_alarm function should use the provided uv_light_heuristic function, which operates on a vector of data and returns a value based on certain thresholds.
This is a mockup version of the complex code that will run during production, please don't change the interface.
Define the uv_alarm function in the speedywagon namespace. It should:
pillar_men_sensor struct as its parameter.false if the sensor pointer is null.uv_light_heuristic function, passing the address of the sensor's data array.true if the value returned by uv_light_heuristic is greater than the sensor->activity level, otherwise return false.