22. Dynamic SensorData Allocation

A sensor driver needs to create a SensorData structure dynamically at runtime, fill it with readings, and process it.

You must:

  1. Define a struct named SensorData with three integer fields:
    • x
    • y
    • z
  2. Dynamically allocate a SensorData object using new.
  3. Read integer values for x, y, and z from standard input and store them in the allocated struct.
  4. Print the values in the following format:
    1. x y z
  5. Free the allocated memory using delete.

 

Example 1

Input:

3 4 5

Output:

3 4 5

 

Example 2

Input:

10 20 30

Output:

10 20 30

 

Constraints:

  • Use new to allocate the struct.
  • Use delete to free the allocated memory.
  • Do not allocate arrays.
  • Use standard input and output.
  • Assume int is sufficient to hold all input values.

 

 

 

 

Loading...

Input

3 4 5

Expected Output

3 4 5