Study the following code class IPPacket public IPPacket siz

Study the following code

class IPPacket
{
public:

    IPPacket( size_t sz ) :
        m_size(sz)
    {
        m_data = new char[sz];
    }

    ~IPPacket( )

    {
        m_size = 0;
        delete m_data;
        m_data = nullptr;
    }

private:
    size_t m_size = 0;
    char* m_data = nullptr;
};

int main( int argc, char* argv)

{

      IPPacket pkt1; // line A

      IPPacket* ppkt2 = new IPPacket(10); // line B

      delete [] ppkt2; // line C

      return 0;

}

which of the following are true about this class

This class must have a copy constructor and assignment operator added also

The class has a memory leak

Refer to line A - the object pkt1 is instantiated in the local stack frame of function main in which it is created in but performs no heap based memory allocation.

Refer to line A - the object pkt1 internally performs heap based memory allocation.

Refer to line B - the variable ppkt2 is an array of 10 IPPacket objects.

Refer to line B - the variable ppkt2 is a pointer to a single IPPacket object which is allocated in the heap.

Refer to line C - the variable ppkt2 is incorrectly deallocated as shown in this code.

Question 8

Study the following code

class AVDevice

{

public:  

      AVDevice( ) { }

      ~AVDevice( ) { }

private:

      unsigned long long m_device_id = 0;

}

class Walkman : public virtual AVDevice

{

public:

Walkman( ) { }

          ~Walkman( ) { }

private:

      unsigned long long m_serial_number = 0;

};

Select all that applies:

(A) class Walkman is a pure virtual abstract base class

class AVDevice is a pure virtual abstract base class

class AVDevice is a virtual base class

class Walkman is a type of AVDevice

class AVDevice cannot be instantiated

Question 5

One way to characterize and record principal high level activities of value a system performs is to model them in UML drawn as

a Use-case diagram

a suit-case diagram

a class diagrams

a stakeholder

(A)

This class must have a copy constructor and assignment operator added also

(B)

The class has a memory leak

(C)

Refer to line A - the object pkt1 is instantiated in the local stack frame of function main in which it is created in but performs no heap based memory allocation.

(D)

Refer to line A - the object pkt1 internally performs heap based memory allocation.

(E)

Refer to line B - the variable ppkt2 is an array of 10 IPPacket objects.

(F)

Refer to line B - the variable ppkt2 is a pointer to a single IPPacket object which is allocated in the heap.

(G)

Refer to line C - the variable ppkt2 is incorrectly deallocated as shown in this code.

Solution

Q1:True statements are:

The class has a memory leak

at line C because it is wrongly deleted

Refer to line A - the object pkt1 is instantiated in the local stack frame of function main in which it is created in but performs no heap based memory allocation.

Refer to line B - the variable ppkt2 is a pointer to a single IPPacket object which is allocated in the heap.

Refer to line C - the variable ppkt2 is incorrectly deallocated as shown in this code.

==========================================================================

Q8:

class AVDevice is a virtual base class

class Walkman is a type of AVDevice

========================================================================

Q5:

a Use-case diagram

(B)

The class has a memory leak

Study the following code class IPPacket { public: IPPacket( size_t sz ) : m_size(sz) { m_data = new char[sz]; } ~IPPacket( ) { m_size = 0; delete m_data; m_data
Study the following code class IPPacket { public: IPPacket( size_t sz ) : m_size(sz) { m_data = new char[sz]; } ~IPPacket( ) { m_size = 0; delete m_data; m_data
Study the following code class IPPacket { public: IPPacket( size_t sz ) : m_size(sz) { m_data = new char[sz]; } ~IPPacket( ) { m_size = 0; delete m_data; m_data

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site