Cpp - Write program to use the proper deletion method to prevent memory leaks

Requirements

Write program to use the proper deletion method to prevent memory leaks

Demo

#include <iostream>
  
class Bug/*  w w w . j  av a 2s  .  c  o  m*/
{
public:
    Bug (int age, int weight);
    ~Bug() {}
    int GetAge() { return itsAge; }
    int GetWeight() { return itsWeight; }
  
private:
    int itsAge;
    int itsWeight;
};
  
Bug::Bug(int age, int weight):itsAge(age), itsWeight(weight) {

}
  
Bug* TheFunction();
  
int main()
{
    Bug* rBug = TheFunction();
    int age = rBug->GetAge();
    std::cout << "rBug is " << age << " years old!\n";
    std::cout << "rBug: " << rBug << "\n";
    // How do you get rid of that memory?
    Bug* pBug = rBug;
    delete pBug;
    return 0;
}
  
Bug* TheFunction()
{
    Bug *pBug = new Bug(5,9);
    std::cout << "pBug: " << pBug << "\n";
    return pBug;
}

Result