Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Compile & run the code to see the crash. Use valgrind to show memory leak(or som

ID: 3565402 • Letter: C

Question

Compile & run the code to see the crash. Use valgrind to show memory leak(or something else). Add copy constructor and = operator for both First and Second classes - compile, rerun the program & check with valgrind to make sure that all the problems are resolved.

#include <iostream>

using namespace std;

class First
{
   private:
   int *aptr;
   int size;
   public:
       First(int s = 5) {
           size = s;
           aptr = new int [s];
       }
       ~First() {
           delete [] aptr;
       }
};
  
class Second
{
   private:
   First *bptr;
   int size;
   public:
       Second(int s=3) {
           size = s;
           bptr = new First [s];
       }
       ~Second() {
           delete [] bptr;
       }
};
  
int main()
{
       Second x;
       Second y(x);
       Second z;
       z = x;
}

Explanation / Answer

umm too late.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote