C++20 sections · 1024 units
Open in Course

Force Vectors - Algorithm

Implementation approach

Here's your approach using inheritance:

1.1. Define a

Vector3D base class with protected x, y, z members and a constructor.

2.2. Define a

ForceVector class that inherits from Vector3D and adds an add() method.

3.3. Read nn, then create a result ForceVector initialized to (0,0,0)(0,0,0).

4.4. Loop nn times: read a force vector and add it to result.

5.5. Check if result equals (0,0,0)(0,0,0).

6.6. Output YES or NO based on the check. The inheritance structure keeps your code organized and extensible.