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

Can someone help me answer these questions in C++? Thank you!! (3) Suppose that

ID: 3597019 • Letter: C

Question

Can someone help me answer these questions in C++? Thank you!!

(3) Suppose that I write a bag class that uses a dynamic array of integers. Do l need to implement deep copy semantics for this class? If so, just write the names of the functions that I must implement to support deep copy (4) Consider the following code. Bag2 b1; Bag2 b2(b1); Bag2 b3 b2; Bag2 b4; b4 = b3; Against each line of the above code write just the name of the constructor(s) and/or the operator(s) that will be called. Do not write function prototypes, just names (5) Within the assignment operator do you need to check against self-assignment? If yes then how.

Explanation / Answer

Please find my answer.

3)

Yes, you need to implement deep copy functionality for Bag class because Bag class is user defined.

You need to overload '=' (assignment operator)

4)

Bag2 b1; Default constructor

Bag2 b2(b1); Copy constructor

Bag2 b3 = b2; Copy constructor

Bag2 b4; Default constructor

b4 = b3; // assignment operator

5)

Yes, we need to check for self assignment

we can check like :

operator =(const Bag2 &obj) {

if(*this != obj) {

}

}

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