CJCoding With Joseph
15free / daySign inCreate account

Update a Heap Sensor Through the Arrow Operator

The Sensor struct (an int id and a double reading) is already written for you, and cout is already set to fixed with setprecision(2).

Allocate exactly ONE Sensor on the heap with new and store its address in sensor, then use the arrow operator to set id to 7 and reading to 21.5. The program prints the sensor, then you must add 1.25 to the reading (again through ->) before it prints a second time.

Both cout lines are already written. Print exactly the output shown in Expected Output.

Free the memory you allocate before the program ends — this question checks for memory leaks.

Expected Output:

Sensor 7 reads 21.50
Sensor 7 reads 22.75

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
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.