Help fixing logical error and segmentation fault in C++ link…

I’m currently working on a C++ project involving [sebutkan topiknya, misal: Dynamic Memory/Arrays]. My code compiles, but I keep getting a runtime error (segmentation fault) when trying to execute the function.

I need a tutor to:

  1. Identify the cause of the memory leak/error.
  2. Explain the fix clearly so I can avoid this in the future.
  3. Ensure the code follows best practices (using smart pointers if applicable).

Attached is my current source code.

WRITE MY PAPER