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

FINAL ENA When you define a C class, should you make the member variables public

ID: 3912756 • Letter: F

Question

FINAL ENA When you define a C class, should you make the member variables public or private? Should you make the member functions public or private 5. Suppose your program contains the following class definition (along with definitions of the member functions) class YourClass public Yourclass (int newinto, char moreNewInfo) i YourClasst void doStuftt privatei int information char moreInformation )a Which of the following are legal Yourclassanobject (42, 'A'); YourClass anotherobjecti Yourclass yetAnotherobject 0a anobject-Yourclass (99, anObject " YourClass( )? anobjectYourClass 6. ls it posible using operator overloading to change the behavior of , on integers Why or why not

Explanation / Answer

4. There is no hard and fast rule but, Private variables and methods should be used when we want to make changes to the internal working of class only. If a class wants to offer variables and methods to the outside of class those methods and variables should be made public.

5.

a. YourClass anObject(42, 'A'); //Legal. Calls the parameterized constructor.

b. YourClass anotherObject; //Legal. Just creates an object but not initializes.

c. YourClass yetAnotherObject();//Legal. Calls the unparameterized constructor.

d. an_object = YourClass(99, 'B'); //Legal. Initializes the object with the parameterized constructor.

e. an_object = YourClass(); //Legal. Initializes the object with the default constructor.

f. an_object = YourClass; //Illegal. YourClass is a datatype, and should not be assigned.

6. No, because you can't overload operator with two same declarations. As int is a built-in data type we can't overload operator + for some other behaviour.

Thanks

Please rate. If you face any problem I am available in comments.