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 non-negative integer value that corresponds to the number of activities in that log. An activity count below 1000 is considered NORMAL, between 1000 and 5000(inclusive) is considered HIGH, and above 5000 is an ANOMALY.
Your task is to:
1. Analyze the logs and categorize them into their respective statuses.
2. Count the number of logs in a given status.
3. Filter out log entries based on their status.
Requirements:
1. Enum Class Definition: Inside code.hpp file, define an enum class named LogStatus with the statuses: "NORMAL", "HIGH", and "ANOMALY".
2. Storage: Use a std::vector to store the logs and their analyzed statuses. An example is given in main.cpp.
3. 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.
1. std::vector analyzeLogs(const 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 1000 is considered NORMAL, between 1000 and 5000(inclusive) is considered HIGH, and above 5000 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.
2. int countLogsByStatus(const 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 "0".
3. std::vector filterLogsByStatus(const 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!