SensorLog Owns Its Reading Buffer
mediumQuestion 695Write a class SensorLog that owns a heap-allocated array of temperature readings.
The class must have these private members:
- int* readings;
- int count;
and this public interface (the hidden driver calls exactly these):
SensorLog(int n); // allocate an array of n ints with new[] and set every slot to 0
~SensorLog(); // release the array
void record(int index, int value);
int at(int index) const; // the value stored at index
int size() const; // how many slots the log holds
int total() const; // the sum of all stored valuesThe driver reads n followed by n integers, records them in order, then prints three lines.
For the input:
4
10 20 30 40the exact output is what is shown in Expected Output.
Free the memory you allocate before the program ends — this question checks for memory leaks.
Do NOT write a main function. A hidden driver creates your object, calls your methods and prints the output.
Expected output
count=4 total=100 last=40
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.