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

i. Write the code in the main program that will print out the information about

ID: 3842856 • Letter: I

Question

i. Write the code in the main program that will print out the information about bestseller. ii Write the code in the main program that will add 50 to the number of copies in stock for bestseller. a) What is the difference between public and private members of a class? b) What is a constructor? c) What is the scope resolution operator, when do we use it when programming with classes? d) What is the Rule of 3? e) Why would I need a copy constructor instead just using the = operator? f)What is the difference between a deep and shallow copy? g) Why would l overload an operator? Write a code snippet to increase size of dynamic array games (50) if it becomes full.

Explanation / Answer

Question 5 :

a) diff between public and private members of a class :

A public class is one that is accessible from any other class. You just have to know what object it is and you can use a dot operator to access it whereas, a private class means that only that class has direct access to the variable, everything else needs a method/function to access or change that data.

b) A constructor is a special method/function in OOP which initializes an object of that type . It is an instance method that usually has the same name as the class, and can be used to set the values of the members of an object, either to default or to user-defined values.

c) The scope resolution operator helps to identify and specify the context to which an identifier refers, particularly by specifying a namespace . The :: operator is used for in classes for - To define a function outside a class, to access a class's static variable and in case of multiple inheritence.

d) It is a rule to decide when an old piece of code neeeds to be refactored (replaced) with a new one . It states that the code can be copied once, but that when the same code is used three times, it should be extracted into a new procedure.

e) The assignment operator CAN be used to copy as well as the copy constructor ! But this will only work when both the objects on the LHS and RHS are of the SAME type otherwise the = operator will be used as a punctuation and not as an equal to sign. Although, use of = operator for this purpose is symantically incoreect.

f) In a shallow copy, any object pointed to by the source is also pointed to by the destination (so that no referenced objects are copied), whereas with a deep copy, any object pointed to by the source is copied and the copy is pointed to by the destination (so there will now be 2 of each referenced object). This recurses down the object tree.

g) Operator overloading can be useful since it can make codes easy to understand and write although generally overloading can cause the programs to become more complex. Also, overloading can be abused to make the code unreadable.
-------------------------------------------