Question: use C + + Problem Statement: In today's era, server logs are critical for diagnosing issues. You've been asked to write a program that analyzes
use C Problem Statement:
In today's era, server logs are critical for diagnosing issues. You've been asked to write a program that analyzes logs to detect anomalous behavior.
Each log is represented by a nonnegative integer value that corresponds to the number of activities in that log An activity count below is considered NORMAL, between and inclusive is considered HIGH, and above is an ANOMALY.
Your task is to:
Analyze the logs and categorize them into their respective statuses.
Count the number of logs in a given status.
Filter out log entries based on their status.
Requirements:
Enum Class Definition: Inside code.hpp file, define an enum class named LogStatus with the statuses: "NORMAL", "HIGH", and "ANOMALY".
Storage: Use a std::vector to store the logs and their analyzed statuses. An example is given in main.cpp
You are provided a test file similar to the tests the autograder uses. Please use the tests.cpp file to check your work and debug.
Functions:
Add C code to the following functions in the code.cpp file. Do not modify function arguments.
std::vector analyzeLogsconst std::vector& logs:
o This function takes in logs an existing vector of logs
o This function returns a vector of statuses, where each element is the status of the corresponding element in logs
o Remember, an activity count below is considered NORMAL, between and inclusive is considered HIGH, and above is an ANOMALY.
o If the input vector is empty, the output vector should also be empty.
o Assume elements of the vector logs are all positive.
int countLogsByStatusconst std::vector& logStatuses const LogStatus status:
o This function takes in logStatuses an existing vector of log statuses, and a given status.
o Note that logStatuses is of the same type as the return type of analyzeLogs function.
o This function returns the number of logs that match the given status.
o If the input vector logStatuses is empty, return
std::vector filterLogsByStatusconst std::vector& logs const LogStatus desiredStatus
o This function takes in logs an existing vector of logs and a given desiredStatus.
o You will filter the elements in logs by the given status.
o The function returns a new vector of logs containing all log entries that match the specified status.
o Hint: You can use analyzeLogs function you implemented above.
o If the input vector is empty, the output vector should also be empty.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
