Question 2 6 marks Objects with Pointers Consider the follow

Question 2, (6 marks). Objects with Pointers Consider the following declaration and implementation of the class Name contained in the file class Name private stringe firstName: string\" lastName: public Name string fname, string 1name) const Name & src) -Name() void printo const; Now consider the implementation of the class in Name.cpp. #include \"Name. h\" include ciostreamo using namespace std; Name: (string fname string 1 name) firstName new stringd lastName new string 1 name) Name: (const Name & src) f firstName new string (src.firstName)): lastName new string(*(src.lastName)) delete delete lastName; void Name: print const This prints the rst name, followed by a space, followed by the last nane cout co *firstName *lastName endl Page 4 of 25 Now consider the program below that uses the above Name class include dostreamo. include Sinclude \"Name.h\" using namespace std; int maino string Tom Johns string Michael \"Michael\" string Jackson 2ackson\"i string Sarah \"Sarah string Johnson \"Dohnson Name first(Toma, Johns): Name third (Sarah, Johnson first, print(): second, printo third print() first second second third third first first print second print(): printo; Point A return (0): a) a ark. What is the output produced by the program above when itreaches Point A? (b) a mark). Does the program above suffer from any memory leaks by the time it reaches point A? If so, then how many variables (ints, strings, or objects of type Nane) end up being memory leaks? Page 5 of 25

Solution

a. 2

The main purpose of inheritance is code reuse. it is inheriting the properties of base class and those are used in derived class.

b. 2

C. True

To enable inheritance between two classes, we don\'t need access to its source code.

D. True

An abstract class doesn\'t have any data member. it have only member functions. which is used for inheritance purpose.

E. 2

\' visited flag \' is using to mark a vertex as visited, so that only program can determine whether a vertex is visited or not.

F. 1

algorithm a have o(n) complexity. algorithm have o(log n) complexity. value of \'log n\'3 is always lesser than \'n\'. therefor algorithm B is always more efficient than algorithm A.

G. 3

I (1) true

(2) false

(3) false

(4) true

End************** pls give me good rating**** ****

 Question 2, (6 marks). Objects with Pointers Consider the following declaration and implementation of the class Name contained in the file class Name private s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site