Stevens-capital Online Assessment: Time Series Class Implementation
Question Details
Time Series class Write a time series class that stores and accesses double values based on time_t. The class should be capable of storing up to the most recent 5000 seconds of data. You should provid
Full Details
Time Series class Write a time series class that stores and accesses double values based on time_t. The class should be capable of storing up to the most recent 5000 seconds of data. You should provide the following functions:class TimeSeries { public: TimeSeries(size_t window); void AddValue(time_t current_time, double value); double GetValue(time_t desired_time); }; The AddValue function will be called with monotonically increasing values of current_time. That is, if AddValue is called for current_time = k, subsequent calls will be for times >= k. If there are multiple inserts for the same time_t value, use the latest one. If there were no inserts at a particular time, GetValue should return the value which was inserted prior to that time. For example:TimeSeries ts(5000); // object saves the most recent 5000 seconds ts.AddValue(10, 2.0); ts.AddValue(12, 3.0); ts.AddValue(14, 3.5); ts.GetValue(13); // returns 3.0 ts.GetValue(14); // returns 3.5 ts.GetValue(9); // returns 0 ts.AddValue(5011, 4.0); ts.GetValue(9); // undefined — more than 5000 seconds ago Code will be evaluated by speed and design. Memory consumption is a secondary concern and correctness is essential. The class should be as fast as possible when the value is changed frequently or infrequently. Final reminder: this class should be fast. Please give me rice, please give me rice! !